diff options
author | Florian Mickler <florian@mickler.org> | 2011-03-21 06:19:13 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-05-20 08:28:12 -0400 |
commit | ee52f120b0adc469f5c67815cef79ecdd01cfd14 (patch) | |
tree | 53e9053e23c4dbd1185bbea6e7336f371c6e35aa /drivers/media/dvb/dvb-usb | |
parent | 8ea793aa736137aa2453ce6877bb31a4b15dc28d (diff) |
[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>
Diffstat (limited to 'drivers/media/dvb/dvb-usb')
-rw-r--r-- | drivers/media/dvb/dvb-usb/vp702x.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/drivers/media/dvb/dvb-usb/vp702x.c b/drivers/media/dvb/dvb-usb/vp702x.c index 6dd50bc8418e..54355f84a98f 100644 --- a/drivers/media/dvb/dvb-usb/vp702x.c +++ b/drivers/media/dvb/dvb-usb/vp702x.c | |||
@@ -116,13 +116,28 @@ int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int il | |||
116 | static int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o, | 116 | static int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o, |
117 | int olen, u8 *i, int ilen, int msec) | 117 | int olen, u8 *i, int ilen, int msec) |
118 | { | 118 | { |
119 | struct vp702x_device_state *st = d->priv; | ||
119 | int ret = 0; | 120 | int ret = 0; |
120 | u8 *buf; | 121 | u8 *buf; |
121 | int buflen = max(olen + 2, ilen + 1); | 122 | int buflen = max(olen + 2, ilen + 1); |
122 | 123 | ||
123 | buf = kmalloc(buflen, GFP_KERNEL); | 124 | ret = mutex_lock_interruptible(&st->buf_mutex); |
124 | if (!buf) | 125 | if (ret < 0) |
125 | return -ENOMEM; | 126 | return ret; |
127 | |||
128 | if (buflen > st->buf_len) { | ||
129 | buf = kmalloc(buflen, GFP_KERNEL); | ||
130 | if (!buf) { | ||
131 | mutex_unlock(&st->buf_mutex); | ||
132 | return -ENOMEM; | ||
133 | } | ||
134 | info("successfully reallocated a bigger buffer"); | ||
135 | kfree(st->buf); | ||
136 | st->buf = buf; | ||
137 | st->buf_len = buflen; | ||
138 | } else { | ||
139 | buf = st->buf; | ||
140 | } | ||
126 | 141 | ||
127 | buf[0] = 0x00; | 142 | buf[0] = 0x00; |
128 | buf[1] = cmd; | 143 | buf[1] = cmd; |
@@ -132,8 +147,8 @@ static int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o, | |||
132 | 147 | ||
133 | if (ret == 0) | 148 | if (ret == 0) |
134 | memcpy(i, &buf[1], ilen); | 149 | memcpy(i, &buf[1], ilen); |
150 | mutex_unlock(&st->buf_mutex); | ||
135 | 151 | ||
136 | kfree(buf); | ||
137 | return ret; | 152 | return ret; |
138 | } | 153 | } |
139 | 154 | ||