Skip to contentSkip to conversation

vp702x

PATCH Superseded Florian Mickler 3 participants 8 messages Aug 2, 2011 – Sep 4, 2011 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

Hi Mauro! Hi Patrick!

I realized this morning, that I broke vp702x (if it was working before) with my last patchseries. Sorry. :(

I'm gonna follow up on this mail with a patch to hopefully fix it, but if nobody can test it, I'd say to rather revert my patchseries for v3.1 . It will then still use on-stack dma buffers and will produce a WARN() in the dmesg if it does so, but hopefully nothing bad happens.

Patrick, do you still have the hardware to test this? I'm semi confident that I did not make any silly mistakes. :| (it compiles)

Regards,
Flo

p.s.: or I could wipe up a dead simple patch that just kmalloc's a new buffer everytime we need one...

#1 lore raw

PATCH 1/1 vp702x: fix buffer handling

In my previous change to this driver, I was not aware that dvb_usb_device_init calls the frontend_attach routine which needs a transfer
buffer. So we can not setup anything private in the probe routine beforehand but have to allocate when needed. This means also that we cannot use a private buffer mutex to serialize that buffer but instead need to use the dvb_usb_device's usb_mutex.

Note: Compile tested only!

---
 drivers/media/dvb/dvb-usb/vp702x-fe.c |   30 ++++-
 drivers/media/dvb/dvb-usb/vp702x.c    |  220 ++++++++++++++++++---------------
 drivers/media/dvb/dvb-usb/vp702x.h    |    8 +-
 3 files changed, 150 insertions(+), 108 deletions(-)
drivers/media/dvb/dvb-usb/vp702x-fe.c +23 -7
index 2bb8d4c..d9eff02 100644
@@ -43,21 +43,30 @@ static int vp702x_fe_refresh_state(struct vp702x_fe_state *st)
 {
 	struct vp702x_device_state *dst = st->d->priv;
 	u8 *buf;
+	int ret;
 
 	if (time_after(jiffies, st->next_status_check)) {
-		mutex_lock(&dst->buf_mutex);
-		buf = dst->buf;
+		ret = mutex_lock_interruptible(&st->d->usb_mutex);
+		if (ret < 0)
+			return ret;
 
-		vp702x_usb_in_op(st->d, READ_STATUS, 0, 0, buf, 10);
+		ret = vp702x_buffer_setup(dst, &buf, 10);
+		if (ret)
+			goto unlock;
+
+		vp702x_usb_in_op_unlocked(st->d, READ_STATUS, 0, 0, buf, 10);
 		st->lock = buf[4];
 
-		vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x11, 0, buf, 1);
+		vp702x_usb_in_op_unlocked(st->d, READ_TUNER_REG_REQ, 0x11, 0,
+				buf, 1);
 		st->snr = buf[0];
 
-		vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x15, 0, buf, 1);
+		vp702x_usb_in_op_unlocked(st->d, READ_TUNER_REG_REQ, 0x15, 0,
+				buf, 1);
 		st->sig = buf[0];
 
-		mutex_unlock(&dst->buf_mutex);
+unlock:
+		mutex_unlock(&st->d->usb_mutex);
 		st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
 	}
 	return 0;
@@ -200,8 +209,15 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe,
 static int vp702x_fe_init(struct dvb_frontend *fe)
 {
 	struct vp702x_fe_state *st = fe->demodulator_priv;
+	int ret;
+
 	deb_fe("%s\n",__func__);
-	vp702x_usb_in_op(st->d, RESET_TUNER, 0, 0, NULL, 0);
+	ret = mutex_lock_interruptible(&st->d->usb_mutex);
+	if (ret < 0)
+		return ret;
+	vp702x_usb_in_op_unlocked(st->d, RESET_TUNER, 0, 0, NULL, 0);
+
+	mutex_unlock(&st->d->usb_mutex);
 	return 0;
 }
 
drivers/media/dvb/dvb-usb/vp702x.c +121 -99

367 lines not on this page · raw message

drivers/media/dvb/dvb-usb/vp702x.h +6 -2
index 20b9005..25d5616 100644
@@ -107,7 +107,11 @@ struct vp702x_device_state {
 
 extern struct dvb_frontend * vp702x_fe_attach(struct dvb_usb_device *d);
 
-extern int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int ilen, int msec);
-extern int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen);
+extern int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i,
+		int ilen, int msec);
+extern int vp702x_usb_in_op_unlocked(struct dvb_usb_device *d, u8 req,
+		u16 value, u16 index, u8 *b, int blen);
+extern int vp702x_buffer_setup(struct vp702x_device_state *st, u8 **buf,
+		int len);
 
 #endif
Signature · 1 line
1.7.6
#2 lore raw

PATCH v2 1/1 vp702x: fix buffer handling

In my previous change to this driver, I was not aware, that dvb_usb_device_init calls the frontend_attach routine which needs a transfer
buffer. So we can not setup anything private in the probe routine beforehand but have to allocate when needed. This means also that we cannot use a private buffer mutex to serialize that buffer but instead need to use the dvb_usb_device's usb_mutex.

---

So, someone who could test that driver found me after all.

I renamed the functions to get rid of that ugly and pointless _unlocked suffix I deliriously added earlier. Markus tested this patch modulo function renaming. I am so shure that this version will still work for him, that I already added his Tested-by. *fingerscrossed*

 drivers/media/dvb/dvb-usb/vp702x-fe.c |   92 +++++++++++----
 drivers/media/dvb/dvb-usb/vp702x.c    |  211 ++++++++++++++++++---------------
 drivers/media/dvb/dvb-usb/vp702x.h    |   13 ++-
 3 files changed, 193 insertions(+), 123 deletions(-)
drivers/media/dvb/dvb-usb/vp702x-fe.c +67 -25
index 2bb8d4c..ad16455 100644
@@ -43,21 +43,30 @@ static int vp702x_fe_refresh_state(struct vp702x_fe_state *st)
 {
 	struct vp702x_device_state *dst = st->d->priv;
 	u8 *buf;
+	int ret;
 
 	if (time_after(jiffies, st->next_status_check)) {
-		mutex_lock(&dst->buf_mutex);
-		buf = dst->buf;
+		ret = mutex_lock_interruptible(&st->d->usb_mutex);
+		if (ret < 0)
+			return ret;
+
+		ret = vp702x_buffer_setup(dst, &buf, 10);
+		if (ret)
+			goto unlock;
 
 		vp702x_usb_in_op(st->d, READ_STATUS, 0, 0, buf, 10);
 		st->lock = buf[4];
 
-		vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x11, 0, buf, 1);
+		vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x11, 0,
+				buf, 1);
 		st->snr = buf[0];
 
-		vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x15, 0, buf, 1);
+		vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x15, 0,
+				buf, 1);
 		st->sig = buf[0];
 
-		mutex_unlock(&dst->buf_mutex);
+unlock:
+		mutex_unlock(&st->d->usb_mutex);
 		st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
 	}
 	return 0;
@@ -145,11 +154,15 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe,
 /*	u16 frequencyRef[16] = { 2, 4, 8, 16, 32, 64, 128, 256, 24, 5, 10, 20, 40, 80, 160, 320 }; */
 	u64 sr;
 	u8 *cmd;
+	int ret;
 
-	mutex_lock(&dst->buf_mutex);
+	ret = mutex_lock_interruptible(&st->d->usb_mutex);
+	if (ret < 0)
+		return ret;
 
-	cmd = dst->buf;
-	memset(cmd, 0, 10);
+	ret = vp702x_buffer_setup(dst, &cmd, 10);
+	if (ret)
+		goto unlock;
 
 	cmd[0] = (freq >> 8) & 0x7f;
 	cmd[1] =  freq       & 0xff;
@@ -191,17 +204,25 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe,
 		deb_fe("tuning failed.\n");
 	else
 		deb_fe("tuning succeeded.\n");
+	ret = 0;
 
-	mutex_unlock(&dst->buf_mutex);
-
-	return 0;
+unlock:
+	mutex_unlock(&st->d->usb_mutex);
+	return ret;
 }
 
 static int vp702x_fe_init(struct dvb_frontend *fe)
 {
 	struct vp702x_fe_state *st = fe->demodulator_priv;
+	int ret;
+
 	deb_fe("%s\n",__func__);
+	ret = mutex_lock_interruptible(&st->d->usb_mutex);
+	if (ret < 0)
+		return ret;
 	vp702x_usb_in_op(st->d, RESET_TUNER, 0, 0, NULL, 0);
+
+	mutex_unlock(&st->d->usb_mutex);
 	return 0;
 }
 
@@ -224,15 +245,21 @@ static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe,
 	u8 *cmd;
 	struct vp702x_fe_state *st = fe->demodulator_priv;
 	struct vp702x_device_state *dst = st->d->priv;
+	int ret;
 
 	deb_fe("%s\n",__func__);
 
 	if (m->msg_len > 4)
 		return -EINVAL;
 
-	mutex_lock(&dst->buf_mutex);
+	ret = mutex_lock_interruptible(&st->d->usb_mutex);
+	if (ret < 0)
+		return ret;
+
+	ret = vp702x_buffer_setup(dst, &cmd, 10);
+	if (ret)
+		goto unlock;
 
-	cmd = dst->buf;
 	cmd[1] = SET_DISEQC_CMD;
 	cmd[2] = m->msg_len;
 	memcpy(&cmd[3], m->msg, m->msg_len);
@@ -244,10 +271,12 @@ static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe,
 		deb_fe("diseqc cmd failed.\n");
 	else
 		deb_fe("diseqc cmd succeeded.\n");
+	ret = 0;
 
-	mutex_unlock(&dst->buf_mutex);
+unlock:
+	mutex_unlock(&st->d->usb_mutex);
 
-	return 0;
+	return ret;
 }
 
 static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
@@ -261,6 +290,7 @@ static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
 	struct vp702x_fe_state *st = fe->demodulator_priv;
 	struct vp702x_device_state *dst = st->d->priv;
 	u8 *buf;
+	int ret;
 
 	deb_fe("%s\n",__func__);
 
@@ -273,9 +303,14 @@ static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
 
 	st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7);
 
-	mutex_lock(&dst->buf_mutex);
+	ret = mutex_lock_interruptible(&st->d->usb_mutex);
+	if (ret < 0)
+		return ret;
+
+	ret = vp702x_buffer_setup(dst, &buf, 10);
+	if (ret)
+		goto unlock;
 
-	buf = dst->buf;
 	memcpy(buf, st->lnb_buf, 8);
 
 	vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100);
@@ -283,10 +318,11 @@ static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
 		deb_fe("set_tone cmd failed.\n");
 	else
 		deb_fe("set_tone cmd succeeded.\n");
+	ret = 0;
+unlock:
+	mutex_unlock(&st->d->usb_mutex);
 
-	mutex_unlock(&dst->buf_mutex);
-
-	return 0;
+	return ret;
 }
 
 static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t
@@ -295,6 +331,7 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t
 	struct vp702x_fe_state *st = fe->demodulator_priv;
 	struct vp702x_device_state *dst = st->d->priv;
 	u8 *buf;
+	int ret;
 	deb_fe("%s\n",__func__);
 
 	st->voltage = voltage;
@@ -306,9 +343,13 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t
 
 	st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7);
 
-	mutex_lock(&dst->buf_mutex);
+	ret = mutex_lock_interruptible(&st->d->usb_mutex);
+	if (ret < 0)
+		return ret;
+	ret = vp702x_buffer_setup(dst, &buf, 10);
+	if (ret)
+		goto unlock;
 
-	buf = dst->buf;
 	memcpy(buf, st->lnb_buf, 8);
 
 	vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100);
@@ -316,9 +357,10 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t
 		deb_fe("set_voltage cmd failed.\n");
 	else
 		deb_fe("set_voltage cmd succeeded.\n");
-
-	mutex_unlock(&dst->buf_mutex);
-	return 0;
+	ret = 0;
+unlock:
+	mutex_unlock(&st->d->usb_mutex);
+	return ret;
 }
 
 static void vp702x_fe_release(struct dvb_frontend* fe)
drivers/media/dvb/dvb-usb/vp702x.c +116 -95

359 lines not on this page · raw message

drivers/media/dvb/dvb-usb/vp702x.h +10 -3
index 20b9005..f7a39d6 100644
@@ -99,7 +99,10 @@ extern int dvb_usb_vp702x_debug;
 /* IN  i: 0, v: 0, no extra buffer */
 
 struct vp702x_device_state {
-	struct mutex buf_mutex;
+	/*
+	 * access to these has to be protected by
+	 * dvb_usb_device.usb_mutex
+	 */
 	int buf_len;
 	u8 *buf;
 };
@@ -107,7 +110,11 @@ struct vp702x_device_state {
 
 extern struct dvb_frontend * vp702x_fe_attach(struct dvb_usb_device *d);
 
-extern int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int ilen, int msec);
-extern int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen);
+extern int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i,
+		int ilen, int msec);
+extern int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req,
+		u16 value, u16 index, u8 *b, int blen);
+extern int vp702x_buffer_setup(struct vp702x_device_state *st, u8 **buf,
+		int len);
 
 #endif
Signature · 1 line
1.7.6
#3 lore raw

Re: [PATCH v2] [media] vp702x: fix buffer handling

Quoted 11 lines · On Fri, 26 Aug 2011 00:11:15 +0200 Florian Mickler <[email protected]> wrote:

In my previous change to this driver, I was not aware, that dvb_usb_device_init calls the frontend_attach routine which needs a transfer
buffer. So we can not setup anything private in the probe routine beforehand but have to allocate when needed. This means also that we cannot use a private buffer mutex to serialize that buffer but instead need to use the dvb_usb_device's usb_mutex.

Quoted 8 lines

---

So, someone who could test that driver found me after all.

I renamed the functions to get rid of that ugly and pointless _unlocked suffix I deliriously added earlier. Markus tested this patch modulo function renaming. I am so shure that this version will still work for him, that I already added his Tested-by. *fingerscrossed*

Hi Mauro!
I just checked patchwork and in case you hold off on this because of my *fingerscrossed* remark above: Markus reported off-list that this version still works for him.

Regards,
Flo

#4 lore raw
In reply to Florian Mickler

Hi Florian,

Quoted 5 lines · Florian Mickler

Hi Mauro! Hi Patrick!

I realized this morning, that I broke vp702x (if it was working before) with my last patchseries. Sorry. :(

Quoted 8 lines

I'm gonna follow up on this mail with a patch to hopefully fix it, but if nobody can test it, I'd say to rather revert my patchseries for v3.1 . It will then still use on-stack dma buffers and will produce a WARN() in the dmesg if it does so, but hopefully nothing bad happens.

Patrick, do you still have the hardware to test this? I'm semi confident that I did not make any silly mistakes. :| (it compiles)

I'm not sure whether I still have exactly this box. There were two versions and I got rid of at least one of them.

I moved recently into a new house and right now a lot of things are hidden in some boxes somewhere... I'll try to find some time to check it. Don't ask me when that will be :).

regards,
--

Patrick Boettcher - Kernel Labs
http://www.kernellabs.com/

#5 lore raw

Hi,

Quoted 10 lines · On Wed, 3 Aug 2011 09:39:46 +0200 (CEST) Patrick Boettcher…

Hi Florian,

I'm not sure whether I still have exactly this box. There were two versions and I got rid of at least one of them.

I moved recently into a new house and right now a lot of things are hidden in some boxes somewhere... I'll try to find some time to check it. Don't ask me when that will be :).

ok, thanks for the heads up nonetheless.

Mauro, what to do? Currently it will bug on
driver probe like the vp7045 (which Tino confirmed works now again with my recent patch).

Before the patchseries it would use on-stack dma buffers (don't know about the actual harm of these, at least a WARN from libdma, but rumours are that they may format your disk if the moon aligns with the sun and a special unspecified planet).

Regards,
Flo

Quoted 5 lines

regards,
--

Patrick Boettcher - Kernel Labs
http://www.kernellabs.com/

#6 lore raw
Quoted 1 line · Florian Mickler

Mauro, what to do?

Apply the fix which Tino tested, perhaps? :P (obviously).

The bug is present in 3.0 so it should be tagged for stable as well.

regards,
dan carpenter

#7 lore raw
Quoted 9 lines · On Thu, 4 Aug 2011 13:29:42 +0300 Dan Carpenter <[email protected]> wrote:
Quoted 1 line · Florian Mickler

Mauro, what to do?

Apply the fix which Tino tested, perhaps? :P (obviously).

The bug is present in 3.0 so it should be tagged for stable as well.

regards,
dan carpenter

Two different drivers ;) I fear the fix Tino tested does not apply to vp702x.. (it's for vp7045)

Regards,
Flo