mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH next] media: i2c: fix error handling in ub960_rxport_add_serializer()
@ 2023-07-18  8:58 Harshit Mogalapalli
  2023-07-18 13:31 ` Tomi Valkeinen
  2023-07-18 13:58 ` Andy Shevchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Harshit Mogalapalli @ 2023-07-18  8:58 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>
---
Found with static analysis, only compile tested. Although in
drivers/media i2c_client_has_driver() checks are present, IS_ERR() would
probably be sufficient here.
---
 drivers/media/i2c/ds90ub960.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c
index e101bcf2356a..88144e3ec183 100644
--- a/drivers/media/i2c/ds90ub960.c
+++ b/drivers/media/i2c/ds90ub960.c
@@ -1662,7 +1662,7 @@ 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;
-- 
2.39.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH next] media: i2c: fix error handling in ub960_rxport_add_serializer()
  2023-07-18  8:58 [PATCH next] media: i2c: fix error handling in ub960_rxport_add_serializer() Harshit Mogalapalli
@ 2023-07-18 13:31 ` Tomi Valkeinen
  2023-07-18 13:38   ` Harshit Mogalapalli
  2023-07-18 13:58 ` Andy Shevchenko
  1 sibling, 1 reply; 5+ messages in thread
From: Tomi Valkeinen @ 2023-07-18 13:31 UTC (permalink / raw)
  To: Harshit Mogalapalli, Mauro Carvalho Chehab, Sakari Ailus,
	Andy Shevchenko, linux-media, linux-kernel
  Cc: dan.carpenter, kernel-janitors, error27

Hi,

On 18/07/2023 11:58, 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>
> ---
> Found with static analysis, only compile tested. Although in
> drivers/media i2c_client_has_driver() checks are present, IS_ERR() would
> probably be sufficient here.
> ---
>   drivers/media/i2c/ds90ub960.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c
> index e101bcf2356a..88144e3ec183 100644
> --- a/drivers/media/i2c/ds90ub960.c
> +++ b/drivers/media/i2c/ds90ub960.c
> @@ -1662,7 +1662,7 @@ 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;

Good catch. I think this should be modified to return 
PTR_ERR(rxport->ser.client) instead of -EIO. Do you want to update the 
patch or shall I do the change?

  Tomi


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH next] media: i2c: fix error handling in ub960_rxport_add_serializer()
  2023-07-18 13:31 ` Tomi Valkeinen
@ 2023-07-18 13:38   ` Harshit Mogalapalli
  0 siblings, 0 replies; 5+ messages in thread
From: Harshit Mogalapalli @ 2023-07-18 13:38 UTC (permalink / raw)
  To: Tomi Valkeinen, Mauro Carvalho Chehab, Sakari Ailus,
	Andy Shevchenko, linux-media, linux-kernel
  Cc: dan.carpenter, kernel-janitors, error27

Hi Tomi,

On 18/07/23 7:01 pm, Tomi Valkeinen wrote:
> Hi,
> 
> On 18/07/2023 11:58, 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>
>> ---
>> Found with static analysis, only compile tested. Although in
>> drivers/media i2c_client_has_driver() checks are present, IS_ERR() would
>> probably be sufficient here.
>> ---
>>   drivers/media/i2c/ds90ub960.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/i2c/ds90ub960.c 
>> b/drivers/media/i2c/ds90ub960.c
>> index e101bcf2356a..88144e3ec183 100644
>> --- a/drivers/media/i2c/ds90ub960.c
>> +++ b/drivers/media/i2c/ds90ub960.c
>> @@ -1662,7 +1662,7 @@ 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;
> 
> Good catch. I think this should be modified to return 
> PTR_ERR(rxport->ser.client) instead of -EIO. Do you want to update the 
> patch or shall I do the change?

Thanks,

I think it is easier for me to do that change PTR_ERR change. Will send 
V2 with that change added.

Regards,
Harshit

> 
>   Tomi
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH next] media: i2c: fix error handling in ub960_rxport_add_serializer()
  2023-07-18  8:58 [PATCH next] media: i2c: fix error handling in ub960_rxport_add_serializer() Harshit Mogalapalli
  2023-07-18 13:31 ` Tomi Valkeinen
@ 2023-07-18 13:58 ` Andy Shevchenko
  2023-07-18 14:10   ` Harshit Mogalapalli
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2023-07-18 13:58 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 01:58:46AM -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.

...

> -	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;

It should be changed to return PTR_ERR(...);

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH next] media: i2c: fix error handling in ub960_rxport_add_serializer()
  2023-07-18 13:58 ` Andy Shevchenko
@ 2023-07-18 14:10   ` Harshit Mogalapalli
  0 siblings, 0 replies; 5+ messages in thread
From: Harshit Mogalapalli @ 2023-07-18 14:10 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Tomi Valkeinen, Mauro Carvalho Chehab, Sakari Ailus, linux-media,
	linux-kernel, dan.carpenter, kernel-janitors, error27

Hi Andy,

On 18/07/23 7:28 pm, Andy Shevchenko wrote:
> On Tue, Jul 18, 2023 at 01:58:46AM -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.
> 
> ...
> 
>> -	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;
> 
> It should be changed to return PTR_ERR(...);

I just sent a V2 with this suggestion included.

Thanks,
Harshit

> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-18 14:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18  8:58 [PATCH next] media: i2c: fix error handling in ub960_rxport_add_serializer() Harshit Mogalapalli
2023-07-18 13:31 ` Tomi Valkeinen
2023-07-18 13:38   ` Harshit Mogalapalli
2023-07-18 13:58 ` Andy Shevchenko
2023-07-18 14:10   ` Harshit Mogalapalli

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®