From 1c1d152cc5ac3a67d199728a9ba0b4f54a498f8b Mon Sep 17 00:00:00 2001 From: Logan Gunthorpe Date: Fri, 17 Mar 2017 12:48:14 -0600 Subject: [PATCH] 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 Signed-off-by: Greg Kroah-Hartman --- drivers/platform/chrome/cros_ec_dev.c | 31 ++++++--------------------- 1 file 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) @@ -406,24 +405,12 @@ static int ec_device_probe(struct platform_device *pdev) device_initialize(&ec->class_dev); 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; }