regmap: kunit: Replace a kmalloc/kfree() pair with KUnit-managed alloc

BugLink: https://bugs.launchpad.net/bugs/2083656

Replace the kmalloc() and kfree() in raw_read_defaults() with a
kunit_kmalloc() so that KUnit will free it automatically.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://msgid.link/r/20240408144600.230848-10-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
(backported from commit d6f2fd7adcb5f25ac661808be9409f846b1de6fe)
[koichiroden: prereq for "regmap: kunit: Fix memory leaks in
gen_regmap() and gen_raw_regmap()"]
Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
This commit is contained in:
Richard Fitzgerald
2024-04-08 15:45:58 +01:00
committed by Mehmet Basaran
parent 6fdb2273eb
commit bf328eefa6
+1 -3
View File
@@ -1078,7 +1078,7 @@ static void raw_read_defaults(struct kunit *test)
return;
val_len = sizeof(*rval) * (config.max_register + 1);
rval = kmalloc(val_len, GFP_KERNEL);
rval = kunit_kmalloc(test, val_len, GFP_KERNEL);
KUNIT_ASSERT_TRUE(test, rval != NULL);
if (!rval)
return;
@@ -1093,8 +1093,6 @@ static void raw_read_defaults(struct kunit *test)
KUNIT_EXPECT_EQ(test, def, le16_to_cpu(rval[i]));
}
}
kfree(rval);
}
static void raw_write_read_single(struct kunit *test)