lib: packing: catch kunit_kzalloc() failure in the pack() test
authorVladimir Oltean <vladimir.oltean@nxp.com>
Fri, 4 Oct 2024 11:00:12 +0000 (14:00 +0300)
committerJakub Kicinski <kuba@kernel.org>
Mon, 7 Oct 2024 23:36:25 +0000 (16:36 -0700)
kunit_kzalloc() may fail. Other call sites verify that this is the case,
either using a direct comparison with the NULL pointer, or the
KUNIT_ASSERT_NOT_NULL() or KUNIT_ASSERT_NOT_ERR_OR_NULL().

Pick KUNIT_ASSERT_NOT_NULL() as the error handling method that made most
sense to me. It's an unlikely thing to happen, but at least we call
__kunit_abort() instead of dereferencing this NULL pointer.

Fixes: e9502ea6db8a ("lib: packing: add KUnit tests adapted from selftests")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20241004110012.1323427-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
lib/packing_test.c

index 015ad1180d23d04dcb9324fe6ffc8a861da13fa9..b38ea43c03fd83639f18a6f3e2a42eae36118c45 100644 (file)
@@ -375,6 +375,7 @@ static void packing_test_pack(struct kunit *test)
        int err;
 
        pbuf = kunit_kzalloc(test, params->pbuf_size, GFP_KERNEL);
+       KUNIT_ASSERT_NOT_NULL(test, pbuf);
 
        err = pack(pbuf, params->uval, params->start_bit, params->end_bit,
                   params->pbuf_size, params->quirks);