All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Yingliang <yangyingliang@huawei.com>
To: <linux-kernel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>
Cc: <viro@zeniv.linux.org.uk>
Subject: [PATCH] chardev: fix error handling in cdev_device_add()
Date: Tue, 12 Oct 2021 21:09:15 +0800	[thread overview]
Message-ID: <20211012130915.3426584-1-yangyingliang@huawei.com> (raw)

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;
-- 
2.25.1


             reply	other threads:[~2021-10-12 13:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-12 13:09 Yang Yingliang [this message]
2021-12-23  1:41 ` [PATCH] chardev: fix error handling in cdev_device_add() Yang Yingliang
2021-12-23  7:15   ` Greg KH
2021-12-23  7:43     ` Yang Yingliang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211012130915.3426584-1-yangyingliang@huawei.com \
    --to=yangyingliang@huawei.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.