Skip to content

Commit 938835a

Browse files
gregkhandy-shev
authored andcommitted
platform/x86: intel_pmc_core: do not create a static struct device
A struct device is a dynamic structure, with reference counting. "Tricking" the kernel to make a dynamic structure static, by working around the driver core release detection logic, is not nice. Because of this, this code has been used as an example for others on "how to do things", which is just about the worst thing possible to have happen. Fix this all up by making the platform device dynamic and providing a real release function. Cc: Rajneesh Bhardwaj <[email protected]> Cc: Vishwanath Somayaji <[email protected]> Cc: Darren Hart <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: Rajat Jain <[email protected]> Cc: [email protected] Cc: [email protected] Reported-by: Maximilian Luz <[email protected]> Fixes: b02f6a2 ("platform/x86: intel_pmc_core: Attach using APCI HID "INT33A1"") Signed-off-by: Greg Kroah-Hartman <[email protected]> Acked-by: Rajat Jain <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]>
1 parent 2b06a1c commit 938835a

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

drivers/platform/x86/intel_pmc_core_pltdrv.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@
2020

2121
static void intel_pmc_core_release(struct device *dev)
2222
{
23-
/* Nothing to do. */
23+
kfree(dev);
2424
}
2525

26-
static struct platform_device pmc_core_device = {
27-
.name = "intel_pmc_core",
28-
.dev = {
29-
.release = intel_pmc_core_release,
30-
},
31-
};
26+
static struct platform_device *pmc_core_device;
3227

3328
/*
3429
* intel_pmc_core_platform_ids is the list of platforms where we want to
@@ -52,19 +47,32 @@ MODULE_DEVICE_TABLE(x86cpu, intel_pmc_core_platform_ids);
5247

5348
static int __init pmc_core_platform_init(void)
5449
{
50+
int retval;
51+
5552
/* Skip creating the platform device if ACPI already has a device */
5653
if (acpi_dev_present("INT33A1", NULL, -1))
5754
return -ENODEV;
5855

5956
if (!x86_match_cpu(intel_pmc_core_platform_ids))
6057
return -ENODEV;
6158

62-
return platform_device_register(&pmc_core_device);
59+
pmc_core_device = kzalloc(sizeof(*pmc_core_device), GFP_KERNEL);
60+
if (!pmc_core_device)
61+
return -ENOMEM;
62+
63+
pmc_core_device->name = "intel_pmc_core";
64+
pmc_core_device->dev.release = intel_pmc_core_release;
65+
66+
retval = platform_device_register(pmc_core_device);
67+
if (retval)
68+
kfree(pmc_core_device);
69+
70+
return retval;
6371
}
6472

6573
static void __exit pmc_core_platform_exit(void)
6674
{
67-
platform_device_unregister(&pmc_core_device);
75+
platform_device_unregister(pmc_core_device);
6876
}
6977

7078
module_init(pmc_core_platform_init);

0 commit comments

Comments
 (0)