diff mbox series

[3/4] hwmon: (smsc47m1) Simplify device registration

Message ID ab326fb9b1ad2191583b4cb3a8bd624dfedb908e.1701957841.git.u.kleine-koenig@pengutronix.de (mailing list archive)
State Accepted
Headers show
Series hwmon: (smsc47m1) Various improvements | expand

Commit Message

Uwe Kleine-König Dec. 7, 2023, 2:09 p.m. UTC
Use platform_device_register_full() instead of open coding this
function.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/hwmon/smsc47m1.c | 44 +++++++++++++---------------------------
 1 file changed, 14 insertions(+), 30 deletions(-)

Comments

Guenter Roeck Dec. 11, 2023, 2:39 p.m. UTC | #1
On Thu, Dec 07, 2023 at 03:09:31PM +0100, Uwe Kleine-König wrote:
> Use platform_device_register_full() instead of open coding this
> function.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Applied. Removed double empty line while doing so.

Guenter
Uwe Kleine-König Dec. 11, 2023, 4:50 p.m. UTC | #2
Hello Guenter,

On Mon, Dec 11, 2023 at 06:39:02AM -0800, Guenter Roeck wrote:
> On Thu, Dec 07, 2023 at 03:09:31PM +0100, Uwe Kleine-König wrote:
> > Use platform_device_register_full() instead of open coding this
> > function.
> > 
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> 
> Applied. Removed double empty line while doing so.

Oh indeed. Thanks

Uwe
diff mbox series

Patch

diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index bda39a5a5d4c..7e9c183b8e7f 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -864,50 +864,34 @@  static struct platform_driver smsc47m1_driver __refdata = {
 static int __init smsc47m1_device_add(unsigned short address,
 				      const struct smsc47m1_sio_data *sio_data)
 {
-	struct resource res = {
+	const struct resource res = {
 		.start	= address,
 		.end	= address + SMSC_EXTENT - 1,
 		.name	= DRVNAME,
 		.flags	= IORESOURCE_IO,
 	};
+	const struct platform_device_info pdevinfo = {
+		.name = DRVNAME,
+		.id = address,
+		.res = &res,
+		.num_res = 1,
+		.data = sio_data,
+		.size_data = sizeof(struct smsc47m1_sio_data),
+	};
 	int err;
 
 	err = smsc47m1_handle_resources(address, sio_data->type, CHECK, NULL);
 	if (err)
-		goto exit;
+		return err;
 
-	pdev = platform_device_alloc(DRVNAME, address);
-	if (!pdev) {
-		err = -ENOMEM;
+
+	pdev = platform_device_register_full(&pdevinfo);
+	if (IS_ERR(pdev)) {
 		pr_err("Device allocation failed\n");
-		goto exit;
-	}
-
-	err = platform_device_add_resources(pdev, &res, 1);
-	if (err) {
-		pr_err("Device resource addition failed (%d)\n", err);
-		goto exit_device_put;
-	}
-
-	err = platform_device_add_data(pdev, sio_data,
-				       sizeof(struct smsc47m1_sio_data));
-	if (err) {
-		pr_err("Platform data allocation failed\n");
-		goto exit_device_put;
-	}
-
-	err = platform_device_add(pdev);
-	if (err) {
-		pr_err("Device addition failed (%d)\n", err);
-		goto exit_device_put;
+		return PTR_ERR(pdev);
 	}
 
 	return 0;
-
-exit_device_put:
-	platform_device_put(pdev);
-exit:
-	return err;
 }
 
 static int __init sm_smsc47m1_init(void)