* [PATCH v2 next] media: i2c: fix error handling in ub960_rxport_add_serializer()
@ 2023-07-18 14:06 Harshit Mogalapalli
2023-07-18 14:19 ` Andy Shevchenko
2023-07-18 14:45 ` Tomi Valkeinen
0 siblings, 2 replies; 3+ messages in thread
From: Harshit Mogalapalli @ 2023-07-18 14:06 UTC (permalink / raw)
To: Tomi Valkeinen, Mauro Carvalho Chehab, Sakari Ailus,
Andy Shevchenko, linux-media, linux-kernel
Cc: dan.carpenter, kernel-janitors, error27, harshit.m.mogalapalli
Smatch warns:
drivers/media/i2c/ds90ub960.c:1671 ub960_rxport_add_serializer():
err: 'rxport->ser.client' dereferencing possible ERR_PTR()
i2c_new_client_device() returns error pointers on failure and in
dev_dbg statement we are dereferencing error pointer which is a bug.
Fix this by using IS_ERR() which checks for error pointers.
Fixes: afe267f2d368 ("media: i2c: add DS90UB960 driver")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
This is based on static analysis and only compile tested.
V1->V2: Suggestion from Tomi Valkeinen: Propogate the error code with
PTR_ERR() instead of -EIO.
---
drivers/media/i2c/ds90ub960.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c
index e101bcf2356a..92aa004a3674 100644
--- a/drivers/media/i2c/ds90ub960.c
+++ b/drivers/media/i2c/ds90ub960.c
@@ -1662,10 +1662,10 @@ static int ub960_rxport_add_serializer(struct ub960_data *priv, u8 nport)
ser_info.addr = rxport->ser.alias;
rxport->ser.client =
i2c_new_client_device(priv->client->adapter, &ser_info);
- if (!rxport->ser.client) {
+ if (IS_ERR(rxport->ser.client)) {
dev_err(dev, "rx%u: cannot add %s i2c device", nport,
ser_info.type);
- return -EIO;
+ return PTR_ERR(rxport->ser.client);
}
dev_dbg(dev, "rx%u: remote serializer at alias 0x%02x (%u-%04x)\n",
--
2.39.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 next] media: i2c: fix error handling in ub960_rxport_add_serializer()
2023-07-18 14:06 [PATCH v2 next] media: i2c: fix error handling in ub960_rxport_add_serializer() Harshit Mogalapalli
@ 2023-07-18 14:19 ` Andy Shevchenko
2023-07-18 14:45 ` Tomi Valkeinen
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2023-07-18 14:19 UTC (permalink / raw)
To: Harshit Mogalapalli
Cc: Tomi Valkeinen, Mauro Carvalho Chehab, Sakari Ailus, linux-media,
linux-kernel, dan.carpenter, kernel-janitors, error27
On Tue, Jul 18, 2023 at 07:06:58AM -0700, Harshit Mogalapalli wrote:
> Smatch warns:
> drivers/media/i2c/ds90ub960.c:1671 ub960_rxport_add_serializer():
> err: 'rxport->ser.client' dereferencing possible ERR_PTR()
>
> i2c_new_client_device() returns error pointers on failure and in
> dev_dbg statement we are dereferencing error pointer which is a bug.
>
> Fix this by using IS_ERR() which checks for error pointers.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 next] media: i2c: fix error handling in ub960_rxport_add_serializer()
2023-07-18 14:06 [PATCH v2 next] media: i2c: fix error handling in ub960_rxport_add_serializer() Harshit Mogalapalli
2023-07-18 14:19 ` Andy Shevchenko
@ 2023-07-18 14:45 ` Tomi Valkeinen
1 sibling, 0 replies; 3+ messages in thread
From: Tomi Valkeinen @ 2023-07-18 14:45 UTC (permalink / raw)
To: Harshit Mogalapalli, Mauro Carvalho Chehab, Sakari Ailus,
Andy Shevchenko, linux-media, linux-kernel
Cc: dan.carpenter, kernel-janitors, error27
On 18/07/2023 17:06, Harshit Mogalapalli wrote:
> Smatch warns:
> drivers/media/i2c/ds90ub960.c:1671 ub960_rxport_add_serializer():
> err: 'rxport->ser.client' dereferencing possible ERR_PTR()
>
> i2c_new_client_device() returns error pointers on failure and in
> dev_dbg statement we are dereferencing error pointer which is a bug.
>
> Fix this by using IS_ERR() which checks for error pointers.
>
> Fixes: afe267f2d368 ("media: i2c: add DS90UB960 driver")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> ---
> This is based on static analysis and only compile tested.
>
> V1->V2: Suggestion from Tomi Valkeinen: Propogate the error code with
> PTR_ERR() instead of -EIO.
> ---
> drivers/media/i2c/ds90ub960.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c
> index e101bcf2356a..92aa004a3674 100644
> --- a/drivers/media/i2c/ds90ub960.c
> +++ b/drivers/media/i2c/ds90ub960.c
> @@ -1662,10 +1662,10 @@ static int ub960_rxport_add_serializer(struct ub960_data *priv, u8 nport)
> ser_info.addr = rxport->ser.alias;
> rxport->ser.client =
> i2c_new_client_device(priv->client->adapter, &ser_info);
> - if (!rxport->ser.client) {
> + if (IS_ERR(rxport->ser.client)) {
> dev_err(dev, "rx%u: cannot add %s i2c device", nport,
> ser_info.type);
> - return -EIO;
> + return PTR_ERR(rxport->ser.client);
> }
>
> dev_dbg(dev, "rx%u: remote serializer at alias 0x%02x (%u-%04x)\n",
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Tomi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-18 14:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18 14:06 [PATCH v2 next] media: i2c: fix error handling in ub960_rxport_add_serializer() Harshit Mogalapalli
2023-07-18 14:19 ` Andy Shevchenko
2023-07-18 14:45 ` Tomi Valkeinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®