From nobody Thu Jun 18 08:13:40 2026 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEEA5381B15 for ; Thu, 30 Apr 2026 22:16:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777587378; cv=none; b=WqS6USt1iZwm2HqmPFf7UvKd3Ehhd+u5lufo7iyOY0zFiYO9KeVKEVfVfKGUJUjOKo2COwbK0TxY2A4mn1Bkf8sH99qmtjOOJUkpWjbFNCX625DP54Pvt7KGVRnmultMArx6jlIi0pVKnHKny6lN5ssWkylCRqxr3pfITmsO1bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777587378; c=relaxed/simple; bh=KIoMyWKvhjgZMM30/KFdKVEMyY27M/KUH7AVPeHarE0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=K6eyW+xpz5WTUsuxmUErf14zWphAvgaj61grxZs91vWXklwIhmnu/r/3QVesQFsYy3y4F76dO3IzthH43rpLv/HuttoE0fPETLpAXfDNHssW2lu/0hNU0KQU2b2MLlW+6occX5RYgZUULY9PRhl9kVIVA3eqqd6jTdo4URetuSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Pw1jZazi; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pw1jZazi" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-8eb5ad01402so153173485a.2 for ; Thu, 30 Apr 2026 15:16:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777587375; x=1778192175; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=b0Rsfg16xdotslJA1zN20XDN16KykAdChmHnTzqvbpY=; b=Pw1jZazi9tPyqdTSFzFpnn9SQOvt7m9MwiqmVUBqpZCTvbP1NfMiNVWsUUoQgSpm29 ocJTViGezNkFzTFDuHigWoYsXEZpVFf8vU5j5zpjlXAT1e2JtlpKiObaP7QEyBqVY6+t N3IUDxa7FlS99JfRN8z5chzGKLWKo8L5YAVl9VlCG2++whC2vBwIE0dOaRagrw8Xy2+h uqEPqcXbb0ho0SK6hvSGjp1/DEP8O64ms6jsWbSQhpEuV9tV3xvIa4AADQXmBCRXL+Mv i7eGglEfASgz9PQVv102VnqGOUfcKFeGiM1l9kAAIEZHz0xLGmAMUrCW7tvK1eH78ud6 7owQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777587375; x=1778192175; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=b0Rsfg16xdotslJA1zN20XDN16KykAdChmHnTzqvbpY=; b=pQwDIdJybqqmh92zwrUY7Y1xbq2O6DjycM5geHFOgQ3n3UxUsE/OSlkrcYSbU+8RKI PafqPVFZnNUzsE71RNudHSvOrir+H+4Ye/ogIatTVX5LPmDbsqwSAYyPSZxOSbe1KvLb DF93GJ53olxzWOc22/1COjDBSix/wqkzY8g44J6PSCGCg893OlHiniCgjcZNPm3x/mos QDlEjnJAMvn1LsSBEI7FsM0dR2s68J8IdY1zfKXujYnpktqLXDIohBufZhjt9jjyZedp 1/siQGWnVwbf6RNGuhmVsd/JMjUFpj+WD+NQivkzu4eZDpylHlR8nbajRy/ETfuF7Zhb v0VA== X-Forwarded-Encrypted: i=1; AFNElJ8LCvPuz7rPv1+dyyq64RU3lGeJZ/+BwqermABcHFB8WWb07nv32pG+6/lLVRUA1G0v8Lqu2Ffb74ZhGG0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxtk5oUa3AHpQROpwm04Yyd7uVSEV9GNBU1KGm8Ya2VCuIpHD6J Q6POfkY3MDki9uA3G2yNhPwHggyXDUUMM39VOglSfo04dLlZgh4ETslh X-Gm-Gg: AeBDiesr5sXWj8JglpMcWl+BOu272lAR1/NIuE+V7cmgaHE92vCrawgjLCJU9jzHO3j Q04hdSwbUHEEFzpvjmzvBYOQFwkkfgOna882YNWhsfSFZbpO8T8mT3NVxgy5nP6LeIBSutTQviB geKX/vwSNXHANLcC1VSMiCmfhGf+R2Zy9cKJolwEhwLXginzeEjsaQQmu+wicDuJJM9+7qSD6HJ BQr/8kP+TaDGPusu6R7GS0+F6VSjsJQRQq1g0Gzpt/smrrDeHCqpLez9dhBgNhfw2+KBEP2klNR NwYp1PKVrMJlE4Zqf6a3jJGrAXe0gy37ppdAk6wMCS4zqbwjrpunNyJtNhE/os48RST+cmQrtj0 EU0HLHd8RCKxO9aNEpxnJ77BTfiVKPx2wKCGw3xuC76spNkrmPAG4lI15VupHyckBiu3Ud7JuhK xo0csjfJSlHTm0pS1krvUVHrh+RYsTJS6xbzdy8ndLZdXTJyIsJzeQ5M5hYMhi0EMOSC6xShuDu nfqhI49En0LX+UAlMPIIeSecBLelOxwcf6+5lQLvI8b0mHQMoZxZxf9 X-Received: by 2002:a05:620a:31a4:b0:8ee:a1d:baf1 with SMTP id af79cd13be357-8fa8922aa56mr779761685a.42.1777587374557; Thu, 30 Apr 2026 15:16:14 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d:7285:c2ff:fe45:8a32]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8fbf3f20c99sm37649485a.45.2026.04.30.15.16.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2026 15:16:13 -0700 (PDT) From: Rosen Penev To: platform-driver-x86@vger.kernel.org Cc: Kenneth Chan , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCH] platform/x86: panasonic-laptop: simplify allocation of sinf Date: Thu, 30 Apr 2026 15:15:55 -0700 Message-ID: <20260430221555.83351-1-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Change to a flexible array member to allocate once instead of twice. Use __counted_by for extra runtime analysis. Move the counting variable assignment to right after allocation as done by kzalloc_flex for GCC 15 and above. Remove + 1 to allocation. It's already done in the previous line. Signed-off-by: Rosen Penev --- v3: Rephrased. v2: Rebased. drivers/platform/x86/panasonic-laptop.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86= /panasonic-laptop.c index 1337f7c49805..2fe8ff0d32a8 100644 --- a/drivers/platform/x86/panasonic-laptop.c +++ b/drivers/platform/x86/panasonic-laptop.c @@ -246,11 +246,11 @@ struct pcc_acpi { int ac_brightness; int dc_brightness; int current_brightness; - u32 *sinf; struct acpi_device *device; struct input_dev *input_dev; struct backlight_device *backlight; struct platform_device *platform; + u32 sinf[] __counted_by(num_sifr); }; /* @@ -1003,21 +1003,15 @@ static int acpi_pcc_hotkey_probe(struct platform_de= vice *pdev) */ num_sifr++; - pcc =3D kzalloc_obj(struct pcc_acpi); + pcc =3D kzalloc_flex(*pcc, sinf, num_sifr); if (!pcc) { pr_err("Couldn't allocate mem for pcc"); return -ENOMEM; } - pcc->sinf =3D kcalloc(num_sifr + 1, sizeof(u32), GFP_KERNEL); - if (!pcc->sinf) { - result =3D -ENOMEM; - goto out_hotkey; - } - + pcc->num_sifr =3D num_sifr; pcc->device =3D device; pcc->handle =3D device->handle; - pcc->num_sifr =3D num_sifr; device->driver_data =3D pcc; strscpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME); strscpy(acpi_device_class(device), ACPI_PCC_CLASS); @@ -1025,7 +1019,7 @@ static int acpi_pcc_hotkey_probe(struct platform_devi= ce *pdev) result =3D acpi_pcc_init_input(pcc); if (result) { pr_err("Error installing keyinput handler\n"); - goto out_sinf; + goto out_hotkey; } if (!acpi_pcc_retrieve_biosdata(pcc)) { @@ -1106,10 +1100,8 @@ static int acpi_pcc_hotkey_probe(struct platform_dev= ice *pdev) backlight_device_unregister(pcc->backlight); out_input: input_unregister_device(pcc->input_dev); -out_sinf: - device->driver_data =3D NULL; - kfree(pcc->sinf); out_hotkey: + device->driver_data =3D NULL; kfree(pcc); return result; @@ -1139,7 +1131,6 @@ static void acpi_pcc_hotkey_remove(struct platform_de= vice *pdev) device->driver_data =3D NULL; - kfree(pcc->sinf); kfree(pcc); } -- 2.54.0