* [PATCH 0/3] hwmon: (w83627ehf) Cleanups
@ 2021-07-09 18:44 W_Armin
2021-07-09 18:44 ` [PATCH 1/3] hwmon: (w83627ehf) Use platform_create_bundle W_Armin
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: W_Armin @ 2021-07-09 18:44 UTC (permalink / raw)
To: linux; +Cc: jdelvare, linux-hwmon
From: Armin Wolf <W_Armin@gmx.de>
This patch series is cleaning up the pm, init and exits
paths of the w83627ehf driver.
This mainly makes the code more readable.
Armin Wolf (3):
hwmon: (w83627ehf) Use platform_create_bundle
hwmon: (w83627ehf) Remove w83627ehf_remove()
hwmon: (w83627ehf) Switch to SIMPLE_DEV_PM_OPS
drivers/hwmon/w83627ehf.c | 118 +++++++-------------------------------
1 file changed, 21 insertions(+), 97 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] hwmon: (w83627ehf) Use platform_create_bundle
2021-07-09 18:44 [PATCH 0/3] hwmon: (w83627ehf) Cleanups W_Armin
@ 2021-07-09 18:44 ` W_Armin
2021-07-09 18:45 ` [PATCH 2/3] hwmon: (w83627ehf) Remove w83627ehf_remove() W_Armin
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: W_Armin @ 2021-07-09 18:44 UTC (permalink / raw)
To: linux; +Cc: jdelvare, linux-hwmon
From: Armin Wolf <W_Armin@gmx.de>
Using platform_create_bundle() simplifies the module
init code and allows w83627ehf_probe() to be marked
as __init, lowering the runtime memory footprint.
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
drivers/hwmon/w83627ehf.c | 57 +++++++--------------------------------
1 file changed, 10 insertions(+), 47 deletions(-)
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 8618aaf32350..16aed90ca2ec 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -1694,7 +1694,7 @@ static const struct hwmon_chip_info w83627ehf_chip_info = {
.info = w83627ehf_info,
};
-static int w83627ehf_probe(struct platform_device *pdev)
+static int __init w83627ehf_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
@@ -2057,7 +2057,6 @@ static struct platform_driver w83627ehf_driver = {
.name = DRVNAME,
.pm = W83627EHF_DEV_PM_OPS,
},
- .probe = w83627ehf_probe,
.remove = w83627ehf_remove,
};
@@ -2150,8 +2149,7 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
/*
* when Super-I/O functions move to a separate file, the Super-I/O
* bus will manage the lifetime of the device and this module will only keep
- * track of the w83627ehf driver. But since we platform_device_alloc(), we
- * must keep track of the device
+ * track of the w83627ehf driver.
*/
static struct platform_device *pdev;
@@ -2159,7 +2157,10 @@ static int __init sensors_w83627ehf_init(void)
{
int err;
unsigned short address;
- struct resource res;
+ struct resource res = {
+ .name = DRVNAME,
+ .flags = IORESOURCE_IO,
+ };
struct w83627ehf_sio_data sio_data;
/*
@@ -2173,55 +2174,17 @@ static int __init sensors_w83627ehf_init(void)
w83627ehf_find(0x4e, &address, &sio_data))
return -ENODEV;
- err = platform_driver_register(&w83627ehf_driver);
- if (err)
- goto exit;
-
- pdev = platform_device_alloc(DRVNAME, address);
- if (!pdev) {
- err = -ENOMEM;
- pr_err("Device allocation failed\n");
- goto exit_unregister;
- }
-
- err = platform_device_add_data(pdev, &sio_data,
- sizeof(struct w83627ehf_sio_data));
- if (err) {
- pr_err("Platform data allocation failed\n");
- goto exit_device_put;
- }
-
- memset(&res, 0, sizeof(res));
- res.name = DRVNAME;
res.start = address + IOREGION_OFFSET;
res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1;
- res.flags = IORESOURCE_IO;
err = acpi_check_resource_conflict(&res);
if (err)
- goto exit_device_put;
+ return err;
- err = platform_device_add_resources(pdev, &res, 1);
- if (err) {
- pr_err("Device resource addition failed (%d)\n", err);
- goto exit_device_put;
- }
+ pdev = platform_create_bundle(&w83627ehf_driver, w83627ehf_probe, &res, 1, &sio_data,
+ sizeof(struct w83627ehf_sio_data));
- /* platform_device_add calls probe() */
- err = platform_device_add(pdev);
- if (err) {
- pr_err("Device addition failed (%d)\n", err);
- goto exit_device_put;
- }
-
- return 0;
-
-exit_device_put:
- platform_device_put(pdev);
-exit_unregister:
- platform_driver_unregister(&w83627ehf_driver);
-exit:
- return err;
+ return PTR_ERR_OR_ZERO(pdev);
}
static void __exit sensors_w83627ehf_exit(void)
--
2.20.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] hwmon: (w83627ehf) Remove w83627ehf_remove()
2021-07-09 18:44 [PATCH 0/3] hwmon: (w83627ehf) Cleanups W_Armin
2021-07-09 18:44 ` [PATCH 1/3] hwmon: (w83627ehf) Use platform_create_bundle W_Armin
@ 2021-07-09 18:45 ` W_Armin
2021-07-09 18:45 ` [PATCH 3/3] hwmon: (w83627ehf) Switch to SIMPLE_DEV_PM_OPS W_Armin
2021-07-09 20:57 ` [PATCH 0/3] hwmon: (w83627ehf) Cleanups Guenter Roeck
3 siblings, 0 replies; 7+ messages in thread
From: W_Armin @ 2021-07-09 18:45 UTC (permalink / raw)
To: linux; +Cc: jdelvare, linux-hwmon
From: Armin Wolf <W_Armin@gmx.de>
Using devm_request_region() allows us to omit
w83627ehf_remove() and also simplifies error
handling during probe.
Also fixed a checkpatch issue.
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
drivers/hwmon/w83627ehf.c | 42 +++++++--------------------------------
1 file changed, 7 insertions(+), 35 deletions(-)
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 16aed90ca2ec..19af84574324 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -1705,20 +1705,12 @@ static int __init w83627ehf_probe(struct platform_device *pdev)
struct device *hwmon_dev;
res = platform_get_resource(pdev, IORESOURCE_IO, 0);
- if (!request_region(res->start, IOREGION_LENGTH, DRVNAME)) {
- err = -EBUSY;
- dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
- (unsigned long)res->start,
- (unsigned long)res->start + IOREGION_LENGTH - 1);
- goto exit;
- }
+ if (!devm_request_region(dev, res->start, IOREGION_LENGTH, DRVNAME))
+ return -EBUSY;
- data = devm_kzalloc(&pdev->dev, sizeof(struct w83627ehf_data),
- GFP_KERNEL);
- if (!data) {
- err = -ENOMEM;
- goto exit_release;
- }
+ data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
data->addr = res->start;
mutex_init(&data->lock);
@@ -1882,7 +1874,7 @@ static int __init w83627ehf_probe(struct platform_device *pdev)
err = superio_enter(sio_data->sioreg);
if (err)
- goto exit_release;
+ return err;
/* Read VID value */
if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
@@ -1951,26 +1943,7 @@ static int __init w83627ehf_probe(struct platform_device *pdev)
data,
&w83627ehf_chip_info,
w83627ehf_groups);
- if (IS_ERR(hwmon_dev)) {
- err = PTR_ERR(hwmon_dev);
- goto exit_release;
- }
-
- return 0;
-
-exit_release:
- release_region(res->start, IOREGION_LENGTH);
-exit:
- return err;
-}
-
-static int w83627ehf_remove(struct platform_device *pdev)
-{
- struct w83627ehf_data *data = platform_get_drvdata(pdev);
-
- release_region(data->addr, IOREGION_LENGTH);
-
- return 0;
+ return PTR_ERR_OR_ZERO(hwmon_dev);
}
#ifdef CONFIG_PM
@@ -2057,7 +2030,6 @@ static struct platform_driver w83627ehf_driver = {
.name = DRVNAME,
.pm = W83627EHF_DEV_PM_OPS,
},
- .remove = w83627ehf_remove,
};
/* w83627ehf_find() looks for a '627 in the Super-I/O config space */
--
2.20.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] hwmon: (w83627ehf) Switch to SIMPLE_DEV_PM_OPS
2021-07-09 18:44 [PATCH 0/3] hwmon: (w83627ehf) Cleanups W_Armin
2021-07-09 18:44 ` [PATCH 1/3] hwmon: (w83627ehf) Use platform_create_bundle W_Armin
2021-07-09 18:45 ` [PATCH 2/3] hwmon: (w83627ehf) Remove w83627ehf_remove() W_Armin
@ 2021-07-09 18:45 ` W_Armin
2021-07-12 2:38 ` Guenter Roeck
2021-07-09 20:57 ` [PATCH 0/3] hwmon: (w83627ehf) Cleanups Guenter Roeck
3 siblings, 1 reply; 7+ messages in thread
From: W_Armin @ 2021-07-09 18:45 UTC (permalink / raw)
To: linux; +Cc: jdelvare, linux-hwmon
From: Armin Wolf <W_Armin@gmx.de>
Use SIMPLE_DEV_PM_OPS() to also assign poweroff
and thaw callbacks. Remove the now obsolete checking
of CONFIG_PM too.
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
drivers/hwmon/w83627ehf.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 19af84574324..243b9bd8d64f 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -1946,8 +1946,7 @@ static int __init w83627ehf_probe(struct platform_device *pdev)
return PTR_ERR_OR_ZERO(hwmon_dev);
}
-#ifdef CONFIG_PM
-static int w83627ehf_suspend(struct device *dev)
+static int __maybe_unused w83627ehf_suspend(struct device *dev)
{
struct w83627ehf_data *data = w83627ehf_update_device(dev);
@@ -1958,7 +1957,7 @@ static int w83627ehf_suspend(struct device *dev)
return 0;
}
-static int w83627ehf_resume(struct device *dev)
+static int __maybe_unused w83627ehf_resume(struct device *dev)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
int i;
@@ -2013,22 +2012,12 @@ static int w83627ehf_resume(struct device *dev)
return 0;
}
-static const struct dev_pm_ops w83627ehf_dev_pm_ops = {
- .suspend = w83627ehf_suspend,
- .resume = w83627ehf_resume,
- .freeze = w83627ehf_suspend,
- .restore = w83627ehf_resume,
-};
-
-#define W83627EHF_DEV_PM_OPS (&w83627ehf_dev_pm_ops)
-#else
-#define W83627EHF_DEV_PM_OPS NULL
-#endif /* CONFIG_PM */
+static SIMPLE_DEV_PM_OPS(w83627ehf_dev_pm_ops, w83627ehf_suspend, w83627ehf_resume);
static struct platform_driver w83627ehf_driver = {
.driver = {
.name = DRVNAME,
- .pm = W83627EHF_DEV_PM_OPS,
+ .pm = &w83627ehf_dev_pm_ops,
},
};
--
2.20.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] hwmon: (w83627ehf) Cleanups
2021-07-09 18:44 [PATCH 0/3] hwmon: (w83627ehf) Cleanups W_Armin
` (2 preceding siblings ...)
2021-07-09 18:45 ` [PATCH 3/3] hwmon: (w83627ehf) Switch to SIMPLE_DEV_PM_OPS W_Armin
@ 2021-07-09 20:57 ` Guenter Roeck
3 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2021-07-09 20:57 UTC (permalink / raw)
To: W_Armin; +Cc: jdelvare, linux-hwmon
On 7/9/21 11:44 AM, W_Armin@gmx.de wrote:
> From: Armin Wolf <W_Armin@gmx.de>
>
> This patch series is cleaning up the pm, init and exits
> paths of the w83627ehf driver.
> This mainly makes the code more readable.
>
>
> Armin Wolf (3):
> hwmon: (w83627ehf) Use platform_create_bundle
> hwmon: (w83627ehf) Remove w83627ehf_remove()
> hwmon: (w83627ehf) Switch to SIMPLE_DEV_PM_OPS
>
> drivers/hwmon/w83627ehf.c | 118 +++++++-------------------------------
> 1 file changed, 21 insertions(+), 97 deletions(-)
>
> --
> 2.20.1
>
Series applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] hwmon: (w83627ehf) Switch to SIMPLE_DEV_PM_OPS
2021-07-09 18:45 ` [PATCH 3/3] hwmon: (w83627ehf) Switch to SIMPLE_DEV_PM_OPS W_Armin
@ 2021-07-12 2:38 ` Guenter Roeck
2021-07-12 14:46 ` Armin Wolf
0 siblings, 1 reply; 7+ messages in thread
From: Guenter Roeck @ 2021-07-12 2:38 UTC (permalink / raw)
To: W_Armin; +Cc: jdelvare, linux-hwmon
On Fri, Jul 09, 2021 at 08:45:01PM +0200, W_Armin@gmx.de wrote:
> From: Armin Wolf <W_Armin@gmx.de>
>
> Use SIMPLE_DEV_PM_OPS() to also assign poweroff
> and thaw callbacks. Remove the now obsolete checking
> of CONFIG_PM too.
>
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
0-day says:
drivers/hwmon/w83627ehf.c:1954:6: error: 'struct w83627ehf_data' has no member named 'vbat'
.... and there was me thinking that this code was at least compile tested.
Apparently not. Sigh. I dropped this patch.
Guenter
> ---
> drivers/hwmon/w83627ehf.c | 19 ++++---------------
> 1 file changed, 4 insertions(+), 15 deletions(-)
>
> --
> 2.20.1
>
> diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
> index 19af84574324..243b9bd8d64f 100644
> --- a/drivers/hwmon/w83627ehf.c
> +++ b/drivers/hwmon/w83627ehf.c
> @@ -1946,8 +1946,7 @@ static int __init w83627ehf_probe(struct platform_device *pdev)
> return PTR_ERR_OR_ZERO(hwmon_dev);
> }
>
> -#ifdef CONFIG_PM
> -static int w83627ehf_suspend(struct device *dev)
> +static int __maybe_unused w83627ehf_suspend(struct device *dev)
> {
> struct w83627ehf_data *data = w83627ehf_update_device(dev);
>
> @@ -1958,7 +1957,7 @@ static int w83627ehf_suspend(struct device *dev)
> return 0;
> }
>
> -static int w83627ehf_resume(struct device *dev)
> +static int __maybe_unused w83627ehf_resume(struct device *dev)
> {
> struct w83627ehf_data *data = dev_get_drvdata(dev);
> int i;
> @@ -2013,22 +2012,12 @@ static int w83627ehf_resume(struct device *dev)
> return 0;
> }
>
> -static const struct dev_pm_ops w83627ehf_dev_pm_ops = {
> - .suspend = w83627ehf_suspend,
> - .resume = w83627ehf_resume,
> - .freeze = w83627ehf_suspend,
> - .restore = w83627ehf_resume,
> -};
> -
> -#define W83627EHF_DEV_PM_OPS (&w83627ehf_dev_pm_ops)
> -#else
> -#define W83627EHF_DEV_PM_OPS NULL
> -#endif /* CONFIG_PM */
> +static SIMPLE_DEV_PM_OPS(w83627ehf_dev_pm_ops, w83627ehf_suspend, w83627ehf_resume);
>
> static struct platform_driver w83627ehf_driver = {
> .driver = {
> .name = DRVNAME,
> - .pm = W83627EHF_DEV_PM_OPS,
> + .pm = &w83627ehf_dev_pm_ops,
> },
> };
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] hwmon: (w83627ehf) Switch to SIMPLE_DEV_PM_OPS
2021-07-12 2:38 ` Guenter Roeck
@ 2021-07-12 14:46 ` Armin Wolf
0 siblings, 0 replies; 7+ messages in thread
From: Armin Wolf @ 2021-07-12 14:46 UTC (permalink / raw)
Cc: linux-hwmon
Am 12.07.21 um 04:38 schrieb Guenter Roeck:
> On Fri, Jul 09, 2021 at 08:45:01PM +0200, W_Armin@gmx.de wrote:
>> From: Armin Wolf <W_Armin@gmx.de>
>>
>> Use SIMPLE_DEV_PM_OPS() to also assign poweroff
>> and thaw callbacks. Remove the now obsolete checking
>> of CONFIG_PM too.
>>
>> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> 0-day says:
>
> drivers/hwmon/w83627ehf.c:1954:6: error: 'struct w83627ehf_data' has no member named 'vbat'
>
> .... and there was me thinking that this code was at least compile tested.
> Apparently not. Sigh. I dropped this patch.
>
> Guenter
Well, i even tested the patches on real hardware (Asrock AM2NF3-VSTA), however it seems that i forgot to test them
with CONFIG_PM disabled. I already found the problem and will submit a updated patch series soon
(after more testing this time).
Sorry for not doing that sooner.
>> ---
>> drivers/hwmon/w83627ehf.c | 19 ++++---------------
>> 1 file changed, 4 insertions(+), 15 deletions(-)
>>
>> --
>> 2.20.1
>>
>> diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
>> index 19af84574324..243b9bd8d64f 100644
>> --- a/drivers/hwmon/w83627ehf.c
>> +++ b/drivers/hwmon/w83627ehf.c
>> @@ -1946,8 +1946,7 @@ static int __init w83627ehf_probe(struct platform_device *pdev)
>> return PTR_ERR_OR_ZERO(hwmon_dev);
>> }
>>
>> -#ifdef CONFIG_PM
>> -static int w83627ehf_suspend(struct device *dev)
>> +static int __maybe_unused w83627ehf_suspend(struct device *dev)
>> {
>> struct w83627ehf_data *data = w83627ehf_update_device(dev);
>>
>> @@ -1958,7 +1957,7 @@ static int w83627ehf_suspend(struct device *dev)
>> return 0;
>> }
>>
>> -static int w83627ehf_resume(struct device *dev)
>> +static int __maybe_unused w83627ehf_resume(struct device *dev)
>> {
>> struct w83627ehf_data *data = dev_get_drvdata(dev);
>> int i;
>> @@ -2013,22 +2012,12 @@ static int w83627ehf_resume(struct device *dev)
>> return 0;
>> }
>>
>> -static const struct dev_pm_ops w83627ehf_dev_pm_ops = {
>> - .suspend = w83627ehf_suspend,
>> - .resume = w83627ehf_resume,
>> - .freeze = w83627ehf_suspend,
>> - .restore = w83627ehf_resume,
>> -};
>> -
>> -#define W83627EHF_DEV_PM_OPS (&w83627ehf_dev_pm_ops)
>> -#else
>> -#define W83627EHF_DEV_PM_OPS NULL
>> -#endif /* CONFIG_PM */
>> +static SIMPLE_DEV_PM_OPS(w83627ehf_dev_pm_ops, w83627ehf_suspend, w83627ehf_resume);
>>
>> static struct platform_driver w83627ehf_driver = {
>> .driver = {
>> .name = DRVNAME,
>> - .pm = W83627EHF_DEV_PM_OPS,
>> + .pm = &w83627ehf_dev_pm_ops,
>> },
>> };
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-07-12 14:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09 18:44 [PATCH 0/3] hwmon: (w83627ehf) Cleanups W_Armin
2021-07-09 18:44 ` [PATCH 1/3] hwmon: (w83627ehf) Use platform_create_bundle W_Armin
2021-07-09 18:45 ` [PATCH 2/3] hwmon: (w83627ehf) Remove w83627ehf_remove() W_Armin
2021-07-09 18:45 ` [PATCH 3/3] hwmon: (w83627ehf) Switch to SIMPLE_DEV_PM_OPS W_Armin
2021-07-12 2:38 ` Guenter Roeck
2021-07-12 14:46 ` Armin Wolf
2021-07-09 20:57 ` [PATCH 0/3] hwmon: (w83627ehf) Cleanups Guenter Roeck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.