public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] firewire: test: Fix potential null dereference in firewire kunit test
@ 2025-01-10  8:42 Charles Han
  2025-01-13  1:42 ` Takashi Sakamoto
  0 siblings, 1 reply; 2+ messages in thread
From: Charles Han @ 2025-01-10  8:42 UTC (permalink / raw)
  To: o-takashi; +Cc: linux1394-devel, linux-kernel, Charles Han

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: 1c8506d62624 ("firewire: test: add test of device attributes for simple AV/C device")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
 drivers/firewire/device-attribute-test.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/firewire/device-attribute-test.c b/drivers/firewire/device-attribute-test.c
index 2f123c6b0a16..97478a96d1c9 100644
--- a/drivers/firewire/device-attribute-test.c
+++ b/drivers/firewire/device-attribute-test.c
@@ -99,6 +99,7 @@ static void device_attr_simple_avc(struct kunit *test)
 	struct device *unit0_dev = (struct device *)&unit0.device;
 	static const int unit0_expected_ids[] = {0x00ffffff, 0x00ffffff, 0x0000a02d, 0x00010001};
 	char *buf = kunit_kzalloc(test, PAGE_SIZE, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
 	int ids[4] = {0, 0, 0, 0};
 
 	// Ensure associations for node and unit devices.
@@ -180,6 +181,7 @@ static void device_attr_legacy_avc(struct kunit *test)
 	struct device *unit0_dev = (struct device *)&unit0.device;
 	static const int unit0_expected_ids[] = {0x00012345, 0x00fedcba, 0x00abcdef, 0x00543210};
 	char *buf = kunit_kzalloc(test, PAGE_SIZE, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
 	int ids[4] = {0, 0, 0, 0};
 
 	// Ensure associations for node and unit devices.
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] firewire: test: Fix potential null dereference in firewire kunit test
  2025-01-10  8:42 [PATCH] firewire: test: Fix potential null dereference in firewire kunit test Charles Han
@ 2025-01-13  1:42 ` Takashi Sakamoto
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Sakamoto @ 2025-01-13  1:42 UTC (permalink / raw)
  To: Charles Han; +Cc: linux1394-devel, linux-kernel

Hi,

On Fri, Jan 10, 2025 at 04:42:37PM +0800, Charles Han wrote:
> 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: 1c8506d62624 ("firewire: test: add test of device attributes for simple AV/C device")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
> ---
>  drivers/firewire/device-attribute-test.c | 2 ++
>  1 file changed, 2 insertions(+)

Applied to for-next branch.


Thanks

Takashi Sakamoto

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-01-13  1:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-10  8:42 [PATCH] firewire: test: Fix potential null dereference in firewire kunit test Charles Han
2025-01-13  1:42 ` Takashi Sakamoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox