All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: dvb-frontends/cxd2099: report errors
@ 2020-07-22 13:41 trix
  2020-09-03 14:13 ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 3+ messages in thread
From: trix @ 2020-07-22 13:41 UTC (permalink / raw)
  To: jasmin, mchehab, o.endriss, rjkm; +Cc: linux-media, linux-kernel, Tom Rix

From: Tom Rix <trix@redhat.com>

Clang static analysis reports this error

drivers/media/dvb-frontends/cxd2099.c:420:2: warning: Undefined
  or garbage value returned to caller
        return val;
        ^~~~~~~~~~

In read_cam_control, the call to read_io can fail.
When it fails val is not set.

The failure status should be returned to the caller,
not the unset val.

Similar problem with read_attribute_mem

Fixes: 0f0b270f905b ("[media] ngene: CXD2099AR Common Interface driver")

Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/media/dvb-frontends/cxd2099.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-frontends/cxd2099.c b/drivers/media/dvb-frontends/cxd2099.c
index f88b5355493e..9dfaf18fc4b4 100644
--- a/drivers/media/dvb-frontends/cxd2099.c
+++ b/drivers/media/dvb-frontends/cxd2099.c
@@ -387,12 +387,15 @@ static int read_attribute_mem(struct dvb_ca_en50221 *ca,
 {
 	struct cxd *ci = ca->data;
 	u8 val;
+	int ret;
 
 	mutex_lock(&ci->lock);
 	set_mode(ci, 1);
-	read_pccard(ci, address, &val, 1);
+	ret = read_pccard(ci, address, &val, 1);
+	if (!ret)
+		ret = val;
 	mutex_unlock(&ci->lock);
-	return val;
+	return ret;
 }
 
 static int write_attribute_mem(struct dvb_ca_en50221 *ca, int slot,
@@ -412,12 +415,15 @@ static int read_cam_control(struct dvb_ca_en50221 *ca,
 {
 	struct cxd *ci = ca->data;
 	unsigned int val;
+	int ret;
 
 	mutex_lock(&ci->lock);
 	set_mode(ci, 0);
-	read_io(ci, address, &val);
+	ret = read_io(ci, address, &val);
+	if (!ret)
+		ret = val;
 	mutex_unlock(&ci->lock);
-	return val;
+	return ret;
 }
 
 static int write_cam_control(struct dvb_ca_en50221 *ca, int slot,
-- 
2.18.1


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

* Re: [PATCH] media: dvb-frontends/cxd2099: report errors
  2020-07-22 13:41 [PATCH] media: dvb-frontends/cxd2099: report errors trix
@ 2020-09-03 14:13 ` Mauro Carvalho Chehab
  2020-09-03 14:41   ` Tom Rix
  0 siblings, 1 reply; 3+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-03 14:13 UTC (permalink / raw)
  To: trix; +Cc: jasmin, o.endriss, rjkm, linux-media, linux-kernel

Em Wed, 22 Jul 2020 06:41:26 -0700
trix@redhat.com escreveu:

> From: Tom Rix <trix@redhat.com>
> 
> Clang static analysis reports this error
> 
> drivers/media/dvb-frontends/cxd2099.c:420:2: warning: Undefined
>   or garbage value returned to caller
>         return val;
>         ^~~~~~~~~~
> 
> In read_cam_control, the call to read_io can fail.
> When it fails val is not set.
> 
> The failure status should be returned to the caller,
> not the unset val.
> 
> Similar problem with read_attribute_mem
> 
> Fixes: 0f0b270f905b ("[media] ngene: CXD2099AR Common Interface driver")
> 
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  drivers/media/dvb-frontends/cxd2099.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/dvb-frontends/cxd2099.c b/drivers/media/dvb-frontends/cxd2099.c
> index f88b5355493e..9dfaf18fc4b4 100644
> --- a/drivers/media/dvb-frontends/cxd2099.c
> +++ b/drivers/media/dvb-frontends/cxd2099.c
> @@ -387,12 +387,15 @@ static int read_attribute_mem(struct dvb_ca_en50221 *ca,
>  {
>  	struct cxd *ci = ca->data;
>  	u8 val;
> +	int ret;
>  
>  	mutex_lock(&ci->lock);
>  	set_mode(ci, 1);
> -	read_pccard(ci, address, &val, 1);
> +	ret = read_pccard(ci, address, &val, 1);
> +	if (!ret)
> +		ret = val;
>  	mutex_unlock(&ci->lock);
> -	return val;
> +	return ret;
>  }
>  
>  static int write_attribute_mem(struct dvb_ca_en50221 *ca, int slot,
> @@ -412,12 +415,15 @@ static int read_cam_control(struct dvb_ca_en50221 *ca,
>  {
>  	struct cxd *ci = ca->data;
>  	unsigned int val;
> +	int ret;
>  
>  	mutex_lock(&ci->lock);
>  	set_mode(ci, 0);
> -	read_io(ci, address, &val);
> +	ret = read_io(ci, address, &val);
> +	if (!ret)
> +		ret = val;
>  	mutex_unlock(&ci->lock);
> -	return val;
> +	return ret;
>  }
>  
>  static int write_cam_control(struct dvb_ca_en50221 *ca, int slot,

Hmm... Had you test this one on a real hardware? It is not
uncommon to have some DVB devices that would fail reading
when the firmware is on cold state.

Without testing a patch like that at a real hardware, there's
no way to know if this is intentional or if the original
developer forgot to add a check for the error.

So, at most, it could print some warning message for
non-zero return codes.


Thanks,
Mauro

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

* Re: [PATCH] media: dvb-frontends/cxd2099: report errors
  2020-09-03 14:13 ` Mauro Carvalho Chehab
@ 2020-09-03 14:41   ` Tom Rix
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Rix @ 2020-09-03 14:41 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: jasmin, o.endriss, rjkm, linux-media, linux-kernel


On 9/3/20 7:13 AM, Mauro Carvalho Chehab wrote:
> Em Wed, 22 Jul 2020 06:41:26 -0700
> trix@redhat.com escreveu:
>
>> From: Tom Rix <trix@redhat.com>
>>
>> Clang static analysis reports this error
>>
>> drivers/media/dvb-frontends/cxd2099.c:420:2: warning: Undefined
>>   or garbage value returned to caller
>>         return val;
>>         ^~~~~~~~~~
>>
>> In read_cam_control, the call to read_io can fail.
>> When it fails val is not set.
>>
>> The failure status should be returned to the caller,
>> not the unset val.
>>
>> Similar problem with read_attribute_mem
>>
>> Fixes: 0f0b270f905b ("[media] ngene: CXD2099AR Common Interface driver")
>>
>> Signed-off-by: Tom Rix <trix@redhat.com>
>> ---
>>  drivers/media/dvb-frontends/cxd2099.c | 14 ++++++++++----
>>  1 file changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/media/dvb-frontends/cxd2099.c b/drivers/media/dvb-frontends/cxd2099.c
>> index f88b5355493e..9dfaf18fc4b4 100644
>> --- a/drivers/media/dvb-frontends/cxd2099.c
>> +++ b/drivers/media/dvb-frontends/cxd2099.c
>> @@ -387,12 +387,15 @@ static int read_attribute_mem(struct dvb_ca_en50221 *ca,
>>  {
>>  	struct cxd *ci = ca->data;
>>  	u8 val;
>> +	int ret;
>>  
>>  	mutex_lock(&ci->lock);
>>  	set_mode(ci, 1);
>> -	read_pccard(ci, address, &val, 1);
>> +	ret = read_pccard(ci, address, &val, 1);
>> +	if (!ret)
>> +		ret = val;
>>  	mutex_unlock(&ci->lock);
>> -	return val;
>> +	return ret;
>>  }
>>  
>>  static int write_attribute_mem(struct dvb_ca_en50221 *ca, int slot,
>> @@ -412,12 +415,15 @@ static int read_cam_control(struct dvb_ca_en50221 *ca,
>>  {
>>  	struct cxd *ci = ca->data;
>>  	unsigned int val;
>> +	int ret;
>>  
>>  	mutex_lock(&ci->lock);
>>  	set_mode(ci, 0);
>> -	read_io(ci, address, &val);
>> +	ret = read_io(ci, address, &val);
>> +	if (!ret)
>> +		ret = val;
>>  	mutex_unlock(&ci->lock);
>> -	return val;
>> +	return ret;
>>  }
>>  
>>  static int write_cam_control(struct dvb_ca_en50221 *ca, int slot,
> Hmm... Had you test this one on a real hardware? It is not
> uncommon to have some DVB devices that would fail reading
> when the firmware is on cold state.
>
> Without testing a patch like that at a real hardware, there's
> no way to know if this is intentional or if the original
> developer forgot to add a check for the error.

No, I do not have hw.  I understand your concerns, it is ok if you want to drop this patch, else i'll beef up the warnings.

Tom

>
> So, at most, it could print some warning message for
> non-zero return codes.
>
>
> Thanks,
> Mauro
>


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

end of thread, other threads:[~2020-09-03 14:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22 13:41 [PATCH] media: dvb-frontends/cxd2099: report errors trix
2020-09-03 14:13 ` Mauro Carvalho Chehab
2020-09-03 14:41   ` Tom Rix

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.