Skip to contentSkip to conversation

media: dvb-usb-v2: lmedm04: Improve logic checking of warm start.

PATCH In review Malcolm Priestley 2 participants 3 messages Sep 26, 2017 – Sep 27, 2017

Subsystems (2)
lore
Share & tools
lore

Malcolm Priestley

author maintainer
#0 lore raw

PATCH 1/2 media: dvb-usb-v2: lmedm04: Improve logic checking of warm start.

Warm start has no check as whether a genuine device has connected and proceeds to next execution path.

Check device should read 0x47 at offset of 2 on USB descriptor read and it is the amount requested of 6 bytes.

Fix for
kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access as

---
 drivers/media/usb/dvb-usb-v2/lmedm04.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/media/usb/dvb-usb-v2/lmedm04.c +18 -8
index 5e320fa4a795..992f2011a6ba 100644
@@ -494,18 +494,23 @@ static int lme2510_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
 
 static int lme2510_return_status(struct dvb_usb_device *d)
 {
-	int ret = 0;
+	int ret;
 	u8 *data;
 
-	data = kzalloc(10, GFP_KERNEL);
+	data = kzalloc(6, GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
-	ret |= usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
-			0x06, 0x80, 0x0302, 0x00, data, 0x0006, 200);
-	info("Firmware Status: %x (%x)", ret , data[2]);
+	ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
+			      0x06, 0x80, 0x0302, 0x00,
+			      data, 0x6, 200);
+	if (ret != 6)
+		ret = -EINVAL;
+	else
+		ret = data[2];
+
+	info("Firmware Status: %6ph", data);
 
-	ret = (ret < 0) ? -ENODEV : data[2];
 	kfree(data);
 	return ret;
 }
@@ -1189,6 +1194,7 @@ static int lme2510_get_adapter_count(struct dvb_usb_device *d)
 static int lme2510_identify_state(struct dvb_usb_device *d, const char **name)
 {
 	struct lme2510_state *st = d->priv;
+	int status;
 
 	usb_reset_configuration(d->udev);
 
@@ -1197,12 +1203,16 @@ static int lme2510_identify_state(struct dvb_usb_device *d, const char **name)
 
 	st->dvb_usb_lme2510_firmware = dvb_usb_lme2510_firmware;
 
-	if (lme2510_return_status(d) == 0x44) {
+	status = lme2510_return_status(d);
+	if (status == 0x44) {
 		*name = lme_firmware_switch(d, 0);
 		return COLD;
 	}
 
-	return 0;
+	if (status != 0x47)
+		return -EINVAL;
+
+	return WARM;
 }
 
 static int lme2510_get_stream_config(struct dvb_frontend *fe, u8 *ts_type,
Signature · 1 line
2.14.1
author maintainer
#1 lore raw

PATCH 2/2 media: dvb-usb-v2: lmedm04: move ts2020 attach to dm04_lme2510_tuner

When the tuner was split from m88rs2000 the attach function is in wrong place.

Move to dm04_lme2510_tuner to trap errors on failure and removing a call to lme_coldreset.

Prevents driver starting up without any tuner connected.

Fixes to trap for ts2020 fail.
LME2510(C): FE Found M88RS2000
ts2020: probe of 0-0060 failed with error -11
...
LME2510(C): TUN Found RS2000 tuner
kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access

general protection fault: 0000 [#1] PREEMPT SMP KASAN
---
 drivers/media/usb/dvb-usb-v2/lmedm04.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/media/usb/dvb-usb-v2/lmedm04.c +6 -7
index 992f2011a6ba..be26c029546b 100644
@@ -1076,8 +1076,6 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
 
 		if (adap->fe[0]) {
 			info("FE Found M88RS2000");
-			dvb_attach(ts2020_attach, adap->fe[0], &ts2020_config,
-					&d->i2c_adap);
 			st->i2c_tuner_gate_w = 5;
 			st->i2c_tuner_gate_r = 5;
 			st->i2c_tuner_addr = 0x60;
@@ -1143,17 +1141,18 @@ static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap)
 			ret = st->tuner_config;
 		break;
 	case TUNER_RS2000:
-		ret = st->tuner_config;
+		if (dvb_attach(ts2020_attach, adap->fe[0],
+			       &ts2020_config, &d->i2c_adap))
+			ret = st->tuner_config;
 		break;
 	default:
 		break;
 	}
 
-	if (ret)
+	if (ret) {
 		info("TUN Found %s tuner", tun_msg[ret]);
-	else {
-		info("TUN No tuner found --- resetting device");
-		lme_coldreset(d);
+	} else {
+		info("TUN No tuner found");
 		return -ENODEV;
 	}
 
Signature · 1 line
2.14.1
Tested-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] media: dvb-usb-v2: lmedm04: move ts2020 attach to dm04_lme2510_tuner

Quoted 15 lines · Malcolm Priestley

When the tuner was split from m88rs2000 the attach function is in wrong place.

Move to dm04_lme2510_tuner to trap errors on failure and removing a call to lme_coldreset.

Prevents driver starting up without any tuner connected.

Fixes to trap for ts2020 fail.
LME2510(C): FE Found M88RS2000
ts2020: probe of 0-0060 failed with error -11
...
LME2510(C): TUN Found RS2000 tuner
kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access

Quoted 4 lines
general protection fault: 0000 [#1] PREEMPT SMP KASAN

These 2 patches fix the crash with the reproducer that I have.

Thanks!

Quoted 44 lines
---
 drivers/media/usb/dvb-usb-v2/lmedm04.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/media/usb/dvb-usb-v2/lmedm04.c +6 -8
index 992f2011a6ba..be26c029546b 100644
@@ -1076,8 +1076,6 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
 
                if (adap->fe[0]) {
                        info("FE Found M88RS2000");
-                       dvb_attach(ts2020_attach, adap->fe[0], &ts2020_config,
-                                       &d->i2c_adap);
                        st->i2c_tuner_gate_w = 5;
                        st->i2c_tuner_gate_r = 5;
                        st->i2c_tuner_addr = 0x60;
@@ -1143,17 +1141,18 @@ static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap)
                        ret = st->tuner_config;
                break;
        case TUNER_RS2000:
-               ret = st->tuner_config;
+               if (dvb_attach(ts2020_attach, adap->fe[0],
+                              &ts2020_config, &d->i2c_adap))
+                       ret = st->tuner_config;
                break;
        default:
                break;
        }
 
-       if (ret)
+       if (ret) {
                info("TUN Found %s tuner", tun_msg[ret]);
-       else {
-               info("TUN No tuner found --- resetting device");
-               lme_coldreset(d);
+       } else {
+               info("TUN No tuner found");
                return -ENODEV;
        }
 
--

2.14.1