public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafał Miłecki" <zajec5@gmail.com>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: "Johan Hovold" <johan@kernel.org>,
	"Andrey Smirnov" <andrew.smirnov@gmail.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org, "Rafał Miłecki" <rafal@milecki.pl>
Subject: [PATCH] nvmem: fix unregistering device in nvmem_register() error path
Date: Tue, 21 Dec 2021 16:45:50 +0100	[thread overview]
Message-ID: <20211221154550.11455-1-zajec5@gmail.com> (raw)

From: Rafał Miłecki <rafal@milecki.pl>

1. Drop incorrect put_device() calls

If device_register() fails then underlaying device_add() takes care of
calling put_device() if needed. There is no need to do that in a driver.

2. Use device_unregister()

Now that we don't call put_device() we can use above helper.

Fixes: 3360acdf8391 ("nvmem: core: fix leaks on registration errors")
Cc: Johan Hovold <johan@kernel.org>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
That put_device() was explicitly added by Johan but after checking
device_register() twice I still think it's incorrect. I hope I didn't
miss sth obvious and I didn't mess it up.
---
 drivers/nvmem/core.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 785a56e33f69..f7f31af7226f 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -901,12 +901,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 
 	rval = device_register(&nvmem->dev);
 	if (rval)
-		goto err_put_device;
+		return ERR_PTR(rval);
 
 	if (config->compat) {
 		rval = nvmem_sysfs_setup_compat(nvmem, config);
 		if (rval)
-			goto err_device_del;
+			goto err_device_unreg;
 	}
 
 	if (config->cells) {
@@ -932,10 +932,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 err_teardown_compat:
 	if (config->compat)
 		nvmem_sysfs_remove_compat(nvmem, config);
-err_device_del:
-	device_del(&nvmem->dev);
-err_put_device:
-	put_device(&nvmem->dev);
+err_device_unreg:
+	device_unregister(&nvmem->dev);
 
 	return ERR_PTR(rval);
 }
-- 
2.31.1


             reply	other threads:[~2021-12-21 15:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21 15:45 Rafał Miłecki [this message]
2021-12-21 16:06 ` [PATCH] nvmem: fix unregistering device in nvmem_register() error path Greg Kroah-Hartman
2021-12-21 17:46   ` Rafał Miłecki
2021-12-22  7:44     ` Greg Kroah-Hartman
2021-12-22  8:38       ` Johan Hovold
2021-12-22  8:56         ` Greg Kroah-Hartman
2021-12-22  9:02           ` Rafał Miłecki
2021-12-22  9:03           ` Johan Hovold
2021-12-22  9:24             ` Johan Hovold
2021-12-22  9:34               ` Greg Kroah-Hartman
2021-12-22  9:00         ` Rafał Miłecki
2021-12-22  9:08           ` Johan Hovold
2021-12-22  9:16             ` Rafał Miłecki
2021-12-22  9:26               ` Johan Hovold
2021-12-22  9:46                 ` Rafał Miłecki
2021-12-22  9:30               ` Greg Kroah-Hartman
2021-12-22  9:29           ` Greg Kroah-Hartman

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=20211221154550.11455-1-zajec5@gmail.com \
    --to=zajec5@gmail.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafal@milecki.pl \
    --cc=srinivas.kandagatla@linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox