aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLogan Gunthorpe <logang@deltatee.com>2017-03-17 12:48:14 -0600
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-03-21 06:44:33 +0100
commit1c1d152cc5ac3a67d199728a9ba0b4f54a498f8b (patch)
tree6b449f67aaa42fef6e01ecd78cc64ce1ec4ba660
parenttpm-chip: utilize new cdev_device_add helper function (diff)
downloadlinux-dev-1c1d152cc5ac3a67d199728a9ba0b4f54a498f8b.tar.xz
linux-dev-1c1d152cc5ac3a67d199728a9ba0b4f54a498f8b.zip
platform/chrome: cros_ec_dev - 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. At the same time we cleanup the error path through device_probe function: we use put_device instead of kfree directly as recommended by the device_initialize documentation. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/platform/chrome/cros_ec_dev.c31
1 files changed, 7 insertions, 24 deletions
diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c
index 6f09da4dadb8..6aa120cd0574 100644
--- a/drivers/platform/chrome/cros_ec_dev.c
+++ b/drivers/platform/chrome/cros_ec_dev.c
@@ -391,7 +391,6 @@ static int ec_device_probe(struct platform_device *pdev)
int retval = -ENOMEM;
struct device *dev = &pdev->dev;
struct cros_ec_platform *ec_platform = dev_get_platdata(dev);
- dev_t devno = MKDEV(ec_major, pdev->id);
struct cros_ec_dev *ec = kzalloc(sizeof(*ec), GFP_KERNEL);
if (!ec)
@@ -407,23 +406,11 @@ static int ec_device_probe(struct platform_device *pdev)
cdev_init(&ec->cdev, &fops);
/*
- * Add the character device
- * Link cdev to the class device to be sure device is not used
- * before unbinding it.
- */
- ec->cdev.kobj.parent = &ec->class_dev.kobj;
- retval = cdev_add(&ec->cdev, devno, 1);
- if (retval) {
- dev_err(dev, ": failed to add character device\n");
- goto cdev_add_failed;
- }
-
- /*
* Add the class device
* Link to the character device for creating the /dev entry
* in devtmpfs.
*/
- ec->class_dev.devt = ec->cdev.dev;
+ ec->class_dev.devt = MKDEV(ec_major, pdev->id);
ec->class_dev.class = &cros_class;
ec->class_dev.parent = dev;
ec->class_dev.release = __remove;
@@ -431,13 +418,13 @@ static int ec_device_probe(struct platform_device *pdev)
retval = dev_set_name(&ec->class_dev, "%s", ec_platform->ec_name);
if (retval) {
dev_err(dev, "dev_set_name failed => %d\n", retval);
- goto set_named_failed;
+ goto failed;
}
- retval = device_add(&ec->class_dev);
+ retval = cdev_device_add(&ec->cdev, &ec->class_dev);
if (retval) {
- dev_err(dev, "device_register failed => %d\n", retval);
- goto dev_reg_failed;
+ dev_err(dev, "cdev_device_add failed => %d\n", retval);
+ goto failed;
}
/* check whether this EC is a sensor hub. */
@@ -446,12 +433,8 @@ static int ec_device_probe(struct platform_device *pdev)
return 0;
-dev_reg_failed:
-set_named_failed:
- dev_set_drvdata(dev, NULL);
- cdev_del(&ec->cdev);
-cdev_add_failed:
- kfree(ec);
+failed:
+ put_device(&ec->class_dev);
return retval;
}