Re: [PATCH] kunit: Fix a NULL vs IS_ERR() bug

From: Rae Moar
Date: Wed Jan 10 2024 - 15:50:45 EST


On Wed, Jan 10, 2024 at 1:55 PM Dan Carpenter <dan.carpenter@linaroorg> wrote:
>
> The kunit_device_register() function doesn't return NULL, it returns
> error pointers. Change the KUNIT_ASSERT_NOT_NULL() to check for
> ERR_OR_NULL().
>
> Fixes: d03c720e03bd ("kunit: Add APIs for managing devices")
> Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

This change looks good to me! Thanks!
-Rae

Reviewed-by: Rae Moar <rmoar@xxxxxxxxxx>

> ---
> It's a pity that there isn't a KUNIT_ASSERT_NOT_ERR_PTR() macro...
>
> lib/kunit/kunit-test.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c
> index c4259d910356..f7980ef236a3 100644
> --- a/lib/kunit/kunit-test.c
> +++ b/lib/kunit/kunit-test.c
> @@ -720,7 +720,7 @@ static void kunit_device_cleanup_test(struct kunit *test)
> long action_was_run = 0;
>
> test_device = kunit_device_register(test, "my_device");
> - KUNIT_ASSERT_NOT_NULL(test, test_device);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, test_device);
>
> /* Add an action to verify cleanup. */
> devm_add_action(test_device, test_dev_action, &action_was_run);
> --
> 2.43.0
>
> --
> You received this message because you are subscribed to the Google Groups "KUnit Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+unsubscribe@xxxxxxxxxxxxxxxx.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/39b4278f-35d2-4071-a3aa-ec49705272af%40moroto.mountain.