[PATCH] [i2c] robotfuzz-osif: Add error handling for i2c_add_adapter in osif_probe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch introduces error handling for the i2c_add_adapter. This missing
error handling was identified through static analysis, revealing that the
function did not properly address potential failures of i2c_add_adapter.
Previously, such a failure could result in incomplete initialization of
the I2C adapter, leading to erratic 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@xxxxxxx>
---
 drivers/i2c/busses/i2c-robotfuzz-osif.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-robotfuzz-osif.c b/drivers/i2c/busses/i2c-robotfuzz-osif.c
index 66dfa211e736..0f4d84449050 100644
--- a/drivers/i2c/busses/i2c-robotfuzz-osif.c
+++ b/drivers/i2c/busses/i2c-robotfuzz-osif.c
@@ -161,7 +161,12 @@ static int osif_probe(struct usb_interface *interface,
 		return ret;
 	}
 
-	i2c_add_adapter(&(priv->adapter));
+	ret = i2c_add_adapter(&(priv->adapter));
+	if (ret) {
+		dev_err(&interface->dev, "i2c_add_adapter failed: %d\n", ret);
+		usb_put_dev(priv->usb_dev);
+		return ret;
+	}
 
 	version = le16_to_cpu(priv->usb_dev->descriptor.bcdDevice);
 	dev_info(&interface->dev,
-- 
2.17.1





[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux