From: Kurt Borja <kuurtb@gmail.com>
To: platform-driver-x86@vger.kernel.org
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
"Len Brown" <lenb@kernel.org>,
linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
"Mario Limonciello" <mario.limonciello@amd.com>,
"Armin Wolf" <W_Armin@gmx.de>,
"Joshua Grisham" <josh@joshuagrisham.com>,
"Derek J. Clark" <derekjohn.clark@gmail.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Hans de Goede" <hdegoede@redhat.com>,
"Kurt Borja" <kuurtb@gmail.com>,
"Maximilian Luz" <luzmaximilian@gmail.com>,
"Lee, Chun-Yi" <jlee@suse.com>,
"Shyam Sundar S K" <Shyam-sundar.S-k@amd.com>,
"Corentin Chary" <corentin.chary@gmail.com>,
"Luke D. Jones" <luke@ljones.dev>,
"Lyndon Sanche" <lsanche@lyndeno.ca>,
"Ike Panhc" <ike.pan@canonical.com>,
"Henrique de Moraes Holschuh" <hmh@hmh.eng.br>,
"Mark Pearson" <mpearson-lenovo@squebb.ca>,
"Alexis Belmonte" <alexbelm48@gmail.com>,
"Ai Chao" <aichao@kylinos.cn>, "Gergo Koteles" <soyer@irl.hu>,
Dell.Client.Kernel@dell.com,
ibm-acpi-devel@lists.sourceforge.net
Subject: [PATCH v3 01/19] ACPI: platform_profile: Replace *class_dev member with class_dev
Date: Wed, 15 Jan 2025 02:10:04 -0500 [thread overview]
Message-ID: <20250115071022.4815-2-kuurtb@gmail.com> (raw)
In-Reply-To: <20250115071022.4815-1-kuurtb@gmail.com>
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>
---
drivers/acpi/platform_profile.c | 37 +++++++++++++++++---------------
include/linux/platform_profile.h | 3 ++-
2 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
index 4c4200a0b1a6..15f24adc57d4 100644
--- a/drivers/acpi/platform_profile.c
+++ b/drivers/acpi/platform_profile.c
@@ -5,11 +5,12 @@
#include <linux/acpi.h>
#include <linux/bits.h>
#include <linux/init.h>
-#include <linux/kdev_t.h>
#include <linux/mutex.h>
#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 +61,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 +77,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 +101,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->profile_get(handler, &val);
if (err) {
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)
{
- 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 +143,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 +230,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 +411,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");
}
@@ -476,11 +477,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) {
+ put_device(&pprof->class_dev);
goto cleanup_ida;
}
@@ -493,7 +496,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);
@@ -508,7 +511,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 f1cd4b65e351..8a9b8754f9ac 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>
/*
@@ -30,7 +31,7 @@ enum platform_profile_option {
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)];
int (*profile_get)(struct platform_profile_handler *pprof,
--
2.48.0
next prev parent reply other threads:[~2025-01-15 7:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-15 7:10 [PATCH v3 00/19] Hide platform_profile_handler from consumers Kurt Borja
2025-01-15 7:10 ` Kurt Borja [this message]
2025-01-15 7:10 ` [PATCH v3 02/19] ACPI: platform_profile: Let drivers set drvdata to the class device Kurt Borja
2025-01-15 7:10 ` [PATCH v3 03/19] ACPI: platform_profile: Remove platform_profile_handler from callbacks Kurt Borja
2025-01-15 7:10 ` [PATCH v3 04/19] ACPI: platform_profile: Add `ops` member to handlers Kurt Borja
2025-01-15 7:10 ` [PATCH v3 05/19] ACPI: platform_profile: Add `probe` to platform_profile_ops Kurt Borja
2025-01-15 16:43 ` Mario Limonciello
2025-01-15 7:10 ` [PATCH v3 06/19] platform/surface: surface_platform_profile: Use devm_platform_profile_register() Kurt Borja
2025-01-15 7:10 ` [PATCH v3 07/19] platform/x86: acer-wmi: " Kurt Borja
2025-01-15 7:10 ` [PATCH v3 08/19] platform/x86: amd: pmf: sps: " Kurt Borja
2025-01-15 7:10 ` [PATCH v3 09/19] platform/x86: asus-wmi: " Kurt Borja
2025-01-15 14:08 ` Ilpo Järvinen
2025-01-15 14:41 ` Kurt Borja
2025-01-15 7:10 ` [PATCH v3 10/19] platform/x86: dell-pc: " Kurt Borja
2025-01-15 7:10 ` [PATCH v3 11/19] platform/x86: ideapad-laptop: " Kurt Borja
2025-01-15 7:10 ` [PATCH v3 12/19] platform/x86: hp-wmi: " Kurt Borja
2025-01-15 7:10 ` [PATCH v3 13/19] platform/x86: inspur_platform_profile: " Kurt Borja
2025-01-15 7:10 ` [PATCH v3 14/19] platform/x86: thinkpad_acpi: " Kurt Borja
2025-01-15 7:10 ` [PATCH v3 15/19] ACPI: platform_profile: Remove platform_profile_handler from exported symbols Kurt Borja
2025-01-15 7:10 ` [PATCH v3 16/19] ACPI: platform_profile: Move platform_profile_handler Kurt Borja
2025-01-15 7:10 ` [PATCH v3 17/19] ACPI: platform_profile: Clean platform_profile_handler Kurt Borja
2025-01-15 7:10 ` [PATCH v3 18/19] ACPI: platform_profile: Add documentation Kurt Borja
2025-01-15 7:10 ` [PATCH v3 19/19] ACPI: platform_profile: Add a prefix to log messages Kurt Borja
2025-01-15 16:45 ` Mario Limonciello
2025-01-15 20:01 ` Kurt Borja
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250115071022.4815-2-kuurtb@gmail.com \
--to=kuurtb@gmail.com \
--cc=Dell.Client.Kernel@dell.com \
--cc=Shyam-sundar.S-k@amd.com \
--cc=W_Armin@gmx.de \
--cc=aichao@kylinos.cn \
--cc=alexbelm48@gmail.com \
--cc=corentin.chary@gmail.com \
--cc=derekjohn.clark@gmail.com \
--cc=hdegoede@redhat.com \
--cc=hmh@hmh.eng.br \
--cc=ibm-acpi-devel@lists.sourceforge.net \
--cc=ike.pan@canonical.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jlee@suse.com \
--cc=josh@joshuagrisham.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lsanche@lyndeno.ca \
--cc=luke@ljones.dev \
--cc=luzmaximilian@gmail.com \
--cc=mario.limonciello@amd.com \
--cc=mpearson-lenovo@squebb.ca \
--cc=platform-driver-x86@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=soyer@irl.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox