platform/x86: panasonic-laptop: simplify allocation of sinf
Subsystems (2)
PATCH 1/1 platform/x86: panasonic-laptop: simplify allocation of sinf
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.
--- drivers/platform/x86/panasonic-laptop.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)
drivers/platform/x86/panasonic-laptop.c +4 -13
@@ -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); };/*
@@ -1017,21 +1017,15 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)*/ 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 );
@@ -1039,7 +1033,7 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device) 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)) {
@@ -1111,8 +1105,6 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)backlight_device_unregister (pcc->backlight); out_input:input_unregister_device (pcc->input_dev); -out_sinf: -kfree (pcc->sinf); out_hotkey:kfree (pcc);
@@ -1140,7 +1132,6 @@ static void acpi_pcc_hotkey_remove(struct acpi_device *device)input_unregister_device (pcc->input_dev); -kfree (pcc->sinf);kfree (pcc); }
Signature · 1 line
2.53.0
Quoted 7 lines · Rosen Penev
Change to a flexible array member to allocate once instead of twice.
Allows using
__counted_byfor 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.
Are you sure this is an accidental +1? I see the "num_sifr++" that happens earlier, but it's not immediately clear why either that or the +1 in the original allocation are needed. I'd like to understand why either/both are/aren't needed.
-Kees
Quoted 76 lines
Signed-off-by Rosen Penev <[email protected]>--- drivers/platform/x86/panasonic-laptop.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)drivers/platform/x86/panasonic-laptop.c +4
-13@@ -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); };/* @@ -1017,21 +1017,15 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)*/ 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 );@@ -1039,7 +1033,7 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device) 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)) {@@ -1111,8 +1105,6 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)backlight_device_unregister (pcc->backlight); out_input:input_unregister_device (pcc->input_dev); -out_sinf: -kfree (pcc->sinf); out_hotkey:kfree (pcc);@@ -1140,7 +1132,6 @@ static void acpi_pcc_hotkey_remove(struct acpi_device *device)input_unregister_device (pcc->input_dev); -kfree (pcc->sinf);kfree (pcc); }Signature · 1 line
2.53.0
Signature · 1 line
Kees Cook
Quoted 8 lines · Kees Cook
Quoted 6 lines · Rosen Penev
Change to a flexible array member to allocate once instead of twice.
Allows using
__counted_byfor extra runtime analysis. Move the counting variable assignment to right after allocation as required by__counted_by.
Quoted 6 lines
Quoted 1 line
Remove + 1 to allocation. It's already done in the previous line.
Are you sure this is an accidental +1? I see the "num_sifr++" that happens earlier, but it's not immediately clear why either that or the +1 in the original allocation are needed. I'd like to understand why either/both are/aren't needed.
Looks like a rebasing mistake to me honestly.
Quoted 82 lines
-Kees
Quoted 74 lines
Signed-off-by Rosen Penev <[email protected]>--- drivers/platform/x86/panasonic-laptop.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)drivers/platform/x86/panasonic-laptop.c +4
-14@@ -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); };/* @@ -1017,21 +1017,15 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)*/ 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 );@@ -1039,7 +1033,7 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device) 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)) {@@ -1111,8 +1105,6 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)backlight_device_unregister (pcc->backlight); out_input:input_unregister_device (pcc->input_dev); -out_sinf: -kfree (pcc->sinf); out_hotkey:kfree (pcc);@@ -1140,7 +1132,6 @@ static void acpi_pcc_hotkey_remove(struct acpi_device *device)input_unregister_device (pcc->input_dev); -kfree (pcc->sinf);kfree (pcc); } --Quoted 2 lines
2.53.0
--
Kees Cook
Ilpo Järvinen
maintainerQuoted 9 lines · Rosen Penev
Quoted 8 lines · Kees Cook
Quoted 6 lines · Rosen Penev
Change to a flexible array member to allocate once instead of twice.
Allows using
__counted_byfor extra runtime analysis. Move the counting variable assignment to right after allocation as required by__counted_by.
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Remove + 1 to allocation. It's already done in the previous line.
Are you sure this is an accidental +1? I see the "num_sifr++" that happens earlier, but it's not immediately clear why either that or the +1 in the original allocation are needed. I'd like to understand why either/both are/aren't needed.
There's a comment right before the increment:
/*
* Some DSDT-s have an off-by-one bug where the SINF package count is
* one higher than the SQTY reported value, allocate 1 entry extra.
*/
num_sifr++;..l.which comes from 33297cef3101 ("platform/x86: panasonic-laptop:
Allocate 1 entry extra in the sinf array").
So I don't know why you said it's not clear why it's there.
Quoted 1 line
Looks like a rebasing mistake to me honestly.
In which commit?
Signature · 1 line
i.
Quoted 26 lines · Ilpo Järvinen
Quoted 9 lines · Rosen Penev
Quoted 8 lines · Kees Cook
Quoted 6 lines · Rosen Penev
Change to a flexible array member to allocate once instead of twice.
Allows using
__counted_byfor extra runtime analysis. Move the counting variable assignment to right after allocation as required by__counted_by.Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Remove + 1 to allocation. It's already done in the previous line.
Are you sure this is an accidental +1? I see the "num_sifr++" that happens earlier, but it's not immediately clear why either that or the +1 in the original allocation are needed. I'd like to understand why either/both are/aren't needed.
There's a comment right before the increment:
/* * Some DSDT-s have an off-by-one bug where the SINF package count is * one higher than the SQTY reported value, allocate 1 entry extra. */ num_sifr++;
Quoted 8 lines
..l.which comes from
33297cef3101("platform/x86: panasonic-laptop:
Allocate 1 entry extra in the sinf array").So I don't know why you said it's not clear why it's there.
Quoted 1 line
Looks like a rebasing mistake to me honestly.
In which commit?
None in particular. Probably just a mistake.
Quoted 4 lines
--
i.