aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
authorLogan Gunthorpe <logang@deltatee.com>2017-03-17 14:48:12 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-03-21 01:44:33 -0400
commit111379dcccebc3eaf50ccf7daeb7d72210c1314c (patch)
tree2eda06c13cd80b537c8dc38fcf1170cc5f22f363 /drivers/gpio/gpiolib.c
parent358a89ca2c9680ceddc219ab25d1583619e9159f (diff)
gpiolib: utilize new cdev_device_add helper function
Replace the open coded registration of the cdev and dev with the new device_add_cdev() helper. The helper replaces a common pattern by taking the proper reference against the parent device and adding both the cdev and the device. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 8b4d721d6d63..3ce2a27ee78f 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1035,18 +1035,14 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
1035 1035
1036 cdev_init(&gdev->chrdev, &gpio_fileops); 1036 cdev_init(&gdev->chrdev, &gpio_fileops);
1037 gdev->chrdev.owner = THIS_MODULE; 1037 gdev->chrdev.owner = THIS_MODULE;
1038 gdev->chrdev.kobj.parent = &gdev->dev.kobj;
1039 gdev->dev.devt = MKDEV(MAJOR(gpio_devt), gdev->id); 1038 gdev->dev.devt = MKDEV(MAJOR(gpio_devt), gdev->id);
1040 status = cdev_add(&gdev->chrdev, gdev->dev.devt, 1); 1039
1041 if (status < 0) 1040 status = cdev_device_add(&gdev->chrdev, &gdev->dev);
1042 chip_warn(gdev->chip, "failed to add char device %d:%d\n",
1043 MAJOR(gpio_devt), gdev->id);
1044 else
1045 chip_dbg(gdev->chip, "added GPIO chardev (%d:%d)\n",
1046 MAJOR(gpio_devt), gdev->id);
1047 status = device_add(&gdev->dev);
1048 if (status) 1041 if (status)
1049 goto err_remove_chardev; 1042 return status;
1043
1044 chip_dbg(gdev->chip, "added GPIO chardev (%d:%d)\n",
1045 MAJOR(gpio_devt), gdev->id);
1050 1046
1051 status = gpiochip_sysfs_register(gdev); 1047 status = gpiochip_sysfs_register(gdev);
1052 if (status) 1048 if (status)
@@ -1061,9 +1057,7 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
1061 return 0; 1057 return 0;
1062 1058
1063err_remove_device: 1059err_remove_device:
1064 device_del(&gdev->dev); 1060 cdev_device_del(&gdev->chrdev, &gdev->dev);
1065err_remove_chardev:
1066 cdev_del(&gdev->chrdev);
1067 return status; 1061 return status;
1068} 1062}
1069 1063
@@ -1347,8 +1341,7 @@ void gpiochip_remove(struct gpio_chip *chip)
1347 * be removed, else it will be dangling until the last user is 1341 * be removed, else it will be dangling until the last user is
1348 * gone. 1342 * gone.
1349 */ 1343 */
1350 cdev_del(&gdev->chrdev); 1344 cdev_device_del(&gdev->chrdev, &gdev->dev);
1351 device_del(&gdev->dev);
1352 put_device(&gdev->dev); 1345 put_device(&gdev->dev);
1353} 1346}
1354EXPORT_SYMBOL_GPL(gpiochip_remove); 1347EXPORT_SYMBOL_GPL(gpiochip_remove);