Skip to content

Commit d960f14

Browse files
kuu-rtij-intel
authored andcommitted
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 <[email protected]> Signed-off-by: Kurt Borja <[email protected]> Reviewed-by: Mark Pearson <[email protected]> Tested-by: Mark Pearson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent d98bf6a commit d960f14

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

drivers/acpi/platform_profile.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
#include <linux/acpi.h>
66
#include <linux/bits.h>
77
#include <linux/init.h>
8-
#include <linux/kdev_t.h>
98
#include <linux/mutex.h>
109
#include <linux/platform_profile.h>
1110
#include <linux/sysfs.h>
1211

12+
#define to_pprof_handler(d) (container_of(d, struct platform_profile_handler, class_dev))
13+
1314
static DEFINE_MUTEX(profile_lock);
1415

1516
static const char * const profile_names[] = {
@@ -60,7 +61,7 @@ static int _store_class_profile(struct device *dev, void *data)
6061
int *bit = (int *)data;
6162

6263
lockdep_assert_held(&profile_lock);
63-
handler = dev_get_drvdata(dev);
64+
handler = to_pprof_handler(dev);
6465
if (!test_bit(*bit, handler->choices))
6566
return -EOPNOTSUPP;
6667

@@ -76,11 +77,11 @@ static int _store_class_profile(struct device *dev, void *data)
7677
*/
7778
static int _notify_class_profile(struct device *dev, void *data)
7879
{
79-
struct platform_profile_handler *handler = dev_get_drvdata(dev);
80+
struct platform_profile_handler *handler = to_pprof_handler(dev);
8081

8182
lockdep_assert_held(&profile_lock);
82-
sysfs_notify(&handler->class_dev->kobj, NULL, "profile");
83-
kobject_uevent(&handler->class_dev->kobj, KOBJ_CHANGE);
83+
sysfs_notify(&handler->class_dev.kobj, NULL, "profile");
84+
kobject_uevent(&handler->class_dev.kobj, KOBJ_CHANGE);
8485

8586
return 0;
8687
}
@@ -100,7 +101,7 @@ static int get_class_profile(struct device *dev,
100101
int err;
101102

102103
lockdep_assert_held(&profile_lock);
103-
handler = dev_get_drvdata(dev);
104+
handler = to_pprof_handler(dev);
104105
err = handler->profile_get(handler, &val);
105106
if (err) {
106107
pr_err("Failed to get profile for handler %s\n", handler->name);
@@ -124,7 +125,7 @@ static int get_class_profile(struct device *dev,
124125
*/
125126
static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf)
126127
{
127-
struct platform_profile_handler *handler = dev_get_drvdata(dev);
128+
struct platform_profile_handler *handler = to_pprof_handler(dev);
128129

129130
return sysfs_emit(buf, "%s\n", handler->name);
130131
}
@@ -142,7 +143,7 @@ static ssize_t choices_show(struct device *dev,
142143
struct device_attribute *attr,
143144
char *buf)
144145
{
145-
struct platform_profile_handler *handler = dev_get_drvdata(dev);
146+
struct platform_profile_handler *handler = to_pprof_handler(dev);
146147

147148
return _commmon_choices_show(handler->choices, buf);
148149
}
@@ -229,7 +230,7 @@ static int _aggregate_choices(struct device *dev, void *data)
229230
unsigned long *aggregate = data;
230231

231232
lockdep_assert_held(&profile_lock);
232-
handler = dev_get_drvdata(dev);
233+
handler = to_pprof_handler(dev);
233234
if (test_bit(PLATFORM_PROFILE_LAST, aggregate))
234235
bitmap_copy(aggregate, handler->choices, PLATFORM_PROFILE_LAST);
235236
else
@@ -410,7 +411,7 @@ static const struct attribute_group platform_profile_group = {
410411
void platform_profile_notify(struct platform_profile_handler *pprof)
411412
{
412413
scoped_cond_guard(mutex_intr, return, &profile_lock) {
413-
_notify_class_profile(pprof->class_dev, NULL);
414+
_notify_class_profile(&pprof->class_dev, NULL);
414415
}
415416
sysfs_notify(acpi_kobj, NULL, "platform_profile");
416417
}
@@ -476,11 +477,13 @@ int platform_profile_register(struct platform_profile_handler *pprof)
476477
pprof->minor = ida_alloc(&platform_profile_ida, GFP_KERNEL);
477478
if (pprof->minor < 0)
478479
return pprof->minor;
479-
pprof->class_dev = device_create(&platform_profile_class, pprof->dev,
480-
MKDEV(0, 0), pprof, "platform-profile-%d",
481-
pprof->minor);
482-
if (IS_ERR(pprof->class_dev)) {
483-
err = PTR_ERR(pprof->class_dev);
480+
481+
pprof->class_dev.class = &platform_profile_class;
482+
pprof->class_dev.parent = pprof->dev;
483+
dev_set_name(&pprof->class_dev, "platform-profile-%d", pprof->minor);
484+
err = device_register(&pprof->class_dev);
485+
if (err) {
486+
put_device(&pprof->class_dev);
484487
goto cleanup_ida;
485488
}
486489

@@ -493,7 +496,7 @@ int platform_profile_register(struct platform_profile_handler *pprof)
493496
return 0;
494497

495498
cleanup_cur:
496-
device_unregister(pprof->class_dev);
499+
device_unregister(&pprof->class_dev);
497500

498501
cleanup_ida:
499502
ida_free(&platform_profile_ida, pprof->minor);
@@ -508,7 +511,7 @@ int platform_profile_remove(struct platform_profile_handler *pprof)
508511
guard(mutex)(&profile_lock);
509512

510513
id = pprof->minor;
511-
device_unregister(pprof->class_dev);
514+
device_unregister(&pprof->class_dev);
512515
ida_free(&platform_profile_ida, id);
513516

514517
sysfs_notify(acpi_kobj, NULL, "platform_profile");

include/linux/platform_profile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef _PLATFORM_PROFILE_H_
1010
#define _PLATFORM_PROFILE_H_
1111

12+
#include <linux/device.h>
1213
#include <linux/bitops.h>
1314

1415
/*
@@ -30,7 +31,7 @@ enum platform_profile_option {
3031
struct platform_profile_handler {
3132
const char *name;
3233
struct device *dev;
33-
struct device *class_dev;
34+
struct device class_dev;
3435
int minor;
3536
unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
3637
int (*profile_get)(struct platform_profile_handler *pprof,

0 commit comments

Comments
 (0)