diff mbox series

chardev: fix error handling in cdev_device_add()

Message ID 20211012130915.3426584-1-yangyingliang@huawei.com (mailing list archive)
State New, archived
Headers show
Series chardev: fix error handling in cdev_device_add() | expand

Commit Message

Yang Yingliang Oct. 12, 2021, 1:09 p.m. UTC
If dev->devt is not set, cdev_device_add() will not add the cdev,
when device_add failed, cdev_del() is not needed, so delete cdev
only when dev->devt is set.

Reported-by: Hulk Robot <hulkci@huawei.com>
Fixes: 233ed09d7fda ("chardev: add helper function to register...")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 fs/char_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Yang Yingliang Dec. 23, 2021, 1:41 a.m. UTC | #1
ping...

On 2021/10/12 21:09, Yang Yingliang wrote:
> If dev->devt is not set, cdev_device_add() will not add the cdev,
> when device_add failed, cdev_del() is not needed, so delete cdev
> only when dev->devt is set.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Fixes: 233ed09d7fda ("chardev: add helper function to register...")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>   fs/char_dev.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/char_dev.c b/fs/char_dev.c
> index ba0ded7842a7..3f667292608c 100644
> --- a/fs/char_dev.c
> +++ b/fs/char_dev.c
> @@ -547,7 +547,7 @@ int cdev_device_add(struct cdev *cdev, struct device *dev)
>   	}
>   
>   	rc = device_add(dev);
> -	if (rc)
> +	if (rc && dev->devt)
>   		cdev_del(cdev);
>   
>   	return rc;
Greg Kroah-Hartman Dec. 23, 2021, 7:15 a.m. UTC | #2
On Thu, Dec 23, 2021 at 09:41:03AM +0800, Yang Yingliang wrote:
> ping...

ping of what?  You suddenly added a bunch of people that were not on the
original thread here with no context :(
Yang Yingliang Dec. 23, 2021, 7:43 a.m. UTC | #3
Hi,

On 2021/12/23 15:15, Greg KH wrote:
> On Thu, Dec 23, 2021 at 09:41:03AM +0800, Yang Yingliang wrote:
>> ping...
> ping of what?  You suddenly added a bunch of people that were not on the
> original thread here with no context :(
> .
This patch has been in mail list for a while time, I add the author and 
reviewer of fixed patch
to this thread,  I would like to get some advice. Should I resend the 
patch with cc those people ?

Thanks,
Yang
diff mbox series

Patch

diff --git a/fs/char_dev.c b/fs/char_dev.c
index ba0ded7842a7..3f667292608c 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -547,7 +547,7 @@  int cdev_device_add(struct cdev *cdev, struct device *dev)
 	}
 
 	rc = device_add(dev);
-	if (rc)
+	if (rc && dev->devt)
 		cdev_del(cdev);
 
 	return rc;