Skip to content

Commit 5810769

Browse files
Uwe Kleine-Königgroeck
authored andcommitted
hwmon: (smsc47m1) Simplify device registration
Use platform_device_register_full() instead of open coding this function. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.kernel.org/r/ab326fb9b1ad2191583b4cb3a8bd624dfedb908e.1701957841.git.u.kleine-koenig@pengutronix.de [groeck: Removed double empty line] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 5c2833c commit 5810769

1 file changed

Lines changed: 13 additions & 30 deletions

File tree

drivers/hwmon/smsc47m1.c

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -864,50 +864,33 @@ static struct platform_driver smsc47m1_driver __refdata = {
864864
static int __init smsc47m1_device_add(unsigned short address,
865865
const struct smsc47m1_sio_data *sio_data)
866866
{
867-
struct resource res = {
867+
const struct resource res = {
868868
.start = address,
869869
.end = address + SMSC_EXTENT - 1,
870870
.name = DRVNAME,
871871
.flags = IORESOURCE_IO,
872872
};
873+
const struct platform_device_info pdevinfo = {
874+
.name = DRVNAME,
875+
.id = address,
876+
.res = &res,
877+
.num_res = 1,
878+
.data = sio_data,
879+
.size_data = sizeof(struct smsc47m1_sio_data),
880+
};
873881
int err;
874882

875883
err = smsc47m1_handle_resources(address, sio_data->type, CHECK, NULL);
876884
if (err)
877-
goto exit;
885+
return err;
878886

879-
pdev = platform_device_alloc(DRVNAME, address);
880-
if (!pdev) {
881-
err = -ENOMEM;
887+
pdev = platform_device_register_full(&pdevinfo);
888+
if (IS_ERR(pdev)) {
882889
pr_err("Device allocation failed\n");
883-
goto exit;
884-
}
885-
886-
err = platform_device_add_resources(pdev, &res, 1);
887-
if (err) {
888-
pr_err("Device resource addition failed (%d)\n", err);
889-
goto exit_device_put;
890-
}
891-
892-
err = platform_device_add_data(pdev, sio_data,
893-
sizeof(struct smsc47m1_sio_data));
894-
if (err) {
895-
pr_err("Platform data allocation failed\n");
896-
goto exit_device_put;
897-
}
898-
899-
err = platform_device_add(pdev);
900-
if (err) {
901-
pr_err("Device addition failed (%d)\n", err);
902-
goto exit_device_put;
890+
return PTR_ERR(pdev);
903891
}
904892

905893
return 0;
906-
907-
exit_device_put:
908-
platform_device_put(pdev);
909-
exit:
910-
return err;
911894
}
912895

913896
static int __init sm_smsc47m1_init(void)

0 commit comments

Comments
 (0)