Skip to content

Commit f0336cc

Browse files
andy-shevlag-linaro
authored andcommitted
mfd: kempld: Simplify device registration
Use platform_device_register_full() instead of open coding this function. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20240223195113.880121-4-andriy.shevchenko@linux.intel.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent b503627 commit f0336cc

1 file changed

Lines changed: 14 additions & 21 deletions

File tree

drivers/mfd/kempld-core.c

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Author: Michael Brunner <michael.brunner@kontron.com>
77
*/
88

9+
#include <linux/err.h>
910
#include <linux/platform_device.h>
1011
#include <linux/mfd/core.h>
1112
#include <linux/mfd/kempld.h>
@@ -131,28 +132,20 @@ static struct platform_device *kempld_pdev;
131132
static int kempld_create_platform_device(const struct dmi_system_id *id)
132133
{
133134
const struct kempld_platform_data *pdata = id->driver_data;
134-
int ret;
135-
136-
kempld_pdev = platform_device_alloc("kempld", -1);
137-
if (!kempld_pdev)
138-
return -ENOMEM;
139-
140-
ret = platform_device_add_data(kempld_pdev, pdata, sizeof(*pdata));
141-
if (ret)
142-
goto err;
143-
144-
ret = platform_device_add_resources(kempld_pdev, pdata->ioresource, 1);
145-
if (ret)
146-
goto err;
147-
148-
ret = platform_device_add(kempld_pdev);
149-
if (ret)
150-
goto err;
135+
const struct platform_device_info pdevinfo = {
136+
.name = "kempld",
137+
.id = PLATFORM_DEVID_NONE,
138+
.res = pdata->ioresource,
139+
.num_res = 1,
140+
.data = pdata,
141+
.size_data = sizeof(*pdata),
142+
};
143+
144+
kempld_pdev = platform_device_register_full(&pdevinfo);
145+
if (IS_ERR(kempld_pdev))
146+
return PTR_ERR(kempld_pdev);
151147

152148
return 0;
153-
err:
154-
platform_device_put(kempld_pdev);
155-
return ret;
156149
}
157150

158151
/**
@@ -424,7 +417,7 @@ static int kempld_probe(struct platform_device *pdev)
424417
struct resource *ioport;
425418
int ret;
426419

427-
if (kempld_pdev == NULL) {
420+
if (IS_ERR_OR_NULL(kempld_pdev)) {
428421
/*
429422
* No kempld_pdev device has been registered in kempld_init,
430423
* so we seem to be probing an ACPI platform device.

0 commit comments

Comments
 (0)