Skip to contentSkip to conversation

media: pvrusb2: fix parsing error

PATCH Superseded Tong Zhang 3 participants 9 messages Aug 16, 2020 – Aug 20, 2020

Subsystems (2)
lore
Share & tools
lore

Tong Zhang

author
#0 lore raw

PATCH 1/1 media: pvrusb2: fix parsing error

pvr2_std_str_to_id() returns 0 on failure and 1 on success, however the caller is checking failure case using <0

---
 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +2 -1
index 1cfb7cf64131..db5aa66c1936 100644
@@ -867,7 +867,8 @@ static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr,
 	int ret;
 	v4l2_std_id id;
 	ret = pvr2_std_str_to_id(&id,bufPtr,bufSize);
-	if (ret < 0) return ret;
+	if (ret == 0)
+		return ret;
 	if (mskp) *mskp = id;
 	if (valp) *valp = id;
 	return 0;
Signature · 1 line
2.25.1
#1 lore raw

Hi Tong,

Quoted 13 lines · Tong Zhang

pvr2_std_str_to_id() returns 0 on failure and 1 on success, however the caller is checking failure case using <0

---
 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -0
index 1cfb7cf64131..db5aa66c1936 100644

drivers/media/usb/pvrusb2/pvrusb2-hdw.c static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr, · line 871

Quoted 6 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +2 -1
@@ -867,7 +867,8 @@ static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr,
 	int ret;
 	v4l2_std_id id;
 	ret = pvr2_std_str_to_id(&id,bufPtr,bufSize);
-	if (ret < 0) return ret;
+	if (ret == 0)
+		return ret;

But now you return 0 instead of an error when pvr2_std_str_to_id failed.

Just do this:

	if (!pvr2_std_str_to_id(&id,bufPtr,bufSize))
		return -EINVAL;

And you can drop the ret variable as well since that's no longer needed.

Regards,

Hans

Quoted 4 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -0
 	if (mskp) *mskp = id;
 	if (valp) *valp = id;
 	return 0;
author
#2 lore raw

Hi Hans,
Thank you very much for your comments.
The change looks good to me.
-- However, I'm not quite familiar with the patch submission process
in this situation.
Would you like to go ahead and create an improved version? Thanks,
- Tong

Quoted 42 lines · Hans Verkuil

Hi Tong,

Quoted 13 lines · Tong Zhang

pvr2_std_str_to_id() returns 0 on failure and 1 on success, however the caller is checking failure case using <0

---
 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -0
index 1cfb7cf64131..db5aa66c1936 100644

drivers/media/usb/pvrusb2/pvrusb2-hdw.c static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr, · line 871

Quoted 6 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +2 -1
@@ -867,7 +867,8 @@ static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr,
      int ret;
      v4l2_std_id id;
      ret = pvr2_std_str_to_id(&id,bufPtr,bufSize);
-     if (ret < 0) return ret;
+     if (ret == 0)
+             return ret;

But now you return 0 instead of an error when pvr2_std_str_to_id failed.

Just do this:

        if (!pvr2_std_str_to_id(&id,bufPtr,bufSize))
                return -EINVAL;

And you can drop the ret variable as well since that's no longer needed.

Regards,

Hans

Quoted 4 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -0
      if (mskp) *mskp = id;
      if (valp) *valp = id;
      return 0;
author
#3 lore raw

PATCH v2 1/1 media: pvrusb2: fix parsing error

In reply to Hans Verkuil

pvr2_std_str_to_id() returns 0 on failure and 1 on success, however the caller is checking failure case using <0

---

v2: return -EINVAL as suggested by Hans Verkuil<[email protected]>. I also rebased the code on v5.9-rc1.

 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +2 -2
index 1cfb7cf64131..6a444cb27e31 100644
@@ -866,8 +866,8 @@ static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr,
 {
 	int ret;
 	v4l2_std_id id;
-	ret = pvr2_std_str_to_id(&id,bufPtr,bufSize);
-	if (ret < 0) return ret;
+	if (!pvr2_std_str_to_id(&id, bufPtr, bufSize))
+		return -EINVAL;
 	if (mskp) *mskp = id;
 	if (valp) *valp = id;
 	return 0;
Signature · 1 line
2.25.1
#4 lore raw
Quoted 18 lines · Tong Zhang

pvr2_std_str_to_id() returns 0 on failure and 1 on success, however the caller is checking failure case using <0

---

v2: return -EINVAL as suggested by Hans Verkuil<[email protected]>. I also rebased the code on v5.9-rc1.

 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -0
index 1cfb7cf64131..6a444cb27e31 100644

drivers/media/usb/pvrusb2/pvrusb2-hdw.c static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr, · line 867

Quoted 2 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -0
@@ -866,8 +866,8 @@ static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr,
 {
 	int ret;

This is no longer used, so can be removed.

And if I compile this patch I get this warning:

drivers/media/usb/pvrusb2/pvrusb2-hdw.c: In function ‘ctrl_std_sym_to_val’:
drivers/media/usb/pvrusb2/pvrusb2-hdw.c:867:6: warning: unused variable ‘ret’ [-Wunused-variable]

  867 |  int ret;
      |      ^~~

Always compile-test before posting a patch :-)

Regards,

Hans

Quoted 9 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +2 -2
 	v4l2_std_id id;
-	ret = pvr2_std_str_to_id(&id,bufPtr,bufSize);
-	if (ret < 0) return ret;
+	if (!pvr2_std_str_to_id(&id, bufPtr, bufSize))
+		return -EINVAL;
 	if (mskp) *mskp = id;
 	if (valp) *valp = id;
 	return 0;
author
#5 lore raw

PATCH v3 1/1 media: pvrusb2: fix parsing error

pvr2_std_str_to_id() returns 0 on failure and 1 on success, however the caller is checking failure case using <0

---

v2: return -EINVAL as suggested by Hans Verkuil<[email protected]>. I also rebased the code on v5.9-rc1.
v3: remove unused variable

 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +2 -3
index 1cfb7cf64131..f4a727918e35 100644
@@ -864,10 +864,9 @@ static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr,
 			       const char *bufPtr,unsigned int bufSize,
 			       int *mskp,int *valp)
 {
-	int ret;
 	v4l2_std_id id;
-	ret = pvr2_std_str_to_id(&id,bufPtr,bufSize);
-	if (ret < 0) return ret;
+	if (!pvr2_std_str_to_id(&id, bufPtr, bufSize))
+		return -EINVAL;
 	if (mskp) *mskp = id;
 	if (valp) *valp = id;
 	return 0;
Signature · 1 line
2.25.1
Acked-by on v3 1/1
#6 lore raw
Quoted 32 lines · Tong Zhang

pvr2_std_str_to_id() returns 0 on failure and 1 on success, however the caller is checking failure case using <0

---

v2: return -EINVAL as suggested by Hans Verkuil<[email protected]>. I also rebased the code on v5.9-rc1.
v3: remove unused variable

 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +2 -3
index 1cfb7cf64131..f4a727918e35 100644
@@ -864,10 +864,9 @@ static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr,
 			       const char *bufPtr,unsigned int bufSize,
 			       int *mskp,int *valp)
 {
-	int ret;
 	v4l2_std_id id;
-	ret = pvr2_std_str_to_id(&id,bufPtr,bufSize);
-	if (ret < 0) return ret;
+	if (!pvr2_std_str_to_id(&id, bufPtr, bufSize))
+		return -EINVAL;
 	if (mskp) *mskp = id;
 	if (valp) *valp = id;
 	return 0;
Signature · 3 lines
Mike Isely
isely @ isely (dot) net
PGP: 03 54 43 4D 75 E5 CC 92 71 16 01 E2 B5 F5 C1 E8
author
#7 lore raw
In reply to Hans Verkuil
Quoted 11 lines · Hans Verkuil

drivers/media/usb/pvrusb2/pvrusb2-hdw.c static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr, · line 867

Quoted 8 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -0
index 1cfb7cf64131..6a444cb27e31 100644
@@ -866,8 +866,8 @@ static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr,
 {
      int ret;

This is no longer used, so can be removed.

Thank you Hans.
I removed the unused variable and did a compilation test for the new patch. Thanks again for being patient guiding me through this. :-)

author
#8 lore raw
In reply to Hans Verkuil

Hi Hans,
I just made another patch as suggested, I think I need some more work on the commit log.
Please take a look and let me know -
Thanks,
- Tong

Quoted 42 lines · Hans Verkuil

Hi Tong,

Quoted 13 lines · Tong Zhang

pvr2_std_str_to_id() returns 0 on failure and 1 on success, however the caller is checking failure case using <0

---
 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -0
index 1cfb7cf64131..db5aa66c1936 100644

drivers/media/usb/pvrusb2/pvrusb2-hdw.c static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr, · line 871

Quoted 6 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +2 -1
@@ -867,7 +867,8 @@ static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr,
      int ret;
      v4l2_std_id id;
      ret = pvr2_std_str_to_id(&id,bufPtr,bufSize);
-     if (ret < 0) return ret;
+     if (ret == 0)
+             return ret;

But now you return 0 instead of an error when pvr2_std_str_to_id failed.

Just do this:

        if (!pvr2_std_str_to_id(&id,bufPtr,bufSize))
                return -EINVAL;

And you can drop the ret variable as well since that's no longer needed.

Regards,

Hans

Quoted 4 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -0
      if (mskp) *mskp = id;
      if (valp) *valp = id;
      return 0;