# \[rtc-linux\] \[PATCH v2 16/16\] switchtec: utilize new device\_add\_cdev helper function

- From: Logan Gunthorpe \<logang@deltatee.com\>
- Date: 2017-02-26 06:38:17 
- List: linux-rtc
- Page: https://ratatoskr.run/linux-rtc/2017/02/118231
- Thread: https://ratatoskr.run/linux-fsdevel/2017/02/118231/t.md

```text
Very straightforward conversion to device_add_cdev. Drop cdev_add and
device_add and use cdev_device_add.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
---
 drivers/pci/switch/switchtec.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c
index 94384e7..bd8135b 100644
--- a/drivers/pci/switch/switchtec.c
+++ b/drivers/pci/switch/switchtec.c
@@ -1182,10 +1182,10 @@ static void stdev_unregister(struct switchtec_dev *stdev)
 	pci_clear_master(stdev->pdev);
 	pci_set_drvdata(stdev->pdev, NULL);
 
-	cdev_del(&stdev->cdev);
+	cdev_device_del(&stdev->cdev, &stdev->dev);
 	ida_simple_remove(&switchtec_minor_ida,
 			  MINOR(stdev->dev.devt));
-	device_unregister(&stdev->dev);
+	put_device(&stdev->dev);
 }
 
 static struct switchtec_dev *stdev_create(struct pci_dev *pdev)
@@ -1231,24 +1231,17 @@ static struct switchtec_dev *stdev_create(struct pci_dev *pdev)
 	cdev = &stdev->cdev;
 	cdev_init(cdev, &switchtec_fops);
 	cdev->owner = THIS_MODULE;
-	cdev->kobj.parent = &dev->kobj;
 
-	rc = cdev_add(&stdev->cdev, dev->devt, 1);
+	rc = cdev_device_add(&stdev->cdev, dev);
 	if (rc)
 		goto err_cdev;
 
-	rc = device_add(dev);
-	if (rc)
-		goto err_devadd;
-
 	return stdev;
 
-err_devadd:
+err_cdev:
 	mutex_lock(&stdev->mrpc_mutex);
 	stdev->alive = false;
 	mutex_unlock(&stdev->mrpc_mutex);
-	cdev_del(&stdev->cdev);
-err_cdev:
 	ida_simple_remove(&switchtec_minor_ida, minor);
 err_put:
 	put_device(&stdev->dev);
-- 
2.1.4

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
```
