platform/x86: panasonic-laptop: simplify allocation of sinf

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 <rosenp@gmail.com>
Link: https://patch.msgid.link/20260430221555.83351-1-rosenp@gmail.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
This commit is contained in:
Rosen Penev
2026-04-30 15:15:55 -07:00
committed by Ilpo Järvinen
parent 18bc6ce6bb
commit a3d0dbd18c

View File

@@ -246,11 +246,11 @@ struct pcc_acpi {
int ac_brightness; int ac_brightness;
int dc_brightness; int dc_brightness;
int current_brightness; int current_brightness;
u32 *sinf;
struct acpi_device *device; struct acpi_device *device;
struct input_dev *input_dev; struct input_dev *input_dev;
struct backlight_device *backlight; struct backlight_device *backlight;
struct platform_device *platform; 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++; num_sifr++;
pcc = kzalloc_obj(struct pcc_acpi); pcc = kzalloc_flex(*pcc, sinf, num_sifr);
if (!pcc) { if (!pcc) {
pr_err("Couldn't allocate mem for pcc"); pr_err("Couldn't allocate mem for pcc");
return -ENOMEM; return -ENOMEM;
} }
pcc->sinf = kcalloc(num_sifr + 1, sizeof(u32), GFP_KERNEL); pcc->num_sifr = num_sifr;
if (!pcc->sinf) {
result = -ENOMEM;
goto out_hotkey;
}
pcc->device = device; pcc->device = device;
pcc->handle = device->handle; pcc->handle = device->handle;
pcc->num_sifr = num_sifr;
device->driver_data = pcc; device->driver_data = pcc;
strscpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME); strscpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME);
strscpy(acpi_device_class(device), ACPI_PCC_CLASS); 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); result = acpi_pcc_init_input(pcc);
if (result) { if (result) {
pr_err("Error installing keyinput handler\n"); pr_err("Error installing keyinput handler\n");
goto out_sinf; goto out_hotkey;
} }
if (!acpi_pcc_retrieve_biosdata(pcc)) { 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); backlight_device_unregister(pcc->backlight);
out_input: out_input:
input_unregister_device(pcc->input_dev); input_unregister_device(pcc->input_dev);
out_sinf:
device->driver_data = NULL;
kfree(pcc->sinf);
out_hotkey: out_hotkey:
device->driver_data = NULL;
kfree(pcc); kfree(pcc);
return result; return result;
@@ -1139,7 +1131,6 @@ static void acpi_pcc_hotkey_remove(struct platform_device *pdev)
device->driver_data = NULL; device->driver_data = NULL;
kfree(pcc->sinf);
kfree(pcc); kfree(pcc);
} }