Skip to contentSkip to conversation

hwmon: (sch5627) Use devres function

PATCH In review [email protected] 3 participants 5 messages Apr 17, 2021 – Apr 19, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover hwmon: (sch5627) Use devres function

From: Armin Wolf <[email protected]>

Use devm_hwmon_device_register_with_info() to simplify the source code and remove an unnecessary error path in sch5627_probe as it performs nothing useful when using the devres function.

Tested on a Fujitsu Esprimo P720.

Armin Wolf (2):
hwmon: (sch5627) Use devres function
hwmon: (sch5627) Remove unnecessary error path

 drivers/hwmon/sch5627.c | 81 ++++++++++++++---------------------------
 1 file changed, 28 insertions(+), 53 deletions(-)

--
2.20.1

#1 lore raw

PATCH 1/2 hwmon: (sch5627) Use devres function

From: Armin Wolf <[email protected]>

Use devm_hwmon_device_register_with_info() and remove hwmon_dev from sch5627_data struct as it is not needed anymore.

---
 drivers/hwmon/sch5627.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/hwmon/sch5627.c +5 -10
index 8be339ae5f7d..ea042a6dae58 100644
@@ -64,7 +64,6 @@ static const char * const SCH5627_IN_LABELS[SCH5627_NO_IN] = {
 
 struct sch5627_data {
 	unsigned short addr;
-	struct device *hwmon_dev;
 	struct sch56xx_watchdog_data *watchdog;
 	u8 control;
 	u8 temp_max[SCH5627_NO_TEMPS];
@@ -365,15 +364,13 @@ static int sch5627_remove(struct platform_device *pdev)
 	if (data->watchdog)
 		sch56xx_watchdog_unregister(data->watchdog);
 
-	if (data->hwmon_dev)
-		hwmon_device_unregister(data->hwmon_dev);
-
 	return 0;
 }
 
 static int sch5627_probe(struct platform_device *pdev)
 {
 	struct sch5627_data *data;
+	struct device *hwmon_dev;
 	int err, build_code, build_id, hwmon_rev, val;
 
 	data = devm_kzalloc(&pdev->dev, sizeof(struct sch5627_data),
@@ -471,12 +468,10 @@ static int sch5627_probe(struct platform_device *pdev)
 	pr_info("firmware build: code 0x%02X, id 0x%04X, hwmon: rev 0x%02X\n",
 		build_code, build_id, hwmon_rev);
 
-	data->hwmon_dev = hwmon_device_register_with_info(&pdev->dev, DEVNAME, data,
-							  &sch5627_chip_info,
-							  NULL);
-	if (IS_ERR(data->hwmon_dev)) {
-		err = PTR_ERR(data->hwmon_dev);
-		data->hwmon_dev = NULL;
+	hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev, DEVNAME, data,
+							 &sch5627_chip_info, NULL);
+	if (IS_ERR(hwmon_dev)) {
+		err = PTR_ERR(hwmon_dev);
 		goto error;
 	}
 

--
2.20.1

#2 lore raw

PATCH 2/2 hwmon: (sch5627) Remove unnecessary error path

In reply to [email protected]

From: Armin Wolf <[email protected]>

Calling remove() on error whould have only unregistered the watchdog, and since a failure in registering him is considered non-fatal and happens last, remove the error path and return the error codes directly.

---
 drivers/hwmon/sch5627.c | 70 +++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 45 deletions(-)
drivers/hwmon/sch5627.c +25 -45
index ea042a6dae58..4324a5dbc968 100644
@@ -383,72 +383,58 @@ static int sch5627_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, data);
 
 	val = sch56xx_read_virtual_reg(data->addr, SCH5627_REG_HWMON_ID);
-	if (val < 0) {
-		err = val;
-		goto error;
-	}
+	if (val < 0)
+		return val;
+
 	if (val != SCH5627_HWMON_ID) {
 		pr_err("invalid %s id: 0x%02X (expected 0x%02X)\n", "hwmon",
 		       val, SCH5627_HWMON_ID);
-		err = -ENODEV;
-		goto error;
+		return -ENODEV;
 	}
 
 	val = sch56xx_read_virtual_reg(data->addr, SCH5627_REG_COMPANY_ID);
-	if (val < 0) {
-		err = val;
-		goto error;
-	}
+	if (val < 0)
+		return val;
+
 	if (val != SCH5627_COMPANY_ID) {
 		pr_err("invalid %s id: 0x%02X (expected 0x%02X)\n", "company",
 		       val, SCH5627_COMPANY_ID);
-		err = -ENODEV;
-		goto error;
+		return -ENODEV;
 	}
 
 	val = sch56xx_read_virtual_reg(data->addr, SCH5627_REG_PRIMARY_ID);
-	if (val < 0) {
-		err = val;
-		goto error;
-	}
+	if (val < 0)
+		return val;
+
 	if (val != SCH5627_PRIMARY_ID) {
 		pr_err("invalid %s id: 0x%02X (expected 0x%02X)\n", "primary",
 		       val, SCH5627_PRIMARY_ID);
-		err = -ENODEV;
-		goto error;
+		return -ENODEV;
 	}
 
 	build_code = sch56xx_read_virtual_reg(data->addr,
 					      SCH5627_REG_BUILD_CODE);
-	if (build_code < 0) {
-		err = build_code;
-		goto error;
-	}
+	if (build_code < 0)
+		return build_code;
 
 	build_id = sch56xx_read_virtual_reg16(data->addr,
 					      SCH5627_REG_BUILD_ID);
-	if (build_id < 0) {
-		err = build_id;
-		goto error;
-	}
+	if (build_id < 0)
+		return build_id;
 
 	hwmon_rev = sch56xx_read_virtual_reg(data->addr,
 					     SCH5627_REG_HWMON_REV);
-	if (hwmon_rev < 0) {
-		err = hwmon_rev;
-		goto error;
-	}
+	if (hwmon_rev < 0)
+		return hwmon_rev;
 
 	val = sch56xx_read_virtual_reg(data->addr, SCH5627_REG_CTRL);
-	if (val < 0) {
-		err = val;
-		goto error;
-	}
+	if (val < 0)
+		return val;
+
 	data->control = val;
 	if (!(data->control & 0x01)) {
 		pr_err("hardware monitoring not enabled\n");
-		err = -ENODEV;
-		goto error;
+		return -ENODEV;
 	}
 	/* Trigger a Vbat voltage measurement, so that we get a valid reading
 	   the first time we read Vbat */
@@ -462,7 +448,7 @@ static int sch5627_probe(struct platform_device *pdev)
 	 */
 	err = sch5627_read_limits(data);
 	if (err)
-		goto error;
+		return err;
 
 	pr_info("found %s chip at %#hx\n", DEVNAME, data->addr);
 	pr_info("firmware build: code 0x%02X, id 0x%04X, hwmon: rev 0x%02X\n",
@@ -470,10 +456,8 @@ static int sch5627_probe(struct platform_device *pdev)
 
 	hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev, DEVNAME, data,
 							 &sch5627_chip_info, NULL);
-	if (IS_ERR(hwmon_dev)) {
-		err = PTR_ERR(hwmon_dev);
-		goto error;
-	}
+	if (IS_ERR(hwmon_dev))
+		return PTR_ERR(hwmon_dev);
 
 	/* Note failing to register the watchdog is not a fatal error */
 	data->watchdog = sch56xx_watchdog_register(&pdev->dev, data->addr,
@@ -481,10 +465,6 @@ static int sch5627_probe(struct platform_device *pdev)
 			&data->update_lock, 1);
 
 	return 0;
-
-error:
-	sch5627_remove(pdev);
-	return err;
 }
 
 static struct platform_driver sch5627_driver = {

--
2.20.1

Reviewed-by on the v1 series
#3 lore raw
In reply to [email protected]

Hi,

Quoted 7 lines · On 4/17/21 11:09 PM, [email protected] wrote:

From: Armin Wolf <[email protected]>

Use devm_hwmon_device_register_with_info() to simplify the source code and remove an unnecessary error path in sch5627_probe as it performs nothing useful when using the devres function.

Quoted 5 lines

Tested on a Fujitsu Esprimo P720.

Armin Wolf (2):
hwmon: (sch5627) Use devres function
hwmon: (sch5627) Remove unnecessary error path

Thanks, both patches looks good to me:

For the series.

Regards,

Hans

maintainer
#4 lore raw
In reply to [email protected]
Quoted 13 lines · On 4/17/21 2:09 PM, [email protected] wrote:

From: Armin Wolf <[email protected]>

Use devm_hwmon_device_register_with_info() to simplify the source code and remove an unnecessary error path in sch5627_probe as it performs nothing useful when using the devres function.

Tested on a Fujitsu Esprimo P720.

Armin Wolf (2):
hwmon: (sch5627) Use devres function
hwmon: (sch5627) Remove unnecessary error path

Quoted 6 lines
 drivers/hwmon/sch5627.c | 81 ++++++++++++++---------------------------
 1 file changed, 28 insertions(+), 53 deletions(-)

--
2.20.1

Both applied, though it would be even better if you'd do the same with the watchdog device.

Guenter