From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ssh247.corpemail.net (ssh247.corpemail.net [210.51.61.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 056F21FF7DA for ; Fri, 10 Jan 2025 08:43:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.51.61.247 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736498643; cv=none; b=AJrFM9dYbhBKKsmaj2CjrB21sCHjmgYcCRsxMztpxz+tgnXsT5+xcBfHqFCt+/46nruLLL8xK6SITQalTNaAxi9wErUfgVa6OuvrPsFzP4HKujsGNK+tq4z9l2rF4FumJD51I+JSk0KkzfXSQ/jX/uooENwmBXEuByA8qvNAgsA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736498643; c=relaxed/simple; bh=/qloVkrKTq/4YAkhIv/I3RlVEhLXzNTX2F7DBz8Z+rA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=u+o0FttSXI4p+xVSnWLMrITE8TkyzaGcW9Cr6Uba6qkevT1xcDg0wHM6ORphvZHQ0sMrB+cbYY39EEqA40MV9SOoVWiaxE5KuoFZLQonIao/rCV9YMty++qQZ03M437itvSbJ75+3GYgqePW6+KXBXYu+emznsEjAplRUO/OsaY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=inspur.com; spf=pass smtp.mailfrom=inspur.com; arc=none smtp.client-ip=210.51.61.247 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=inspur.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=inspur.com Received: from ssh247.corpemail.net by ssh247.corpemail.net ((D)) with ASMTP (SSL) id IBB00139; Fri, 10 Jan 2025 16:42:39 +0800 Received: from localhost.localdomain (10.94.7.238) by jtjnmail201610.home.langchao.com (10.100.2.10) with Microsoft SMTP Server id 15.1.2507.39; Fri, 10 Jan 2025 16:42:38 +0800 From: Charles Han To: CC: , , Charles Han Subject: [PATCH] firewire: test: Fix potential null dereference in firewire kunit test Date: Fri, 10 Jan 2025 16:42:37 +0800 Message-ID: <20250110084237.8877-1-hanchunchao@inspur.com> X-Mailer: git-send-email 2.31.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain tUid: 202511016423971ce7a444f9f955acc84406b21cde484 X-Abuse-Reports-To: service@corp-email.com Abuse-Reports-To: service@corp-email.com X-Complaints-To: service@corp-email.com X-Report-Abuse-To: service@corp-email.com 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 --- 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