1 From bff469f4167fdabfe15294f375577d7eadbaa1bb Mon Sep 17 00:00:00 2001
2 From: Olivier Grenie <olivier.grenie@dibcom.fr>
3 Date: Mon, 1 Aug 2011 12:45:58 -0300
4 Subject: [media] dib0700: protect the dib0700 buffer access
6 From: Olivier Grenie <olivier.grenie@dibcom.fr>
8 commit bff469f4167fdabfe15294f375577d7eadbaa1bb upstream.
10 This patch protects the common buffer access inside the dib0700 in order
11 to manage concurrent access. This protection is done using mutex.
13 Cc: Mauro Carvalho Chehab <mchehab@redhat.com>
14 Cc: Florian Mickler <florian@mickler.org>
15 Signed-off-by: Javier Marcet <javier@marcet.info>
16 Signed-off-by: Olivier Grenie <olivier.grenie@dibcom.fr>
17 Signed-off-by: Patrick Boettcher <patrick.boettcher@dibcom.fr>
18 [mchehab@redhat.com: dprint requires 3 arguments. Replaced by dib_info]
19 Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
20 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
23 drivers/media/dvb/dvb-usb/dib0700_core.c | 81 +++++++++++++++++++++++++++----
24 1 file changed, 72 insertions(+), 9 deletions(-)
26 --- a/drivers/media/dvb/dvb-usb/dib0700_core.c
27 +++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
28 @@ -30,6 +30,11 @@ int dib0700_get_version(struct dvb_usb_d
29 struct dib0700_state *st = d->priv;
32 + if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
33 + deb_info("could not acquire lock");
37 ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
39 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
40 @@ -46,6 +51,7 @@ int dib0700_get_version(struct dvb_usb_d
42 *fwtype = (st->buf[12] << 24) | (st->buf[13] << 16) |
43 (st->buf[14] << 8) | st->buf[15];
44 + mutex_unlock(&d->usb_mutex);
48 @@ -108,7 +114,12 @@ int dib0700_ctrl_rd(struct dvb_usb_devic
49 int dib0700_set_gpio(struct dvb_usb_device *d, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val)
51 struct dib0700_state *st = d->priv;
55 + if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
56 + deb_info("could not acquire lock");
60 st->buf[0] = REQUEST_SET_GPIO;
62 @@ -116,6 +127,7 @@ int dib0700_set_gpio(struct dvb_usb_devi
64 ret = dib0700_ctrl_wr(d, st->buf, 3);
66 + mutex_unlock(&d->usb_mutex);
70 @@ -125,6 +137,11 @@ static int dib0700_set_usb_xfer_len(stru
73 if (st->fw_version >= 0x10201) {
74 + if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
75 + deb_info("could not acquire lock");
79 st->buf[0] = REQUEST_SET_USB_XFER_LEN;
80 st->buf[1] = (nb_ts_packets >> 8) & 0xff;
81 st->buf[2] = nb_ts_packets & 0xff;
82 @@ -132,6 +149,7 @@ static int dib0700_set_usb_xfer_len(stru
83 deb_info("set the USB xfer len to %i Ts packet\n", nb_ts_packets);
85 ret = dib0700_ctrl_wr(d, st->buf, 3);
86 + mutex_unlock(&d->usb_mutex);
88 deb_info("this firmware does not allow to change the USB xfer len\n");
90 @@ -208,6 +226,10 @@ static int dib0700_i2c_xfer_new(struct i
94 + if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
95 + deb_info("could not acquire lock");
98 st->buf[0] = REQUEST_NEW_I2C_WRITE;
99 st->buf[1] = msg[i].addr << 1;
100 st->buf[2] = (en_start << 7) | (en_stop << 6) |
101 @@ -227,6 +249,7 @@ static int dib0700_i2c_xfer_new(struct i
102 USB_TYPE_VENDOR | USB_DIR_OUT,
103 0, 0, st->buf, msg[i].len + 4,
104 USB_CTRL_GET_TIMEOUT);
105 + mutex_unlock(&d->usb_mutex);
107 deb_info("i2c write error (status = %d)\n", result);
109 @@ -249,6 +272,10 @@ static int dib0700_i2c_xfer_legacy(struc
111 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
113 + if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
114 + deb_info("could not acquire lock");
118 for (i = 0; i < num; i++) {
119 /* fill in the address */
120 @@ -279,6 +306,7 @@ static int dib0700_i2c_xfer_legacy(struc
124 + mutex_unlock(&d->usb_mutex);
125 mutex_unlock(&d->i2c_mutex);
128 @@ -337,7 +365,12 @@ static int dib0700_set_clock(struct dvb_
129 u16 pll_loopdiv, u16 free_div, u16 dsuScaler)
131 struct dib0700_state *st = d->priv;
135 + if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
136 + deb_info("could not acquire lock");
140 st->buf[0] = REQUEST_SET_CLOCK;
141 st->buf[1] = (en_pll << 7) | (pll_src << 6) |
142 @@ -352,6 +385,7 @@ static int dib0700_set_clock(struct dvb_
143 st->buf[9] = dsuScaler & 0xff; /* LSB */
145 ret = dib0700_ctrl_wr(d, st->buf, 10);
146 + mutex_unlock(&d->usb_mutex);
150 @@ -360,10 +394,16 @@ int dib0700_set_i2c_speed(struct dvb_usb
152 struct dib0700_state *st = d->priv;
159 + if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
160 + deb_info("could not acquire lock");
164 st->buf[0] = REQUEST_SET_I2C_PARAM;
165 divider = (u16) (30000 / scl_kHz);
167 @@ -379,7 +419,11 @@ int dib0700_set_i2c_speed(struct dvb_usb
168 deb_info("setting I2C speed: %04x %04x %04x (%d kHz).",
169 (st->buf[2] << 8) | (st->buf[3]), (st->buf[4] << 8) |
170 st->buf[5], (st->buf[6] << 8) | st->buf[7], scl_kHz);
171 - return dib0700_ctrl_wr(d, st->buf, 8);
173 + ret = dib0700_ctrl_wr(d, st->buf, 8);
174 + mutex_unlock(&d->usb_mutex);
180 @@ -515,6 +559,11 @@ int dib0700_streaming_ctrl(struct dvb_us
184 + if (mutex_lock_interruptible(&adap->dev->usb_mutex) < 0) {
185 + deb_info("could not acquire lock");
189 st->buf[0] = REQUEST_ENABLE_VIDEO;
190 /* this bit gives a kind of command,
191 * rather than enabling something or not */
192 @@ -548,7 +597,10 @@ int dib0700_streaming_ctrl(struct dvb_us
194 deb_info("data for streaming: %x %x\n", st->buf[1], st->buf[2]);
196 - return dib0700_ctrl_wr(adap->dev, st->buf, 4);
197 + ret = dib0700_ctrl_wr(adap->dev, st->buf, 4);
198 + mutex_unlock(&adap->dev->usb_mutex);
203 int dib0700_change_protocol(struct rc_dev *rc, u64 rc_type)
204 @@ -557,6 +609,11 @@ int dib0700_change_protocol(struct rc_de
205 struct dib0700_state *st = d->priv;
208 + if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
209 + deb_info("could not acquire lock");
213 st->buf[0] = REQUEST_SET_RC;
216 @@ -567,23 +624,29 @@ int dib0700_change_protocol(struct rc_de
217 else if (rc_type == RC_TYPE_NEC)
219 else if (rc_type == RC_TYPE_RC6) {
220 - if (st->fw_version < 0x10200)
222 + if (st->fw_version < 0x10200) {
235 st->buf[1] = new_proto;
237 ret = dib0700_ctrl_wr(d, st->buf, 3);
239 err("ir protocol setup failed");
244 d->props.rc.core.protocol = rc_type;
247 + mutex_unlock(&d->usb_mutex);