Skip to content

Commit 352fafe

Browse files
Charles Hantakaswie
authored andcommitted
firewire: test: Fix potential null dereference in firewire kunit test
kunit_kzalloc() may return a NULL pointer, dereferencing it without NULL check may lead to NULL dereference. Add a NULL check for test_state. Fixes: 1c8506d ("firewire: test: add test of device attributes for simple AV/C device") Signed-off-by: Charles Han <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Sakamoto <[email protected]>
1 parent 892bb07 commit 352fafe

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/firewire/device-attribute-test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static void device_attr_simple_avc(struct kunit *test)
9999
struct device *unit0_dev = (struct device *)&unit0.device;
100100
static const int unit0_expected_ids[] = {0x00ffffff, 0x00ffffff, 0x0000a02d, 0x00010001};
101101
char *buf = kunit_kzalloc(test, PAGE_SIZE, GFP_KERNEL);
102+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
102103
int ids[4] = {0, 0, 0, 0};
103104

104105
// Ensure associations for node and unit devices.
@@ -180,6 +181,7 @@ static void device_attr_legacy_avc(struct kunit *test)
180181
struct device *unit0_dev = (struct device *)&unit0.device;
181182
static const int unit0_expected_ids[] = {0x00012345, 0x00fedcba, 0x00abcdef, 0x00543210};
182183
char *buf = kunit_kzalloc(test, PAGE_SIZE, GFP_KERNEL);
184+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
183185
int ids[4] = {0, 0, 0, 0};
184186

185187
// Ensure associations for node and unit devices.

0 commit comments

Comments
 (0)