Skip to content

Commit

Permalink
platform/x86: intel_pmc_core: do not create a static struct device
Browse files Browse the repository at this point in the history
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 <rajneesh.bhardwaj@intel.com>
Cc: Vishwanath Somayaji <vishwanath.somayaji@intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: Rajat Jain <rajatja@google.com>
Cc: platform-driver-x86@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reported-by: Maximilian Luz <luzmaximilian@gmail.com>
Fixes: b02f6a2 ("platform/x86: intel_pmc_core: Attach using APCI HID "INT33A1"")
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Rajat Jain <rajatja@google.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  • Loading branch information
gregkh authored and andy-shev committed Sep 24, 2020
1 parent 2b06a1c commit 938835a
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions drivers/platform/x86/intel_pmc_core_pltdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@

static void intel_pmc_core_release(struct device *dev)
{
/* Nothing to do. */
kfree(dev);
}

static struct platform_device pmc_core_device = {
.name = "intel_pmc_core",
.dev = {
.release = intel_pmc_core_release,
},
};
static struct platform_device *pmc_core_device;

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

static int __init pmc_core_platform_init(void)
{
int retval;

/* Skip creating the platform device if ACPI already has a device */
if (acpi_dev_present("INT33A1", NULL, -1))
return -ENODEV;

if (!x86_match_cpu(intel_pmc_core_platform_ids))
return -ENODEV;

return platform_device_register(&pmc_core_device);
pmc_core_device = kzalloc(sizeof(*pmc_core_device), GFP_KERNEL);
if (!pmc_core_device)
return -ENOMEM;

pmc_core_device->name = "intel_pmc_core";
pmc_core_device->dev.release = intel_pmc_core_release;

retval = platform_device_register(pmc_core_device);
if (retval)
kfree(pmc_core_device);

return retval;
}

static void __exit pmc_core_platform_exit(void)
{
platform_device_unregister(&pmc_core_device);
platform_device_unregister(pmc_core_device);
}

module_init(pmc_core_platform_init);
Expand Down

0 comments on commit 938835a

Please sign in to comment.