From: Jens Wiklander <jens.wiklander@linaro.org>
To: linux-kernel@vger.kernel.org, Ulf Hansson <ulf.hansson@linaro.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jens Wiklander <jens.wiklander@linaro.org>,
Dan Carpenter <dan.carpenter@linaro.org>
Subject: [PATCH] rpmb: fix error path in rpmb_dev_register()
Date: Fri, 30 Aug 2024 08:14:04 +0200 [thread overview]
Message-ID: <20240830061404.2831708-1-jens.wiklander@linaro.org> (raw)
Until this patch was rpmb_dev_register() always freeing rdev in the
error path. However, past device_register() it must not do that since
the memory is now managed by the device even if it failed to register
properly. So fix this by doing a device_put() before returning the error
code.
Fixes the smatch warning:
drivers/misc/rpmb-core.c:204 rpmb_dev_register()
warn: freeing device managed memory (leak): 'rdev'
Fixes: 1e9046e3a154 ("rpmb: add Replay Protected Memory Block (RPMB) subsystem")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
---
drivers/misc/rpmb-core.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/misc/rpmb-core.c b/drivers/misc/rpmb-core.c
index c8888267c222..9d41404f8b91 100644
--- a/drivers/misc/rpmb-core.c
+++ b/drivers/misc/rpmb-core.c
@@ -187,8 +187,10 @@ struct rpmb_dev *rpmb_dev_register(struct device *dev,
rdev->dev.parent = dev;
ret = device_register(&rdev->dev);
- if (ret)
- goto err_id_remove;
+ if (ret) {
+ put_device(&rdev->dev);
+ return ERR_PTR(ret);
+ }
dev_dbg(&rdev->dev, "registered device\n");
--
2.34.1
next reply other threads:[~2024-08-30 6:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-30 6:14 Jens Wiklander [this message]
2024-09-02 7:49 ` kernel test robot
2024-09-02 8:51 ` kernel test robot
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=20240830061404.2831708-1-jens.wiklander@linaro.org \
--to=jens.wiklander@linaro.org \
--cc=arnd@arndb.de \
--cc=dan.carpenter@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ulf.hansson@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
all inboxes | Powered by JetHome®