From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Linux ACPI <linux-acpi@vger.kernel.org>
Cc: Linux PM <linux-pm@vger.kernel.org>, Armin Wolf <w_armin@gmx.de>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v2 1/5] ACPI: fan: Pass struct acpi_fan pointers to functions
Date: Wed, 25 Nov 2026 15:07:24 +0100 [thread overview]
Message-ID: <1976174.tdWV9SEqCh@rafael.j.wysocki> (raw)
In-Reply-To: <2859850.mvXUDI8C0e@rafael.j.wysocki>
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Pass a struct acpi_fan pointer as an argument to several functions in
the ACPI fan driver either instead of or in addition to a struct
acpi_device or a struct device pointer.
This allows acpi_driver_data() usage to be reduced and some other
simplifications to be made.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Armin Wolf <W_Armin@gmx.de>
---
v1 -> v2:
* Pass acpi_fan as the first argument to functions (Andy)
* Add R-by from Armin (thanks!)
---
drivers/acpi/fan.h | 4 ++--
drivers/acpi/fan_attr.c | 8 ++++----
drivers/acpi/fan_core.c | 42 ++++++++++++++++++-----------------------
3 files changed, 24 insertions(+), 30 deletions(-)
diff --git a/drivers/acpi/fan.h b/drivers/acpi/fan.h
index 3faa247af514..66dbcc138ddd 100644
--- a/drivers/acpi/fan.h
+++ b/drivers/acpi/fan.h
@@ -101,8 +101,8 @@ static inline bool acpi_fan_power_valid(u64 power)
}
int acpi_fan_get_fst(acpi_handle handle, struct acpi_fan_fst *fst);
-int acpi_fan_create_attributes(struct acpi_device *device);
-void acpi_fan_delete_attributes(struct acpi_device *device);
+int acpi_fan_create_attributes(struct acpi_fan *fan);
+void acpi_fan_delete_attributes(struct acpi_fan *fan);
#if IS_REACHABLE(CONFIG_HWMON)
int devm_acpi_fan_create_hwmon(struct device *dev);
diff --git a/drivers/acpi/fan_attr.c b/drivers/acpi/fan_attr.c
index 9b7fa52f3c2a..5b43b7bb0ab4 100644
--- a/drivers/acpi/fan_attr.c
+++ b/drivers/acpi/fan_attr.c
@@ -70,9 +70,9 @@ static ssize_t show_fine_grain_control(struct device *dev, struct device_attribu
return sysfs_emit(buf, "%d\n", fan->fif.fine_grain_ctrl);
}
-int acpi_fan_create_attributes(struct acpi_device *device)
+int acpi_fan_create_attributes(struct acpi_fan *fan)
{
- struct acpi_fan *fan = acpi_driver_data(device);
+ struct acpi_device *device = fan->adev;
int i, status;
/* _FST is present if we are here */
@@ -127,9 +127,9 @@ int acpi_fan_create_attributes(struct acpi_device *device)
return status;
}
-void acpi_fan_delete_attributes(struct acpi_device *device)
+void acpi_fan_delete_attributes(struct acpi_fan *fan)
{
- struct acpi_fan *fan = acpi_driver_data(device);
+ struct acpi_device *device = fan->adev;
int i;
sysfs_remove_file(&device->dev.kobj, &fan->fst_speed.attr);
diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c
index 4324ff5d9c4c..9b4b57614d66 100644
--- a/drivers/acpi/fan_core.c
+++ b/drivers/acpi/fan_core.c
@@ -222,10 +222,9 @@ static const struct thermal_cooling_device_ops fan_cooling_ops = {
* --------------------------------------------------------------------------
*/
-static int acpi_fan_get_fif(struct acpi_device *device)
+static int acpi_fan_get_fif(struct acpi_fan *fan, struct acpi_device *device)
{
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
- struct acpi_fan *fan = acpi_driver_data(device);
struct acpi_buffer format = { sizeof("NNNN"), "NNNN" };
u64 fields[4];
struct acpi_buffer fif = { sizeof(fields), fields };
@@ -269,9 +268,9 @@ static int acpi_fan_speed_cmp(const void *a, const void *b)
return fps1->speed - fps2->speed;
}
-static int acpi_fan_get_fps(struct device *dev, struct acpi_device *device)
+static int acpi_fan_get_fps(struct acpi_fan *fan, struct device *dev,
+ struct acpi_device *device)
{
- struct acpi_fan *fan = acpi_driver_data(device);
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
acpi_status status;
int i;
@@ -310,7 +309,7 @@ static int acpi_fan_get_fps(struct device *dev, struct acpi_device *device)
return 0;
}
-static int acpi_fan_dsm_init(struct device *dev)
+static int acpi_fan_dsm_init(struct acpi_fan *fan, struct device *dev)
{
union acpi_object dummy = {
.package = {
@@ -319,7 +318,6 @@ static int acpi_fan_dsm_init(struct device *dev)
.elements = NULL,
},
};
- struct acpi_fan *fan = dev_get_drvdata(dev);
acpi_handle fan_handle = fan->adev->handle;
if (!acpi_check_dsm(fan_handle, &acpi_fan_microsoft_guid, 0,
@@ -344,7 +342,7 @@ static int acpi_fan_dsm_init(struct device *dev)
return 0;
}
-static int acpi_fan_dsm_set_trip_points(struct device *dev, u64 upper, u64 lower)
+static int acpi_fan_dsm_set_trip_points(struct acpi_fan *fan, u64 upper, u64 lower)
{
union acpi_object args[2] = {
{
@@ -360,7 +358,6 @@ static int acpi_fan_dsm_set_trip_points(struct device *dev, u64 upper, u64 lower
},
},
};
- struct acpi_fan *fan = dev_get_drvdata(dev);
union acpi_object in = {
.package = {
.type = ACPI_TYPE_PACKAGE,
@@ -377,9 +374,8 @@ static int acpi_fan_dsm_set_trip_points(struct device *dev, u64 upper, u64 lower
return 0;
}
-static int acpi_fan_dsm_start(struct device *dev)
+static int acpi_fan_dsm_start(struct acpi_fan *fan)
{
- struct acpi_fan *fan = dev_get_drvdata(dev);
int ret;
if (!fan->fan_trip_granularity)
@@ -401,11 +397,11 @@ static int acpi_fan_dsm_start(struct device *dev)
* overlap, meaning that the current fan speed needs to be outside at
* least one range.
*/
- ret = acpi_fan_dsm_set_trip_points(dev, fan->fan_trip_granularity, 0);
+ ret = acpi_fan_dsm_set_trip_points(fan, fan->fan_trip_granularity, 0);
if (ret < 0)
return ret;
- return acpi_fan_dsm_set_trip_points(dev, fan->fan_trip_granularity * 3,
+ return acpi_fan_dsm_set_trip_points(fan, fan->fan_trip_granularity * 3,
fan->fan_trip_granularity * 2);
}
@@ -431,7 +427,7 @@ static int acpi_fan_dsm_update_trips_points(struct device *dev, struct acpi_fan_
lower = rounddown((u32)fst->speed - min_trip_distance, fan->fan_trip_granularity);
}
- return acpi_fan_dsm_set_trip_points(dev, upper, lower);
+ return acpi_fan_dsm_set_trip_points(fan, upper, lower);
}
static void acpi_fan_notify_handler(acpi_handle handle, u32 event, void *context)
@@ -493,17 +489,17 @@ static int acpi_fan_probe(struct platform_device *pdev)
}
if (fan->acpi4) {
- result = acpi_fan_get_fif(device);
+ result = acpi_fan_get_fif(fan, device);
if (result)
return result;
- result = acpi_fan_get_fps(&pdev->dev, device);
+ result = acpi_fan_get_fps(fan, &pdev->dev, device);
if (result)
return result;
}
if (fan->has_fst) {
- result = acpi_fan_dsm_init(&pdev->dev);
+ result = acpi_fan_dsm_init(fan, &pdev->dev);
if (result)
return result;
@@ -518,13 +514,13 @@ static int acpi_fan_probe(struct platform_device *pdev)
if (result)
return result;
- result = acpi_fan_dsm_start(&pdev->dev);
+ result = acpi_fan_dsm_start(fan);
if (result) {
dev_err(&pdev->dev, "Failed to start Microsoft fan extensions\n");
return result;
}
- result = acpi_fan_create_attributes(device);
+ result = acpi_fan_create_attributes(fan);
if (result)
return result;
}
@@ -556,7 +552,7 @@ static int acpi_fan_probe(struct platform_device *pdev)
err_end:
if (fan->has_fst)
- acpi_fan_delete_attributes(device);
+ acpi_fan_delete_attributes(fan);
return result;
}
@@ -565,11 +561,9 @@ static void acpi_fan_remove(struct platform_device *pdev)
{
struct acpi_fan *fan = platform_get_drvdata(pdev);
- if (fan->has_fst) {
- struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+ if (fan->has_fst)
+ acpi_fan_delete_attributes(fan);
- acpi_fan_delete_attributes(device);
- }
thermal_cooling_device_unregister(fan->cdev);
}
@@ -591,7 +585,7 @@ static int acpi_fan_resume(struct device *dev)
int result;
if (fan->has_fst) {
- result = acpi_fan_dsm_start(dev);
+ result = acpi_fan_dsm_start(fan);
if (result)
dev_err(dev, "Failed to start Microsoft fan extensions: %d\n", result);
}
--
2.51.0
next prev parent reply other threads:[~2026-11-25 14:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 14:01 [PATCH v2 0/5] ACPI: fan: Assorted cleanups Rafael J. Wysocki
2026-11-25 14:07 ` Rafael J. Wysocki [this message]
2026-11-25 14:07 ` [PATCH v2 2/5] ACPI: fan: Stop using driver_data pointer from struct acpi_device Rafael J. Wysocki
2026-11-25 14:08 ` [PATCH v2 3/5] ACPI: fan: Adjust driver removal code ordering Rafael J. Wysocki
2026-11-25 14:09 ` [PATCH v2 4/5] ACPI: fan: Add local variable dev to acpi_fan_probe() Rafael J. Wysocki
2026-11-25 14:10 ` [PATCH v2 5/5] ACPI: fan: Use acpi_handle_debug/err() for diagnostic messages Rafael J. Wysocki
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=1976174.tdWV9SEqCh@rafael.j.wysocki \
--to=rafael@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=w_armin@gmx.de \
/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