[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c6a0685d-e318-4e54-bae4-3d28ee9f7e8b@amd.com>
Date: Thu, 9 Jan 2025 10:36:49 -0600
From: Mario Limonciello <mario.limonciello@....com>
To: Kurt Borja <kuurtb@...il.com>, platform-driver-x86@...r.kernel.org
Cc: "Rafael J. Wysocki" <rafael@...nel.org>, Len Brown <lenb@...nel.org>,
linux-acpi@...r.kernel.org, linux-kernel@...r.kernel.org,
Armin Wolf <W_Armin@....de>, Joshua Grisham <josh@...huagrisham.com>,
"Derek J . Clark" <derekjohn.clark@...il.com>,
Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
Hans de Goede <hdegoede@...hat.com>, Maximilian Luz
<luzmaximilian@...il.com>, "Lee, Chun-Yi" <jlee@...e.com>,
Shyam Sundar S K <Shyam-sundar.S-k@....com>,
Corentin Chary <corentin.chary@...il.com>, "Luke D. Jones"
<luke@...nes.dev>, Lyndon Sanche <lsanche@...deno.ca>,
Ike Panhc <ike.pan@...onical.com>,
Henrique de Moraes Holschuh <hmh@....eng.br>,
Mark Pearson <mpearson-lenovo@...ebb.ca>,
Colin Ian King <colin.i.king@...il.com>,
Alexis Belmonte <alexbelm48@...il.com>,
Uwe Kleine-König <u.kleine-koenig@...libre.com>,
Ai Chao <aichao@...inos.cn>, Gergo Koteles <soyer@....hu>,
Dell.Client.Kernel@...l.com, ibm-acpi-devel@...ts.sourceforge.net
Subject: Re: [PATCH 03/18] ACPI: platform_profile: Replace *class_dev member
with class_dev
On 1/9/2025 09:06, Kurt Borja wrote:
> 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.
>
> Signed-off-by: Kurt Borja <kuurtb@...il.com>
Reviewed-by: Mario Limonciello <mario.limonciello@....com>
> ---
> drivers/acpi/platform_profile.c | 36 +++++++++++++++++---------------
> include/linux/platform_profile.h | 3 ++-
> 2 files changed, 21 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
> index 9cb82173947c..3cbde8dfed0b 100644
> --- a/drivers/acpi/platform_profile.c
> +++ b/drivers/acpi/platform_profile.c
> @@ -10,6 +10,8 @@
> #include <linux/platform_profile.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 const char * const profile_names[] = {
> @@ -60,7 +62,7 @@ static int _store_class_profile(struct device *dev, void *data)
> int *bit = (int *)data;
>
> lockdep_assert_held(&profile_lock);
> - handler = dev_get_drvdata(dev);
> + handler = to_pprof_handler(dev);
> if (!test_bit(*bit, handler->choices))
> return -EOPNOTSUPP;
>
> @@ -76,11 +78,11 @@ static int _store_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);
> - sysfs_notify(&handler->class_dev->kobj, NULL, "profile");
> - kobject_uevent(&handler->class_dev->kobj, KOBJ_CHANGE);
> + sysfs_notify(&handler->class_dev.kobj, NULL, "profile");
> + kobject_uevent(&handler->class_dev.kobj, KOBJ_CHANGE);
>
> return 0;
> }
> @@ -100,7 +102,7 @@ static int get_class_profile(struct device *dev,
> int err;
>
> lockdep_assert_held(&profile_lock);
> - handler = dev_get_drvdata(dev);
> + handler = to_pprof_handler(dev);
> err = handler->ops->profile_get(handler, &val);
> if (err) {
> pr_err("Failed to get profile for handler %s\n", handler->name);
> @@ -124,7 +126,7 @@ static int get_class_profile(struct device *dev,
> */
> 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);
> }
> @@ -142,7 +144,7 @@ static ssize_t choices_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 _commmon_choices_show(handler->choices, buf);
> }
> @@ -229,7 +231,7 @@ static int _aggregate_choices(struct device *dev, void *data)
> unsigned long *aggregate = data;
>
> lockdep_assert_held(&profile_lock);
> - handler = dev_get_drvdata(dev);
> + handler = to_pprof_handler(dev);
> if (test_bit(PLATFORM_PROFILE_LAST, aggregate))
> bitmap_copy(aggregate, handler->choices, PLATFORM_PROFILE_LAST);
> else
> @@ -410,7 +412,7 @@ static const struct attribute_group platform_profile_group = {
> void platform_profile_notify(struct platform_profile_handler *pprof)
> {
> 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");
> }
> @@ -485,13 +487,13 @@ int platform_profile_register(struct platform_profile_handler *pprof)
> pprof->minor = ida_alloc(&platform_profile_ida, GFP_KERNEL);
> if (pprof->minor < 0)
> return pprof->minor;
> - pprof->class_dev = device_create(&platform_profile_class, pprof->dev,
> - MKDEV(0, 0), pprof, "platform-profile-%d",
> - pprof->minor);
> - if (IS_ERR(pprof->class_dev)) {
> - err = PTR_ERR(pprof->class_dev);
> +
> + pprof->class_dev.class = &platform_profile_class;
> + pprof->class_dev.parent = pprof->dev;
> + dev_set_name(&pprof->class_dev, "platform-profile-%d", pprof->minor);
> + err = device_register(&pprof->class_dev);
> + if (err)
> goto cleanup_ida;
> - }
>
> sysfs_notify(acpi_kobj, NULL, "platform_profile");
>
> @@ -502,7 +504,7 @@ int platform_profile_register(struct platform_profile_handler *pprof)
> return 0;
>
> cleanup_cur:
> - device_unregister(pprof->class_dev);
> + device_unregister(&pprof->class_dev);
>
> cleanup_ida:
> ida_free(&platform_profile_ida, pprof->minor);
> @@ -517,7 +519,7 @@ int platform_profile_remove(struct platform_profile_handler *pprof)
> guard(mutex)(&profile_lock);
>
> id = pprof->minor;
> - device_unregister(pprof->class_dev);
> + device_unregister(&pprof->class_dev);
> ida_free(&platform_profile_ida, id);
>
> sysfs_notify(acpi_kobj, NULL, "platform_profile");
> diff --git a/include/linux/platform_profile.h b/include/linux/platform_profile.h
> index 972a62be60b2..f549067539af 100644
> --- a/include/linux/platform_profile.h
> +++ b/include/linux/platform_profile.h
> @@ -9,6 +9,7 @@
> #ifndef _PLATFORM_PROFILE_H_
> #define _PLATFORM_PROFILE_H_
>
> +#include <linux/device.h>
> #include <linux/bitops.h>
>
> /*
> @@ -40,7 +41,7 @@ struct platform_profile_ops {
> struct platform_profile_handler {
> const char *name;
> struct device *dev;
> - struct device *class_dev;
> + struct device class_dev;
> int minor;
> unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
> const struct platform_profile_ops *ops;
Powered by blists - more mailing lists