Skip to contentSkip to conversation

media: tuners: tda18271: fix error code handling in tda18271_attach()

PATCH In review Roman Smirnov 3 participants 8 messages Apr 16, 2024 – Apr 24, 2024

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

PATCH 1/3 media: tuners: tda18271: fix error code handling in tda18271_attach()

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()")
---
 drivers/media/tuners/tda18271-fe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/tuners/tda18271-fe.c +1 -1
index a7e721baaa99..23432210f06a 100644
@@ -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 */
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/3 media: tuners: xc5000: fix error code handling in xc5000_attach()

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()")
---
 drivers/media/tuners/xc5000.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/tuners/xc5000.c +1 -1
index 2182e5b7b606..6e47edee8ac3 100644
@@ -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 */
Signature · 1 line
2.34.1
Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] media: tuners: xc5000: fix error code handling in xc5000_attach()

Quoted 2 lines · Roman Smirnov

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

Quoted 6 lines

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

[...]

MBR, Sergey

#3 lore raw

PATCH 3/3 media: tuners: tuner_simple: fix error code handling in simple_tuner_attach()

In reply to Roman Smirnov

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()")
---
 drivers/media/tuners/tuner-simple.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/tuners/tuner-simple.c +1 -1
index 8fb186b25d6a..713ce2455910 100644
@@ -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:
Signature · 1 line
2.34.1
Reviewed-by on v1 3/3
#4 lore raw

Re: [PATCH 3/3] media: tuners: tuner_simple: fix error code handling in simple_tuner_attach()

Hello!

Should have been "tuner-simple:" in the subject... :-)

Quoted 8 lines · Roman Smirnov

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

[...]

MBR, Sergey

Reviewed-by on v1 1/3
#5 lore raw
In reply to Roman Smirnov
Quoted 8 lines · Roman Smirnov

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

[...]

MBR, Sergey

#6 lore raw
In reply to Roman Smirnov

Hello Roman,

Quoted 3 lines · Roman Smirnov

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.

Quoted 25 lines

Found by Linux Verification Center (linuxtesting.org) with Svace.

Fixes b9302fa7ed97 ("media: tuners: fix error return code of hybrid_tuner_request_state()")
---
 drivers/media/tuners/tda18271-fe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/tuners/tda18271-fe.c +1 -1
index a7e721baaa99..23432210f06a 100644
@@ -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 */
Signature · 1 line
2.34.1
#7 lore raw
Quoted 13 lines · Fedor Pchelkin

Hello Roman,

Quoted 3 lines · Roman Smirnov

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

Quoted 11 lines

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.

Quoted 4 lines

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.

Quoted 21 lines
Quoted 21 lines
---
 drivers/media/tuners/tda18271-fe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/tuners/tda18271-fe.c +1 -1
index a7e721baaa99..23432210f06a 100644
@@ -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 */
Signature · 1 line
2.34.1