diff mbox series

[v2,4/4] hwmon: (sch56xx-common) Simplify sch56xx_device_add

Message ID 20210508131457.12780-5-W_Armin@gmx.de (mailing list archive)
State Accepted
Headers show
Series hwmon: (sch56xx) Use devres for watchdog and platform_device_register_simple() | expand

Commit Message

Armin Wolf May 8, 2021, 1:14 p.m. UTC
From: Armin Wolf <W_Armin@gmx.de>

Use platform_device_register_simple() instead of
manually calling platform_device_alloc()/platform_device_add().

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/hwmon/sch56xx-common.c | 27 ++++-----------------------
 1 file changed, 4 insertions(+), 23 deletions(-)

--
2.20.1

Comments

Guenter Roeck May 10, 2021, 3:36 p.m. UTC | #1
On Sat, May 08, 2021 at 03:14:57PM +0200, W_Armin@gmx.de wrote:
> From: Armin Wolf <W_Armin@gmx.de>
> 
> Use platform_device_register_simple() instead of
> manually calling platform_device_alloc()/platform_device_add().
> 
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/sch56xx-common.c | 27 ++++-----------------------
>  1 file changed, 4 insertions(+), 23 deletions(-)
> 
> --
> 2.20.1
> 
> diff --git a/drivers/hwmon/sch56xx-common.c b/drivers/hwmon/sch56xx-common.c
> index 180801f80118..5307fda73e70 100644
> --- a/drivers/hwmon/sch56xx-common.c
> +++ b/drivers/hwmon/sch56xx-common.c
> @@ -506,37 +506,18 @@ static int __init sch56xx_device_add(int address, const char *name)
>  	struct resource res = {
>  		.start	= address,
>  		.end	= address + REGION_LENGTH - 1,
> +		.name	= name,
>  		.flags	= IORESOURCE_IO,
>  	};
>  	int err;
> 
> -	sch56xx_pdev = platform_device_alloc(name, address);
> -	if (!sch56xx_pdev)
> -		return -ENOMEM;
> -
> -	res.name = sch56xx_pdev->name;
>  	err = acpi_check_resource_conflict(&res);
>  	if (err)
> -		goto exit_device_put;
> -
> -	err = platform_device_add_resources(sch56xx_pdev, &res, 1);
> -	if (err) {
> -		pr_err("Device resource addition failed\n");
> -		goto exit_device_put;
> -	}
> -
> -	err = platform_device_add(sch56xx_pdev);
> -	if (err) {
> -		pr_err("Device addition failed\n");
> -		goto exit_device_put;
> -	}
> -
> -	return 0;
> +		return err;
> 
> -exit_device_put:
> -	platform_device_put(sch56xx_pdev);
> +	sch56xx_pdev = platform_device_register_simple(name, -1, &res, 1);
> 
> -	return err;
> +	return PTR_ERR_OR_ZERO(sch56xx_pdev);
>  }
> 
>  static int __init sch56xx_init(void)
diff mbox series

Patch

diff --git a/drivers/hwmon/sch56xx-common.c b/drivers/hwmon/sch56xx-common.c
index 180801f80118..5307fda73e70 100644
--- a/drivers/hwmon/sch56xx-common.c
+++ b/drivers/hwmon/sch56xx-common.c
@@ -506,37 +506,18 @@  static int __init sch56xx_device_add(int address, const char *name)
 	struct resource res = {
 		.start	= address,
 		.end	= address + REGION_LENGTH - 1,
+		.name	= name,
 		.flags	= IORESOURCE_IO,
 	};
 	int err;

-	sch56xx_pdev = platform_device_alloc(name, address);
-	if (!sch56xx_pdev)
-		return -ENOMEM;
-
-	res.name = sch56xx_pdev->name;
 	err = acpi_check_resource_conflict(&res);
 	if (err)
-		goto exit_device_put;
-
-	err = platform_device_add_resources(sch56xx_pdev, &res, 1);
-	if (err) {
-		pr_err("Device resource addition failed\n");
-		goto exit_device_put;
-	}
-
-	err = platform_device_add(sch56xx_pdev);
-	if (err) {
-		pr_err("Device addition failed\n");
-		goto exit_device_put;
-	}
-
-	return 0;
+		return err;

-exit_device_put:
-	platform_device_put(sch56xx_pdev);
+	sch56xx_pdev = platform_device_register_simple(name, -1, &res, 1);

-	return err;
+	return PTR_ERR_OR_ZERO(sch56xx_pdev);
 }

 static int __init sch56xx_init(void)