From patchwork Mon Mar 21 10:19:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Mickler X-Patchwork-Id: 647601 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2LAKt9t017696 for ; Mon, 21 Mar 2011 10:20:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753131Ab1CUKUb (ORCPT ); Mon, 21 Mar 2011 06:20:31 -0400 Received: from ist.d-labs.de ([213.239.218.44]:44320 "EHLO mx01.d-labs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752964Ab1CUKTh (ORCPT ); Mon, 21 Mar 2011 06:19:37 -0400 Received: from schatten.dmk.lab (f053218247.adsl.alicedsl.de [78.53.218.247]) by mx01.d-labs.de (Postfix) with ESMTPSA id 78C3A7F8F6; Mon, 21 Mar 2011 11:19:36 +0100 (CET) Received: by schatten.dmk.lab (Postfix, from userid 1000) id D588318101; Mon, 21 Mar 2011 11:19:35 +0100 (CET) From: Florian Mickler To: mchehab@infradead.org Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, pb@linuxtv.org, Florian Mickler Subject: [PATCH 8/9] [media] vp702x: use preallocated buffer in vp702x_usb_inout_cmd Date: Mon, 21 Mar 2011 11:19:13 +0100 Message-Id: <1300702754-16376-9-git-send-email-florian@mickler.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1300702754-16376-1-git-send-email-florian@mickler.org> References: <1300702754-16376-1-git-send-email-florian@mickler.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 21 Mar 2011 10:20:57 +0000 (UTC) diff --git a/drivers/media/dvb/dvb-usb/vp702x.c b/drivers/media/dvb/dvb-usb/vp702x.c index 6dd50bc..54355f8 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 static int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o, int olen, u8 *i, int ilen, int msec) { + struct vp702x_device_state *st = d->priv; int ret = 0; u8 *buf; int buflen = max(olen + 2, ilen + 1); - buf = kmalloc(buflen, GFP_KERNEL); - if (!buf) - return -ENOMEM; + ret = mutex_lock_interruptible(&st->buf_mutex); + if (ret < 0) + return ret; + + if (buflen > st->buf_len) { + buf = kmalloc(buflen, GFP_KERNEL); + if (!buf) { + mutex_unlock(&st->buf_mutex); + 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[1] = cmd; @@ -132,8 +147,8 @@ static int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o, if (ret == 0) memcpy(i, &buf[1], ilen); + mutex_unlock(&st->buf_mutex); - kfree(buf); return ret; }