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>] [day] [month] [year] [list]
Message-Id: <20231203084929.38168-1-liuhaoran14@163.com>
Date:   Sun,  3 Dec 2023 00:49:29 -0800
From:   Haoran Liu <liuhaoran14@....com>
To:     till@...baum.org
Cc:     andi.shyti@...nel.org, linux-i2c@...r.kernel.org,
        linux-kernel@...r.kernel.org, Haoran Liu <liuhaoran14@....com>
Subject: [PATCH] [i2c] tiny-usb: Add error handling in i2c_tiny_usb_probe

This patch adds error handling for the i2c_add_adapter. The need for this
error handling was identified through static analysis, which revealed that
the function did not properly address potential failures of
i2c_add_adapter. Previously, a failure in this call could lead to an
incomplete initialization of the I2C adapter, causing unpredictable
behavior.

Although the error addressed by this patch may not occur in the current
environment, I still suggest implementing these error handling routines
if the function is not highly time-sensitive. As the environment evolves
or the code gets reused in different contexts, there's a possibility that
these errors might occur. In case you find this addition unnecessary, I
completely understand and respect your perspective. My intention was to
enhance the robustness of the code, but I acknowledge that practical
considerations and current functionality might not warrant this change
at this point.

Signed-off-by: Haoran Liu <liuhaoran14@....com>
---
 drivers/i2c/busses/i2c-tiny-usb.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
index 1bffe36c40ad..f165e20fea53 100644
--- a/drivers/i2c/busses/i2c-tiny-usb.c
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -264,7 +264,12 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
 	dev->adapter.dev.parent = &dev->interface->dev;
 
 	/* and finally attach to i2c layer */
-	i2c_add_adapter(&dev->adapter);
+	retval = i2c_add_adapter(&dev->adapter);
+	if (retval) {
+		dev_err(&interface->dev, "i2c_add_adapter failed: %d\n",
+			retval);
+		goto error;
+	}
 
 	/* inform user about successful attachment to i2c layer */
 	dev_info(&dev->adapter.dev, "connected i2c-tiny-usb device\n");
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ