2023-12-03 05:32:38

by Haoran Liu

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

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 <[email protected]>
---
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


2023-12-03 12:39:18

by Andi Shyti

[permalink] [raw]
Subject: Re: [PATCH] [i2c] robotfuzz-osif: Add error handling for i2c_add_adapter in osif_probe

Hi Haoran,

I made some comments on your 3rd patch. Could you please combine
these three patches into a single series?

Also, please remove the [i2c] tag from the subject.

Thanks,
Andi

On Sat, Dec 02, 2023 at 09:31:42PM -0800, Haoran Liu wrote:
> 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 <[email protected]>
> ---
> 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
>