Skip to contentSkip to conversation

regmap: kunit: Fix an NULL vs IS_ERR() check

PATCH In review Dan Carpenter 4 participants 4 messages Apr 15, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regmap: kunit: Fix an NULL vs IS_ERR() check

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")
---
 drivers/base/regmap/regmap-kunit.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/base/regmap/regmap-kunit.c +3 -3
index 44265dc2313d..9c5314785fc2 100644
@@ -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;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Dan Carpenter

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")
---
  drivers/base/regmap/regmap-kunit.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/base/regmap/regmap-kunit.c +0 -0
index 44265dc2313d..9c5314785fc2 100644
@@ -1925,10 +1925,10 @@ static int regmap_test_init(struct kunit *test)
  	test->priv = priv;
 
  	dev = kunit_device_register(test, "regmap_test");

drivers/base/regmap/regmap-kunit.c static int regmap_test_init(struct kunit *test) · line 1934

Quoted 10 lines
drivers/base/regmap/regmap-kunit.c +3 -3
-	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 lore raw
In reply to Dan Carpenter
Quoted 3 lines

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. …

How do you think about to convert this adjustment into a patch series with two update steps?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.9-rc4#n81

Regards,
Markus

maintainer
#3 lore raw
In reply to Dan Carpenter
Quoted 5 lines · Dan Carpenter

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! ;)

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next

Thanks!

[1/1] regmap: kunit: Fix an NULL vs IS_ERR() check

      commit: 991b5e2aad870828669ca105f424ef1b2534f820

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark