From patchwork Mon Apr 14 16:41:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 3984011 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7F62FBFF02 for ; Mon, 14 Apr 2014 16:41:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 92634201DC for ; Mon, 14 Apr 2014 16:41:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 52BB42018E for ; Mon, 14 Apr 2014 16:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755992AbaDNQln (ORCPT ); Mon, 14 Apr 2014 12:41:43 -0400 Received: from top.free-electrons.com ([176.31.233.9]:33648 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755926AbaDNQlj (ORCPT ); Mon, 14 Apr 2014 12:41:39 -0400 Received: by mail.free-electrons.com (Postfix, from userid 106) id 3FA097EA; Mon, 14 Apr 2014 18:41:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from localhost.localdomain (unknown [190.2.108.71]) by mail.free-electrons.com (Postfix) with ESMTPSA id 37C507E1; Mon, 14 Apr 2014 18:41:35 +0200 (CEST) From: Ezequiel Garcia To: , Hans Verkuil Cc: Alan Stern , Sander Eikelenboom , Ezequiel Garcia Subject: [PATCH] media: stk1160: Avoid stack-allocated buffer for control URBs Date: Mon, 14 Apr 2014 13:41:05 -0300 Message-Id: <1397493665-912-1-git-send-email-ezequiel.garcia@free-electrons.com> X-Mailer: git-send-email 1.9.1 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently stk1160_read_reg() uses a stack-allocated char to get the read control value. This is wrong because usb_control_msg() requires a kmalloc-ed buffer, and a DMA-API warning is produced: WARNING: CPU: 0 PID: 1376 at lib/dma-debug.c:1153 check_for_stack+0xa0/0x100() ehci-pci 0000:00:0a.0: DMA-API: device driver maps memory fromstack [addr=ffff88003d0b56bf] This commit fixes such issue by using a 'usb_ctrl_read' field embedded in the device's struct to pass the value. In addition, we introduce a mutex to protect the value. While here, let's remove the urb_buf array which was meant for a similar purpose, but never really used. Reported-by: Sander Eikelenboom Signed-off-by: Ezequiel Garcia --- Sander, Hans: Does this cause any regressions, other than the DMA-API warning? In that case, we can consider this as suitable for -stable. drivers/media/usb/stk1160/stk1160-core.c | 8 +++++++- drivers/media/usb/stk1160/stk1160.h | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/stk1160/stk1160-core.c b/drivers/media/usb/stk1160/stk1160-core.c index 34a26e0..cce91e7 100644 --- a/drivers/media/usb/stk1160/stk1160-core.c +++ b/drivers/media/usb/stk1160/stk1160-core.c @@ -69,15 +69,20 @@ int stk1160_read_reg(struct stk1160 *dev, u16 reg, u8 *value) int pipe = usb_rcvctrlpipe(dev->udev, 0); *value = 0; + + mutex_lock(&dev->urb_ctrl_lock); ret = usb_control_msg(dev->udev, pipe, 0x00, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - 0x00, reg, value, sizeof(u8), HZ); + 0x00, reg, &dev->urb_ctrl_read, sizeof(u8), HZ); if (ret < 0) { stk1160_err("read failed on reg 0x%x (%d)\n", reg, ret); + mutex_unlock(&dev->urb_ctrl_lock); return ret; } + *value = dev->urb_ctrl_read; + mutex_unlock(&dev->urb_ctrl_lock); return 0; } @@ -322,6 +327,7 @@ static int stk1160_probe(struct usb_interface *interface, * because we register the device node as the *last* thing. */ spin_lock_init(&dev->buf_lock); + mutex_init(&dev->urb_ctrl_lock); mutex_init(&dev->v4l_lock); mutex_init(&dev->vb_queue_lock); diff --git a/drivers/media/usb/stk1160/stk1160.h b/drivers/media/usb/stk1160/stk1160.h index 05b05b1..8886be4 100644 --- a/drivers/media/usb/stk1160/stk1160.h +++ b/drivers/media/usb/stk1160/stk1160.h @@ -143,7 +143,7 @@ struct stk1160 { int num_alt; struct stk1160_isoc_ctl isoc_ctl; - char urb_buf[255]; /* urb control msg buffer */ + char urb_ctrl_read; /* frame properties */ int width; /* current frame width */ @@ -159,6 +159,7 @@ struct stk1160 { struct i2c_adapter i2c_adap; struct i2c_client i2c_client; + struct mutex urb_ctrl_lock; /* protects urb_ctrl_read */ struct mutex v4l_lock; struct mutex vb_queue_lock; spinlock_t buf_lock;