Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ALSA: core: Fix possible NULL dereference caused by kunit_kzalloc()

kunit_kzalloc() may return a NULL pointer, dereferencing it without
NULL check may lead to NULL dereference.
Add NULL checks for all the kunit_kzalloc() in sound_kunit.c

Fixes: 3e39acf56ede ("ALSA: core: Add sound core KUnit test")
Signed-off-by: Zichen Xie <zichenxie0106@gmail.com>
Link: https://patch.msgid.link/20241126192448.12645-1-zichenxie0106@gmail.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Zichen Xie and committed by
Takashi Iwai
9ad467a2 db2eee61

+11
+11
sound/core/sound_kunit.c
··· 172 172 u32 i, j; 173 173 174 174 buffer = kunit_kzalloc(test, SILENCE_BUFFER_SIZE, GFP_KERNEL); 175 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buffer); 175 176 176 177 for (i = 0; i < ARRAY_SIZE(buf_samples); i++) { 177 178 for (j = 0; j < ARRAY_SIZE(valid_fmt); j++) ··· 209 208 struct snd_pcm_runtime *r = kunit_kzalloc(test, sizeof(*r), GFP_KERNEL); 210 209 u32 i; 211 210 211 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, r); 212 + 212 213 r->status = kunit_kzalloc(test, sizeof(*r->status), GFP_KERNEL); 213 214 r->control = kunit_kzalloc(test, sizeof(*r->control), GFP_KERNEL); 215 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, r->status); 216 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, r->control); 214 217 215 218 for (i = 0; i < ARRAY_SIZE(p_avail_data); i++) { 216 219 r->buffer_size = p_avail_data[i].buffer_size; ··· 237 232 struct snd_pcm_runtime *r = kunit_kzalloc(test, sizeof(*r), GFP_KERNEL); 238 233 u32 i; 239 234 235 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, r); 236 + 240 237 r->status = kunit_kzalloc(test, sizeof(*r->status), GFP_KERNEL); 241 238 r->control = kunit_kzalloc(test, sizeof(*r->control), GFP_KERNEL); 239 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, r->status); 240 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, r->control); 242 241 243 242 for (i = 0; i < ARRAY_SIZE(c_avail_data); i++) { 244 243 r->buffer_size = c_avail_data[i].buffer_size; ··· 256 247 static void test_card_set_id(struct kunit *test) 257 248 { 258 249 struct snd_card *card = kunit_kzalloc(test, sizeof(*card), GFP_KERNEL); 250 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, card); 259 251 260 252 snd_card_set_id(card, VALID_NAME); 261 253 KUNIT_EXPECT_STREQ(test, card->id, VALID_NAME); ··· 290 280 static void test_card_add_component(struct kunit *test) 291 281 { 292 282 struct snd_card *card = kunit_kzalloc(test, sizeof(*card), GFP_KERNEL); 283 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, card); 293 284 294 285 snd_component_add(card, TEST_FIRST_COMPONENT); 295 286 KUNIT_ASSERT_STREQ(test, card->components, TEST_FIRST_COMPONENT);