* [PATCHv2] platform/x86: panasonic-laptop: simplify allocation of sinf
@ 2026-03-26 2:45 Rosen Penev
2026-03-31 15:02 ` Ilpo Järvinen
0 siblings, 1 reply; 4+ messages in thread
From: Rosen Penev @ 2026-03-26 2:45 UTC (permalink / raw)
To: platform-driver-x86
Cc: Kenneth Chan, Hans de Goede, Ilpo Järvinen, Kees Cook,
Gustavo A. R. Silva, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
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 <rosenp@gmail.com>
---
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_device *pdev)
*/
num_sifr++;
- pcc = kzalloc_obj(struct pcc_acpi);
+ pcc = kzalloc_flex(*pcc, sinf, num_sifr);
if (!pcc) {
pr_err("Couldn't allocate mem for pcc");
return -ENOMEM;
}
- pcc->sinf = kcalloc(num_sifr + 1, sizeof(u32), GFP_KERNEL);
- if (!pcc->sinf) {
- result = -ENOMEM;
- goto out_hotkey;
- }
-
+ pcc->num_sifr = num_sifr;
pcc->device = device;
pcc->handle = device->handle;
- pcc->num_sifr = num_sifr;
device->driver_data = 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_device *pdev)
result = 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_device *pdev)
backlight_device_unregister(pcc->backlight);
out_input:
input_unregister_device(pcc->input_dev);
-out_sinf:
- device->driver_data = NULL;
- kfree(pcc->sinf);
out_hotkey:
+ device->driver_data = NULL;
kfree(pcc);
return result;
@@ -1139,7 +1131,6 @@ static void acpi_pcc_hotkey_remove(struct platform_device *pdev)
device->driver_data = NULL;
- kfree(pcc->sinf);
kfree(pcc);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCHv2] platform/x86: panasonic-laptop: simplify allocation of sinf
2026-03-26 2:45 [PATCHv2] platform/x86: panasonic-laptop: simplify allocation of sinf Rosen Penev
@ 2026-03-31 15:02 ` Ilpo Järvinen
2026-03-31 15:26 ` Gustavo A. R. Silva
0 siblings, 1 reply; 4+ messages in thread
From: Ilpo Järvinen @ 2026-03-31 15:02 UTC (permalink / raw)
To: platform-driver-x86, Rosen Penev
Cc: Kenneth Chan, Hans de Goede, Kees Cook, Gustavo A. R. Silva,
linux-kernel, linux-hardening
On Wed, 25 Mar 2026 19:45:25 -0700, Rosen Penev wrote:
> 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.
>
> [...]
Thank you for your contribution, it has been applied to my local
review-ilpo-next branch. Note it will show up in the public
platform-drivers-x86/review-ilpo-next branch only once I've pushed my
local branch there, which might take a while.
The list of commits applied:
[1/1] platform/x86: panasonic-laptop: simplify allocation of sinf
commit: e75869527c720c4ed1458cfbe25e92186950e43a
--
i.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCHv2] platform/x86: panasonic-laptop: simplify allocation of sinf
2026-03-31 15:02 ` Ilpo Järvinen
@ 2026-03-31 15:26 ` Gustavo A. R. Silva
2026-03-31 15:44 ` Ilpo Järvinen
0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2026-03-31 15:26 UTC (permalink / raw)
To: Ilpo Järvinen, platform-driver-x86, Rosen Penev
Cc: Kenneth Chan, Hans de Goede, Kees Cook, Gustavo A. R. Silva,
linux-kernel, linux-hardening
On 3/31/26 09:02, Ilpo Järvinen wrote:
> On Wed, 25 Mar 2026 19:45:25 -0700, Rosen Penev wrote:
>
>> 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.
This is misinformation and should be phrased differently[1]
-Gustavo
[1] https://lore.kernel.org/linux-hardening/37378f49-437f-438b-ad6c-d60480feb306@embeddedor.com/
>>
>> Remove + 1 to allocation. It's already done in the previous line.
>>
>> [...]
>
>
> Thank you for your contribution, it has been applied to my local
> review-ilpo-next branch. Note it will show up in the public
> platform-drivers-x86/review-ilpo-next branch only once I've pushed my
> local branch there, which might take a while.
>
> The list of commits applied:
> [1/1] platform/x86: panasonic-laptop: simplify allocation of sinf
> commit: e75869527c720c4ed1458cfbe25e92186950e43a
>
> --
> i.
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCHv2] platform/x86: panasonic-laptop: simplify allocation of sinf
2026-03-31 15:26 ` Gustavo A. R. Silva
@ 2026-03-31 15:44 ` Ilpo Järvinen
0 siblings, 0 replies; 4+ messages in thread
From: Ilpo Järvinen @ 2026-03-31 15:44 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: platform-driver-x86, Rosen Penev, Kenneth Chan, Hans de Goede,
Kees Cook, Gustavo A. R. Silva, LKML, linux-hardening
[-- Attachment #1: Type: text/plain, Size: 1250 bytes --]
On Tue, 31 Mar 2026, Gustavo A. R. Silva wrote:
>
>
> On 3/31/26 09:02, Ilpo Järvinen wrote:
> > On Wed, 25 Mar 2026 19:45:25 -0700, Rosen Penev wrote:
> >
> > > 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.
>
> This is misinformation and should be phrased differently[1]
Okay. I'll drop the patch for now.
--
i.
>
> -Gustavo
>
> [1]
> https://lore.kernel.org/linux-hardening/37378f49-437f-438b-ad6c-d60480feb306@embeddedor.com/
>
> > >
> > > Remove + 1 to allocation. It's already done in the previous line.
> > >
> > > [...]
> >
> >
> > Thank you for your contribution, it has been applied to my local
> > review-ilpo-next branch. Note it will show up in the public
> > platform-drivers-x86/review-ilpo-next branch only once I've pushed my
> > local branch there, which might take a while.
> >
> > The list of commits applied:
> > [1/1] platform/x86: panasonic-laptop: simplify allocation of sinf
> > commit: e75869527c720c4ed1458cfbe25e92186950e43a
> >
> > --
> > i.
> >
> >
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-31 15:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-26 2:45 [PATCHv2] platform/x86: panasonic-laptop: simplify allocation of sinf Rosen Penev
2026-03-31 15:02 ` Ilpo Järvinen
2026-03-31 15:26 ` Gustavo A. R. Silva
2026-03-31 15:44 ` Ilpo Järvinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox