Skip to contentSkip to conversation

media: dvb-frontends/cxd2099: report errors

PATCH In review [email protected] 2 participants 3 messages Jul 22, 2020 – Sep 3, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: dvb-frontends/cxd2099: report errors

From: Tom Rix <[email protected]>

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")
---
 drivers/media/dvb-frontends/cxd2099.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/media/dvb-frontends/cxd2099.c +10 -4
index f88b5355493e..9dfaf18fc4b4 100644
@@ -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,
Signature · 1 line
2.18.1
#1 lore raw

Em Wed, 22 Jul 2020 06:41:26 -0700
[email protected] escreveu:

Quoted 54 lines

From: Tom Rix <[email protected]>

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")
---
 drivers/media/dvb-frontends/cxd2099.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/media/dvb-frontends/cxd2099.c +6 -2
index f88b5355493e..9dfaf18fc4b4 100644
@@ -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);

drivers/media/dvb-frontends/cxd2099.c static int read_cam_control(struct dvb_ca_en50221 *ca, · line 429

Quoted 10 lines
drivers/media/dvb-frontends/cxd2099.c +4 -2
-	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

author
#2 lore raw
Quoted 66 lines · Mauro Carvalho Chehab

Em Wed, 22 Jul 2020 06:41:26 -0700
[email protected] escreveu:

Quoted 63 lines

From: Tom Rix <[email protected]>

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")
---
 drivers/media/dvb-frontends/cxd2099.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/media/dvb-frontends/cxd2099.c +10 -4
index f88b5355493e..9dfaf18fc4b4 100644
@@ -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;
 }
 
Quoted 8 lines

drivers/media/dvb-frontends/cxd2099.c static int read_cam_control(struct dvb_ca_en50221 *ca, · line 429

Quoted 1 line
drivers/media/dvb-frontends/cxd2099.c +0 -0
 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

Quoted 8 lines

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

Thanks,
Mauro