Skip to contentSkip to conversation

hwmon: (w83627ehf) Cleanups

PATCH In review [email protected] 2 participants 7 messages Jul 9, 2021 – Jul 12, 2021 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

cover hwmon: (w83627ehf) Cleanups

From: Armin Wolf <[email protected]>

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

#1 lore raw

PATCH 1/3 hwmon: (w83627ehf) Use platform_create_bundle

From: Armin Wolf <[email protected]>

Using platform_create_bundle() simplifies the module init code and allows w83627ehf_probe() to be marked as __init, lowering the runtime memory footprint.

---
 drivers/hwmon/w83627ehf.c | 57 +++++++--------------------------------
 1 file changed, 10 insertions(+), 47 deletions(-)
drivers/hwmon/w83627ehf.c +10 -47
index 8618aaf32350..16aed90ca2ec 100644
@@ -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

#2 lore raw

PATCH 2/3 hwmon: (w83627ehf) Remove w83627ehf_remove()

In reply to [email protected]

From: Armin Wolf <[email protected]>

Using devm_request_region() allows us to omit
w83627ehf_remove() and also simplifies error
handling during probe.
Also fixed a checkpatch issue.

---
 drivers/hwmon/w83627ehf.c | 42 +++++++--------------------------------
 1 file changed, 7 insertions(+), 35 deletions(-)
drivers/hwmon/w83627ehf.c +7 -35
index 16aed90ca2ec..19af84574324 100644
@@ -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

#3 lore raw

PATCH 3/3 hwmon: (w83627ehf) Switch to SIMPLE_DEV_PM_OPS

In reply to [email protected]

From: Armin Wolf <[email protected]>

Use SIMPLE_DEV_PM_OPS() to also assign poweroff and thaw callbacks. Remove the now obsolete checking of CONFIG_PM too.

---
 drivers/hwmon/w83627ehf.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)
drivers/hwmon/w83627ehf.c +4 -15
index 19af84574324..243b9bd8d64f 100644
@@ -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

maintainer
#4 lore raw

Re: [PATCH 3/3] hwmon: (w83627ehf) Switch to SIMPLE_DEV_PM_OPS

Quoted 7 lines · On Fri, Jul 09, 2021 at 08:45:01PM +0200, [email protected] wrote:

From: Armin Wolf <[email protected]>

Use SIMPLE_DEV_PM_OPS() to also assign poweroff and thaw callbacks. Remove the now obsolete checking of CONFIG_PM too.

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

Quoted 54 lines
---
 drivers/hwmon/w83627ehf.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

--
2.20.1

drivers/hwmon/w83627ehf.c +4 -15
index 19af84574324..243b9bd8d64f 100644
@@ -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,
 	},
 };
author
#5 lore raw

Re: [PATCH 3/3] hwmon: (w83627ehf) Switch to SIMPLE_DEV_PM_OPS

Am 12.07.21 um 04:38 schrieb Guenter Roeck:

Quoted 8 lines · On Fri, Jul 09, 2021 at 08:45:01PM +0200, [email protected] wrote:
Quoted 7 lines

From: Armin Wolf <[email protected]>

Use SIMPLE_DEV_PM_OPS() to also assign poweroff and thaw callbacks. Remove the now obsolete checking of CONFIG_PM too.

Quoted 8 lines

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.

Quoted 54 lines
Quoted 54 lines
---
  drivers/hwmon/w83627ehf.c | 19 ++++---------------
  1 file changed, 4 insertions(+), 15 deletions(-)

--
2.20.1

drivers/hwmon/w83627ehf.c +4 -15
index 19af84574324..243b9bd8d64f 100644
@@ -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,
  	},
  };
maintainer
#6 lore raw
In reply to [email protected]
Quoted 12 lines · On 7/9/21 11:44 AM, [email protected] wrote:

From: Armin Wolf <[email protected]>

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

Quoted 6 lines
  drivers/hwmon/w83627ehf.c | 118 +++++++-------------------------------
  1 file changed, 21 insertions(+), 97 deletions(-)

--
2.20.1

Series applied.

Thanks,
Guenter