2020-08-16 08:15:08

by Tong Zhang

[permalink] [raw]
Subject: [PATCH] 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

Signed-off-by: Tong Zhang <[email protected]>
---
drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
index 1cfb7cf64131..db5aa66c1936 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
@@ -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;
--
2.25.1


2020-08-19 14:42:01

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH] media: pvrusb2: fix parsing error

Hi Tong,

On 16/08/2020 08:49, Tong Zhang wrote:
> pvr2_std_str_to_id() returns 0 on failure and 1 on success,
> however the caller is checking failure case using <0
>
> Signed-off-by: Tong Zhang <[email protected]>
> ---
> drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> index 1cfb7cf64131..db5aa66c1936 100644
> --- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> +++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> @@ -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

> if (mskp) *mskp = id;
> if (valp) *valp = id;
> return 0;
>

2020-08-19 16:38:26

by Tong Zhang

[permalink] [raw]
Subject: Re: [PATCH] media: pvrusb2: fix parsing error

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

On Wed, Aug 19, 2020 at 10:38 AM Hans Verkuil <[email protected]> wrote:
>
> Hi Tong,
>
> On 16/08/2020 08:49, Tong Zhang wrote:
> > pvr2_std_str_to_id() returns 0 on failure and 1 on success,
> > however the caller is checking failure case using <0
> >
> > Signed-off-by: Tong Zhang <[email protected]>
> > ---
> > drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> > index 1cfb7cf64131..db5aa66c1936 100644
> > --- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> > +++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> > @@ -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
>
> > if (mskp) *mskp = id;
> > if (valp) *valp = id;
> > return 0;
> >
>

2020-08-19 21:27:02

by Tong Zhang

[permalink] [raw]
Subject: [PATCH v2] 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

Co-developed-by: Hans Verkuil<[email protected]>
Signed-off-by: Tong Zhang <[email protected]>
---

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(-)

diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
index 1cfb7cf64131..6a444cb27e31 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
@@ -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;
--
2.25.1

2020-08-19 21:30:44

by Tong Zhang

[permalink] [raw]
Subject: Re: [PATCH] media: pvrusb2: fix parsing error

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

On Wed, Aug 19, 2020 at 10:38 AM Hans Verkuil <[email protected]> wrote:
>
> Hi Tong,
>
> On 16/08/2020 08:49, Tong Zhang wrote:
> > pvr2_std_str_to_id() returns 0 on failure and 1 on success,
> > however the caller is checking failure case using <0
> >
> > Signed-off-by: Tong Zhang <[email protected]>
> > ---
> > drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> > index 1cfb7cf64131..db5aa66c1936 100644
> > --- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> > +++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> > @@ -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
>
> > if (mskp) *mskp = id;
> > if (valp) *valp = id;
> > return 0;
> >
>

2020-08-20 11:47:41

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH v2] media: pvrusb2: fix parsing error

On 19/08/2020 23:25, Tong Zhang wrote:
> pvr2_std_str_to_id() returns 0 on failure and 1 on success,
> however the caller is checking failure case using <0
>
> Co-developed-by: Hans Verkuil<[email protected]>
> Signed-off-by: Tong Zhang <[email protected]>
> ---
>
> 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(-)
>
> diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> index 1cfb7cf64131..6a444cb27e31 100644
> --- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> +++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> @@ -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

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

2020-08-20 16:58:49

by Tong Zhang

[permalink] [raw]
Subject: [PATCH v3] 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

Co-developed-by: Hans Verkuil<[email protected]>
Signed-off-by: Tong Zhang <[email protected]>
---

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(-)

diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
index 1cfb7cf64131..f4a727918e35 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
@@ -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;
--
2.25.1

2020-08-20 17:01:56

by Mike Isely

[permalink] [raw]
Subject: Re: [PATCH v3] media: pvrusb2: fix parsing error


Acked-by: Mike Isely <[email protected]>

On Thu, 20 Aug 2020, Tong Zhang wrote:

> pvr2_std_str_to_id() returns 0 on failure and 1 on success,
> however the caller is checking failure case using <0
>
> Co-developed-by: Hans Verkuil<[email protected]>
> Signed-off-by: Tong Zhang <[email protected]>
> ---
>
> 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(-)
>
> diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> index 1cfb7cf64131..f4a727918e35 100644
> --- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> +++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> @@ -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;
>

--

Mike Isely
isely @ isely (dot) net
PGP: 03 54 43 4D 75 E5 CC 92 71 16 01 E2 B5 F5 C1 E8

2020-08-20 20:06:03

by Tong Zhang

[permalink] [raw]
Subject: Re: [PATCH v2] media: pvrusb2: fix parsing error

On Thu, Aug 20, 2020 at 7:44 AM Hans Verkuil <[email protected]> wrote:
>
> > diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> > index 1cfb7cf64131..6a444cb27e31 100644
> > --- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> > +++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
> > @@ -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. :-)