* [PATCH 2/3] media: tuners: xc5000: fix error code handling in xc5000_attach()
2024-04-16 11:45 [PATCH 1/3] media: tuners: tda18271: fix error code handling in tda18271_attach() Roman Smirnov
@ 2024-04-16 11:45 ` Roman Smirnov
2024-04-16 18:58 ` Sergey Shtylyov
2024-04-16 11:45 ` [PATCH 3/3] media: tuners: tuner_simple: fix error code handling in simple_tuner_attach() Roman Smirnov
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Roman Smirnov @ 2024-04-16 11:45 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Hans Verkuil, Luis Chamberlain, Jia-Ju Bai
Cc: Roman Smirnov, linux-media, linux-kernel, Sergey Shtylyov,
lvc-project
xc5000_attach() uses the hybrid_tuner_request_state() macro.
It may return the error code -ENOMEM, but the function handle
the value 0 instead.
Found by Linux Verification Center (linuxtesting.org) with Svace.
Fixes: b9302fa7ed97 ("media: tuners: fix error return code of hybrid_tuner_request_state()")
Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
---
drivers/media/tuners/xc5000.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c
index 2182e5b7b606..6e47edee8ac3 100644
--- a/drivers/media/tuners/xc5000.c
+++ b/drivers/media/tuners/xc5000.c
@@ -1379,7 +1379,7 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
hybrid_tuner_instance_list,
i2c, cfg->i2c_address, "xc5000");
switch (instance) {
- case 0:
+ case -ENOMEM:
goto fail;
case 1:
/* new tuner instance */
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 2/3] media: tuners: xc5000: fix error code handling in xc5000_attach()
2024-04-16 11:45 ` [PATCH 2/3] media: tuners: xc5000: fix error code handling in xc5000_attach() Roman Smirnov
@ 2024-04-16 18:58 ` Sergey Shtylyov
0 siblings, 0 replies; 8+ messages in thread
From: Sergey Shtylyov @ 2024-04-16 18:58 UTC (permalink / raw)
To: Roman Smirnov, Mauro Carvalho Chehab, Hans Verkuil,
Luis Chamberlain, Jia-Ju Bai
Cc: linux-media, linux-kernel, lvc-project
On 4/16/24 2:45 PM, Roman Smirnov wrote:
> xc5000_attach() uses the hybrid_tuner_request_state() macro.
> It may return the error code -ENOMEM, but the function handle
Handles (just noticed that grammar issue in all 3 patches).
> the value 0 instead.
>
> Found by Linux Verification Center (linuxtesting.org) with Svace.
>
> Fixes: b9302fa7ed97 ("media: tuners: fix error return code of hybrid_tuner_request_state()")
> Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
[...]
MBR, Sergey
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/3] media: tuners: tuner_simple: fix error code handling in simple_tuner_attach()
2024-04-16 11:45 [PATCH 1/3] media: tuners: tda18271: fix error code handling in tda18271_attach() Roman Smirnov
2024-04-16 11:45 ` [PATCH 2/3] media: tuners: xc5000: fix error code handling in xc5000_attach() Roman Smirnov
@ 2024-04-16 11:45 ` Roman Smirnov
2024-04-16 18:31 ` Sergey Shtylyov
2024-04-16 18:32 ` [PATCH 1/3] media: tuners: tda18271: fix error code handling in tda18271_attach() Sergey Shtylyov
2024-04-24 18:06 ` [lvc-project] " Fedor Pchelkin
3 siblings, 1 reply; 8+ messages in thread
From: Roman Smirnov @ 2024-04-16 11:45 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Hans Verkuil, Jia-Ju Bai
Cc: Roman Smirnov, linux-media, linux-kernel, Sergey Shtylyov,
lvc-project
simple_tuner_attach() uses the hybrid_tuner_request_state() macro.
It may return the error code -ENOMEM, but the function handle
the value 0 instead.
Found by Linux Verification Center (linuxtesting.org) with Svace.
Fixes: b9302fa7ed97 ("media: tuners: fix error return code of hybrid_tuner_request_state()")
Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
---
drivers/media/tuners/tuner-simple.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/tuners/tuner-simple.c b/drivers/media/tuners/tuner-simple.c
index 8fb186b25d6a..713ce2455910 100644
--- a/drivers/media/tuners/tuner-simple.c
+++ b/drivers/media/tuners/tuner-simple.c
@@ -1089,7 +1089,7 @@ struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
i2c_adap, i2c_addr,
"tuner-simple");
switch (instance) {
- case 0:
+ case -ENOMEM:
mutex_unlock(&tuner_simple_list_mutex);
return NULL;
case 1:
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 1/3] media: tuners: tda18271: fix error code handling in tda18271_attach()
2024-04-16 11:45 [PATCH 1/3] media: tuners: tda18271: fix error code handling in tda18271_attach() Roman Smirnov
2024-04-16 11:45 ` [PATCH 2/3] media: tuners: xc5000: fix error code handling in xc5000_attach() Roman Smirnov
2024-04-16 11:45 ` [PATCH 3/3] media: tuners: tuner_simple: fix error code handling in simple_tuner_attach() Roman Smirnov
@ 2024-04-16 18:32 ` Sergey Shtylyov
2024-04-24 18:06 ` [lvc-project] " Fedor Pchelkin
3 siblings, 0 replies; 8+ messages in thread
From: Sergey Shtylyov @ 2024-04-16 18:32 UTC (permalink / raw)
To: Roman Smirnov, Michael Krufky, Mauro Carvalho Chehab, Jia-Ju Bai,
Hans Verkuil
Cc: linux-media, linux-kernel, lvc-project
On 4/16/24 2:45 PM, Roman Smirnov wrote:
> tda18271_attach() uses the hybrid_tuner_request_state() macro.
> It may return the error code -ENOMEM, but the function handle
> the value 0 instead.
>
> Found by Linux Verification Center (linuxtesting.org) with Svace.
>
> Fixes: b9302fa7ed97 ("media: tuners: fix error return code of hybrid_tuner_request_state()")
> Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
[...]
MBR, Sergey
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [lvc-project] [PATCH 1/3] media: tuners: tda18271: fix error code handling in tda18271_attach()
2024-04-16 11:45 [PATCH 1/3] media: tuners: tda18271: fix error code handling in tda18271_attach() Roman Smirnov
` (2 preceding siblings ...)
2024-04-16 18:32 ` [PATCH 1/3] media: tuners: tda18271: fix error code handling in tda18271_attach() Sergey Shtylyov
@ 2024-04-24 18:06 ` Fedor Pchelkin
2024-04-24 20:20 ` Fedor Pchelkin
3 siblings, 1 reply; 8+ messages in thread
From: Fedor Pchelkin @ 2024-04-24 18:06 UTC (permalink / raw)
To: Roman Smirnov
Cc: Michael Krufky, Mauro Carvalho Chehab, Jia-Ju Bai, Hans Verkuil,
lvc-project, Sergey Shtylyov, linux-media, linux-kernel
Hello Roman,
On Tue, 16. Apr 14:45, Roman Smirnov wrote:
> tda18271_attach() uses the hybrid_tuner_request_state() macro.
> It may return the error code -ENOMEM, but the function handle
> the value 0 instead.
Maybe hybrid_tuner_request_state macro declaration should be fixed to
generate zero in case of a memory allocation failure?
At least it has a comment stating the following
* 0 - no instances, indicates an error - kzalloc must have failed
And supposedly a number of drivers implemented the error handling based on
this assumption.
The drivers mentioned in this series are not the only ones susceptible to
the problem. Grepping through "hybrid_tuner_request_state" calls also gives
out tda9887, xc2028, r820t and others.
>
> Found by Linux Verification Center (linuxtesting.org) with Svace.
>
> Fixes: b9302fa7ed97 ("media: tuners: fix error return code of hybrid_tuner_request_state()")
> Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
> ---
> drivers/media/tuners/tda18271-fe.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/tuners/tda18271-fe.c b/drivers/media/tuners/tda18271-fe.c
> index a7e721baaa99..23432210f06a 100644
> --- a/drivers/media/tuners/tda18271-fe.c
> +++ b/drivers/media/tuners/tda18271-fe.c
> @@ -1255,7 +1255,7 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
> hybrid_tuner_instance_list,
> i2c, addr, "tda18271");
> switch (instance) {
> - case 0:
> + case -ENOMEM:
> goto fail;
> case 1:
> /* new tuner instance */
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [lvc-project] [PATCH 1/3] media: tuners: tda18271: fix error code handling in tda18271_attach()
2024-04-24 18:06 ` [lvc-project] " Fedor Pchelkin
@ 2024-04-24 20:20 ` Fedor Pchelkin
0 siblings, 0 replies; 8+ messages in thread
From: Fedor Pchelkin @ 2024-04-24 20:20 UTC (permalink / raw)
To: Roman Smirnov
Cc: Michael Krufky, Mauro Carvalho Chehab, Jia-Ju Bai, Hans Verkuil,
lvc-project, Sergey Shtylyov, linux-media, linux-kernel
On Wed, 24. Apr 21:06, Fedor Pchelkin wrote:
> Hello Roman,
>
> On Tue, 16. Apr 14:45, Roman Smirnov wrote:
> > tda18271_attach() uses the hybrid_tuner_request_state() macro.
> > It may return the error code -ENOMEM, but the function handle
> > the value 0 instead.
>
> Maybe hybrid_tuner_request_state macro declaration should be fixed to
> generate zero in case of a memory allocation failure?
>
> At least it has a comment stating the following
> * 0 - no instances, indicates an error - kzalloc must have failed
>
> And supposedly a number of drivers implemented the error handling based on
> this assumption.
>
> The drivers mentioned in this series are not the only ones susceptible to
> the problem. Grepping through "hybrid_tuner_request_state" calls also gives
> out tda9887, xc2028, r820t and others.
>
> >
> > Found by Linux Verification Center (linuxtesting.org) with Svace.
> >
> > Fixes: b9302fa7ed97 ("media: tuners: fix error return code of hybrid_tuner_request_state()")
Looking more thoroughly, I think commit b9302fa7ed97 ("media: tuners: fix
error return code of hybrid_tuner_request_state()") should be reverted
because it just contradicts with the return values contract which is stated
in the comment for the macro and which is followed by all the existing
drivers.
__ret should be assigned 0 in error case as was before the commit.
> > Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
> > ---
> > drivers/media/tuners/tda18271-fe.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/media/tuners/tda18271-fe.c b/drivers/media/tuners/tda18271-fe.c
> > index a7e721baaa99..23432210f06a 100644
> > --- a/drivers/media/tuners/tda18271-fe.c
> > +++ b/drivers/media/tuners/tda18271-fe.c
> > @@ -1255,7 +1255,7 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
> > hybrid_tuner_instance_list,
> > i2c, addr, "tda18271");
> > switch (instance) {
> > - case 0:
> > + case -ENOMEM:
> > goto fail;
> > case 1:
> > /* new tuner instance */
> > --
> > 2.34.1
> >
^ permalink raw reply [flat|nested] 8+ messages in thread