ACPI: platform_profile: Replace *class_dev member with class_dev

Instead of holding a reference to the class device, embed it the
platform_profile_handler. This involves manually creating and
registering the device and replacing dev_get_drvdata() with the newly
created to_pprof_handler() macro.

Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Kurt Borja <kuurtb@gmail.com>
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Link: https://lore.kernel.org/r/20250116002721.75592-2-kuurtb@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:
Kurt Borja
2025-01-15 19:27:03 -05:00
committed by Ilpo Järvinen
parent d98bf6a6ed
commit d960f14800
2 changed files with 22 additions and 18 deletions

View File

@@ -5,11 +5,12 @@
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/bits.h> #include <linux/bits.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/kdev_t.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/platform_profile.h> #include <linux/platform_profile.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
#define to_pprof_handler(d) (container_of(d, struct platform_profile_handler, class_dev))
static DEFINE_MUTEX(profile_lock); static DEFINE_MUTEX(profile_lock);
static const char * const profile_names[] = { static const char * const profile_names[] = {
@@ -60,7 +61,7 @@ static int _store_class_profile(struct device *dev, void *data)
int *bit = (int *)data; int *bit = (int *)data;
lockdep_assert_held(&profile_lock); lockdep_assert_held(&profile_lock);
handler = dev_get_drvdata(dev); handler = to_pprof_handler(dev);
if (!test_bit(*bit, handler->choices)) if (!test_bit(*bit, handler->choices))
return -EOPNOTSUPP; return -EOPNOTSUPP;
@@ -76,11 +77,11 @@ static int _store_class_profile(struct device *dev, void *data)
*/ */
static int _notify_class_profile(struct device *dev, void *data) static int _notify_class_profile(struct device *dev, void *data)
{ {
struct platform_profile_handler *handler = dev_get_drvdata(dev); struct platform_profile_handler *handler = to_pprof_handler(dev);
lockdep_assert_held(&profile_lock); lockdep_assert_held(&profile_lock);
sysfs_notify(&handler->class_dev->kobj, NULL, "profile"); sysfs_notify(&handler->class_dev.kobj, NULL, "profile");
kobject_uevent(&handler->class_dev->kobj, KOBJ_CHANGE); kobject_uevent(&handler->class_dev.kobj, KOBJ_CHANGE);
return 0; return 0;
} }
@@ -100,7 +101,7 @@ static int get_class_profile(struct device *dev,
int err; int err;
lockdep_assert_held(&profile_lock); lockdep_assert_held(&profile_lock);
handler = dev_get_drvdata(dev); handler = to_pprof_handler(dev);
err = handler->profile_get(handler, &val); err = handler->profile_get(handler, &val);
if (err) { if (err) {
pr_err("Failed to get profile for handler %s\n", handler->name); pr_err("Failed to get profile for handler %s\n", handler->name);
@@ -124,7 +125,7 @@ static int get_class_profile(struct device *dev,
*/ */
static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf)
{ {
struct platform_profile_handler *handler = dev_get_drvdata(dev); struct platform_profile_handler *handler = to_pprof_handler(dev);
return sysfs_emit(buf, "%s\n", handler->name); return sysfs_emit(buf, "%s\n", handler->name);
} }
@@ -142,7 +143,7 @@ static ssize_t choices_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct platform_profile_handler *handler = dev_get_drvdata(dev); struct platform_profile_handler *handler = to_pprof_handler(dev);
return _commmon_choices_show(handler->choices, buf); return _commmon_choices_show(handler->choices, buf);
} }
@@ -229,7 +230,7 @@ static int _aggregate_choices(struct device *dev, void *data)
unsigned long *aggregate = data; unsigned long *aggregate = data;
lockdep_assert_held(&profile_lock); lockdep_assert_held(&profile_lock);
handler = dev_get_drvdata(dev); handler = to_pprof_handler(dev);
if (test_bit(PLATFORM_PROFILE_LAST, aggregate)) if (test_bit(PLATFORM_PROFILE_LAST, aggregate))
bitmap_copy(aggregate, handler->choices, PLATFORM_PROFILE_LAST); bitmap_copy(aggregate, handler->choices, PLATFORM_PROFILE_LAST);
else else
@@ -410,7 +411,7 @@ static const struct attribute_group platform_profile_group = {
void platform_profile_notify(struct platform_profile_handler *pprof) void platform_profile_notify(struct platform_profile_handler *pprof)
{ {
scoped_cond_guard(mutex_intr, return, &profile_lock) { scoped_cond_guard(mutex_intr, return, &profile_lock) {
_notify_class_profile(pprof->class_dev, NULL); _notify_class_profile(&pprof->class_dev, NULL);
} }
sysfs_notify(acpi_kobj, NULL, "platform_profile"); sysfs_notify(acpi_kobj, NULL, "platform_profile");
} }
@@ -476,11 +477,13 @@ int platform_profile_register(struct platform_profile_handler *pprof)
pprof->minor = ida_alloc(&platform_profile_ida, GFP_KERNEL); pprof->minor = ida_alloc(&platform_profile_ida, GFP_KERNEL);
if (pprof->minor < 0) if (pprof->minor < 0)
return pprof->minor; return pprof->minor;
pprof->class_dev = device_create(&platform_profile_class, pprof->dev,
MKDEV(0, 0), pprof, "platform-profile-%d", pprof->class_dev.class = &platform_profile_class;
pprof->minor); pprof->class_dev.parent = pprof->dev;
if (IS_ERR(pprof->class_dev)) { dev_set_name(&pprof->class_dev, "platform-profile-%d", pprof->minor);
err = PTR_ERR(pprof->class_dev); err = device_register(&pprof->class_dev);
if (err) {
put_device(&pprof->class_dev);
goto cleanup_ida; goto cleanup_ida;
} }
@@ -493,7 +496,7 @@ int platform_profile_register(struct platform_profile_handler *pprof)
return 0; return 0;
cleanup_cur: cleanup_cur:
device_unregister(pprof->class_dev); device_unregister(&pprof->class_dev);
cleanup_ida: cleanup_ida:
ida_free(&platform_profile_ida, pprof->minor); ida_free(&platform_profile_ida, pprof->minor);
@@ -508,7 +511,7 @@ int platform_profile_remove(struct platform_profile_handler *pprof)
guard(mutex)(&profile_lock); guard(mutex)(&profile_lock);
id = pprof->minor; id = pprof->minor;
device_unregister(pprof->class_dev); device_unregister(&pprof->class_dev);
ida_free(&platform_profile_ida, id); ida_free(&platform_profile_ida, id);
sysfs_notify(acpi_kobj, NULL, "platform_profile"); sysfs_notify(acpi_kobj, NULL, "platform_profile");

View File

@@ -9,6 +9,7 @@
#ifndef _PLATFORM_PROFILE_H_ #ifndef _PLATFORM_PROFILE_H_
#define _PLATFORM_PROFILE_H_ #define _PLATFORM_PROFILE_H_
#include <linux/device.h>
#include <linux/bitops.h> #include <linux/bitops.h>
/* /*
@@ -30,7 +31,7 @@ enum platform_profile_option {
struct platform_profile_handler { struct platform_profile_handler {
const char *name; const char *name;
struct device *dev; struct device *dev;
struct device *class_dev; struct device class_dev;
int minor; int minor;
unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)]; unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
int (*profile_get)(struct platform_profile_handler *pprof, int (*profile_get)(struct platform_profile_handler *pprof,