From nobody Mon Apr 6 09:10:04 2026 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.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 0E9A51C549F for ; Fri, 20 Mar 2026 00:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773967788; cv=none; b=IeyEFnmT118wXohA2VPdMg+RDvZ3uUKdoKip+rPqrnUyro1uABfuovRVFw4pYrdGAp8cCmXR68bDVai8KM/+f9TQ+6s3QPYjB3e0qmoWSuhqNfnzrrt1Is6dorQFaUMy4tRnlJkjmcBKmfnywxkf6V0antWi+Cue4zmSVmluhfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773967788; c=relaxed/simple; bh=aj+amzHykz0VP8Omkgv4PdojHt+uGLfiOHMytOe5yJk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=qzKIvINDl+tdsiMqm1oKTgIEStbJh5KtrLM1K6oPH1qupHLh4f+1JRFQcGnjNfTr1g7XcZ3/V66xM641+EAJWI3d+OeYLVYElGYSPV3A/Vm1hegDy+WZCJCJFl3bncQ/bq4GmQkX07rn6qKTAs+urDJpWXSAWtiO/HpN5hdm9W4= 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=YBGJqv5S; arc=none smtp.client-ip=209.85.214.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="YBGJqv5S" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2b07069e2efso8010075ad.3 for ; Thu, 19 Mar 2026 17:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773967786; x=1774572586; 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=IpBmk5APBUS2BhHlK8KMNZh8R0vKiaeWox7A/MEW/zg=; b=YBGJqv5Ss08VGKNl6/PqnSL9fts+KjEqoZJ3BW44RhBpm6HD0hEVdu37PKeN894VwM E46q+pqCEuoISqRD0DwhoHcApkb9K/kO6uCYRmGOMzKIhiD3mXsF/SRXBJm39ub/B5qR rZcPPT7jnADzDohlENu0P3K12Vae45vpUMHx0GlgjdY2I6Bt0OtTNK9NCim/9TU8G9/z yc9svMbqGpOp6B5GHzw9ybA+XWheAZErLS56oDLPm9zYZ+ku4n7hpTLKbkKXPCS6q4Wh 2pgYRhbKRRfJnr75wJNJZlzzc8vpHJLwo4eb6YHfVPcqeQh0YgJa0jHGiW10ZCmJuyZh /5fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773967786; x=1774572586; 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=IpBmk5APBUS2BhHlK8KMNZh8R0vKiaeWox7A/MEW/zg=; b=bvPRxW88h8Dy3XeyACX2CN8eXhRRLIPFDh1ouQm99GbwdrGiWguX2uXkGHEeJKw9ix 5kur67uK2tmwyuBaqa/FhS381jMTStLQ53JPZxdONbDBRwPE7se5PFTuSVHiZ/SEb8pE LAwkPJvWfe21hcrFcWUf19YZh2VGYZNbdD3dOhLJ/64Pn5stSm27QsZuU88Y2oUURnBG NEwklz8ioP1LO0G1I72L+FW63jmNd93hkeTQyoqCkPZoIR40wZQzuAKgV26Tbmg2kqU8 rSBOFV63ZmTIXRjhHIz5VUdMCHA9Y+HDzaYt6YYPiu3nYA7/H1L+htwBSWEnZ2t3dK4K 8RbQ== X-Forwarded-Encrypted: i=1; AJvYcCWT5tcCRxTGIjqFBDHOgMKcMK3PVJ0iU4v1bYkeImBDpsdl6MrPpEUYxUcZAlyNDUwP9GNEo50IovYUy7s=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9zt6CDaolqNAx2/t3aXehFGOVV3y+efyHwniGJZQAy67WBLGA 7bDZqAPWDogw1sraFWj2RjKJWIZbt/p3I+o40lDZv0UbvT7zFTgavGlK X-Gm-Gg: ATEYQzyM0guPPXGqtxsnd2oWSfITYMxDNb5IVtTRp/rSZp95WVgWC4cWBR9N7Bmy6wP USTuMgep1sootPGtl+/baX2U2U7dB7OUPoFDBX+GvcPQmxgk51mNTlXhav3gbTgXi50XvMj3mUR gFKW9XFzqNFnv5fbWbgvIHOf62sY8mU1mdhk8NlQu6bWHPHPUVENTt7Pfsi9WgVuyw8s5U0k3Sz Xqf5WWs7GT9Ajd/PlfJZX/2VoaiSPwYNoVHbdnWoaB6zOVgZUTrjURkzoYbj8QV2ZyDX2x9UtmN z15gg5YwMbFIgd4kLvvB1gN5t4EiE5r0YWlaipCgsTZD6CxAIbuJBapbZ73ODIza+HzlL/id8cM 06AoqN5rhInzPkF31bQL2ASiMJWCWqZ4/jf0iSoAcGauPsC9PEBwMbTef2D5X+9Qs+yU32P5dUw UQcLHtNFPPDt35jOu6zDDVbbkIUAwW5zY1g2vsnpwvFMwPzlr3sCnE2Qk= X-Received: by 2002:a17:903:124e:b0:2b0:5a4c:726b with SMTP id d9443c01a7336-2b0827ca665mr9999575ad.40.1773967786258; Thu, 19 Mar 2026 17:49:46 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b08353e94asm4299265ad.25.2026.03.19.17.49.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 17:49:45 -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, 19 Mar 2026 17:49:28 -0700 Message-ID: <20260320004928.29914-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.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. Allows using __counted_by for extra runtime analysis. Move the counting variable assignment to right after allocation as required by __counted_by. Remove + 1 to allocation. It's already done in the previous line. Signed-off-by: Rosen Penev --- drivers/platform/x86/panasonic-laptop.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86= /panasonic-laptop.c index d923ddaa4849..4d663fffbcc8 100644 --- a/drivers/platform/x86/panasonic-laptop.c +++ b/drivers/platform/x86/panasonic-laptop.c @@ -248,11 +248,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); }; =20 /* @@ -1017,21 +1017,15 @@ static int acpi_pcc_hotkey_add(struct acpi_device *= device) */ num_sifr++; =20 - 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; } =20 - 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); @@ -1039,7 +1033,7 @@ static int acpi_pcc_hotkey_add(struct acpi_device *de= vice) result =3D acpi_pcc_init_input(pcc); if (result) { pr_err("Error installing keyinput handler\n"); - goto out_sinf; + goto out_hotkey; } =20 if (!acpi_pcc_retrieve_biosdata(pcc)) { @@ -1111,8 +1105,6 @@ static int acpi_pcc_hotkey_add(struct acpi_device *de= vice) backlight_device_unregister(pcc->backlight); out_input: input_unregister_device(pcc->input_dev); -out_sinf: - kfree(pcc->sinf); out_hotkey: kfree(pcc); =20 @@ -1140,7 +1132,6 @@ static void acpi_pcc_hotkey_remove(struct acpi_device= *device) =20 input_unregister_device(pcc->input_dev); =20 - kfree(pcc->sinf); kfree(pcc); } =20 --=20 2.53.0