[media] vp702x: use preallocated buffer in vp702x_usb_inout_cmd
If we need a bigger buffer, we reallocte a new buffer and free the old one. Note: This change is tested to compile only as I don't have the hardware. Signed-off-by: Florian Mickler <florian@mickler.org> Cc: Patrick Boettcher <pb@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
parent
8ea793aa73
commit
ee52f120b0
1 changed files with 19 additions and 4 deletions
|
@ -116,13 +116,28 @@ int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int il
|
||||||
static int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o,
|
static int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o,
|
||||||
int olen, u8 *i, int ilen, int msec)
|
int olen, u8 *i, int ilen, int msec)
|
||||||
{
|
{
|
||||||
|
struct vp702x_device_state *st = d->priv;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
u8 *buf;
|
u8 *buf;
|
||||||
int buflen = max(olen + 2, ilen + 1);
|
int buflen = max(olen + 2, ilen + 1);
|
||||||
|
|
||||||
|
ret = mutex_lock_interruptible(&st->buf_mutex);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (buflen > st->buf_len) {
|
||||||
buf = kmalloc(buflen, GFP_KERNEL);
|
buf = kmalloc(buflen, GFP_KERNEL);
|
||||||
if (!buf)
|
if (!buf) {
|
||||||
|
mutex_unlock(&st->buf_mutex);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
info("successfully reallocated a bigger buffer");
|
||||||
|
kfree(st->buf);
|
||||||
|
st->buf = buf;
|
||||||
|
st->buf_len = buflen;
|
||||||
|
} else {
|
||||||
|
buf = st->buf;
|
||||||
|
}
|
||||||
|
|
||||||
buf[0] = 0x00;
|
buf[0] = 0x00;
|
||||||
buf[1] = cmd;
|
buf[1] = cmd;
|
||||||
|
@ -132,8 +147,8 @@ static int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o,
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
memcpy(i, &buf[1], ilen);
|
memcpy(i, &buf[1], ilen);
|
||||||
|
mutex_unlock(&st->buf_mutex);
|
||||||
|
|
||||||
kfree(buf);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue