lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220723043229.2953386-1-williamsukatube@163.com>
Date:   Sat, 23 Jul 2022 12:32:29 +0800
From:   williamsukatube@....com
To:     bence98@....bme.hu, linux-i2c@...r.kernel.org,
        linux-kernel@...r.kernel.org
Cc:     William Dean <williamsukatube@...il.com>,
        Hacash Robot <hacashRobot@...tino.com>
Subject: [PATCH] i2c: cp2615: check the return value of kzalloc()

From: William Dean <williamsukatube@...il.com>

kzalloc() is a memory allocation function which can return NULL when
some internal memory errors happen. So it is better to check the
return value of it to prevent potential wrong memory access or
memory leak.

Fixes: 4a7695429eade ("i2c: cp2615: add i2c driver for Silicon Labs' CP2615 Digital Audio Bridge")
Reported-by: Hacash Robot <hacashRobot@...tino.com>
Signed-off-by: William Dean <williamsukatube@...il.com>
---
 drivers/i2c/busses/i2c-cp2615.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-cp2615.c b/drivers/i2c/busses/i2c-cp2615.c
index 3ded28632e4c..7c9403346615 100644
--- a/drivers/i2c/busses/i2c-cp2615.c
+++ b/drivers/i2c/busses/i2c-cp2615.c
@@ -171,11 +171,17 @@ cp2615_i2c_recv(struct usb_interface *usbif, unsigned char tag, void *buf)
 /* Checks if the IOP is functional by querying the part's ID */
 static int cp2615_check_iop(struct usb_interface *usbif)
 {
-	struct cp2615_iop_msg *msg = kzalloc(sizeof(*msg), GFP_KERNEL);
-	struct cp2615_iop_accessory_info *info = (struct cp2615_iop_accessory_info *)&msg->data;
+	struct cp2615_iop_msg *msg;
+	struct cp2615_iop_accessory_info *info;
 	struct usb_device *usbdev = interface_to_usbdev(usbif);
-	int res = cp2615_init_iop_msg(msg, iop_GetAccessoryInfo, NULL, 0);
+	int res;
+
+	msg = kzalloc(sizeof(*msg), GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
 
+	info = (struct cp2615_iop_accessory_info *)&msg->data;
+	res = cp2615_init_iop_msg(msg, iop_GetAccessoryInfo, NULL, 0);
 	if (res)
 		goto out;
 
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ