From: Dan Carpenter <dan.carpenter@linaro.org>
To: Richard Fitzgerald <rf@opensource.cirrus.com>
Cc: Mark Brown <broonie@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH] regmap: kunit: Fix an NULL vs IS_ERR() check
Date: Mon, 15 Apr 2024 13:34:54 +0300 [thread overview]
Message-ID: <b32e80cf-b385-40cd-b8ec-77ec73e07530@moroto.mountain> (raw)
The kunit_device_register() function returns error pointers, not NULL.
Passing an error pointer to get_device() will lead to an Oops. Also
get_device() returns the same device you passed to it. Fix it! ;)
Fixes: 7b7982f14315 ("regmap: kunit: Create a struct device for the regmap")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/base/regmap/regmap-kunit.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/base/regmap/regmap-kunit.c b/drivers/base/regmap/regmap-kunit.c
index 44265dc2313d..9c5314785fc2 100644
--- a/drivers/base/regmap/regmap-kunit.c
+++ b/drivers/base/regmap/regmap-kunit.c
@@ -1925,10 +1925,10 @@ static int regmap_test_init(struct kunit *test)
test->priv = priv;
dev = kunit_device_register(test, "regmap_test");
- priv->dev = get_device(dev);
- if (!priv->dev)
- return -ENODEV;
+ if (IS_ERR(dev))
+ return PTR_ERR(dev);
+ priv->dev = get_device(dev);
dev_set_drvdata(dev, test);
return 0;
--
2.43.0
next reply other threads:[~2024-04-15 10:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 10:34 Dan Carpenter [this message]
2024-04-15 13:31 ` Richard Fitzgerald
2024-04-15 16:00 ` Markus Elfring
2024-04-15 23:43 ` Mark Brown
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=b32e80cf-b385-40cd-b8ec-77ec73e07530@moroto.mountain \
--to=dan.carpenter@linaro.org \
--cc=broonie@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rf@opensource.cirrus.com \
/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®