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: 7b7982f143 ("regmap: kunit: Create a struct device for the regmap")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/b32e80cf-b385-40cd-b8ec-77ec73e07530@moroto.mountain
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Dan Carpenter 2024-04-15 13:34:54 +03:00 committed by Mark Brown
parent 135cec6ba8
commit 991b5e2aad
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0

View File

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