From patchwork Tue May 4 12:14:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 3295 Return-path: Envelope-to: mchehab@infradead.org Delivery-date: Tue, 04 May 2010 12:14:46 +0000 Received: from bombadil.infradead.org [18.85.46.34] by pedra with IMAP (fetchmail-6.3.6) for (single-drop); Tue, 04 May 2010 09:27:46 -0300 (BRT) Received: from vger.kernel.org ([209.132.180.67]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1O9H1R-0004uU-Pl; Tue, 04 May 2010 12:14:45 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757859Ab0EDMOn (ORCPT + 1 other); Tue, 4 May 2010 08:14:43 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:56685 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752137Ab0EDMOl (ORCPT ); Tue, 4 May 2010 08:14:41 -0400 Received: by fxm10 with SMTP id 10so3133468fxm.19 for ; Tue, 04 May 2010 05:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=kNhqZyYRplt/glCW8Yy3qdaf94r/FCtx394v3mDmJao=; b=bTs/UgKs0TNAW3q+LFntzcuz84OYJTwEWGyYlTKCPfrN0FJsF/rZQMA5yNPTouTy/t G/UZ0VCV5mtbhPHLGtPJMNBcHHAIaZ5aEhosXIvsOSBceZTrxacFOBwZqTNCVnxpriKB TGThTsop+4nOSuA0bTd7KxIN7XnQoLJUjvMEE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=tHU5i9bGydo8e+hrHxEUw0upMe4YQeTy8uPq9OExicwROjHVAwCyDfHiO98a1O5oPE tRqTQoqBYOCDg3GHM1G96fUtY1/t+YqRnodCvDJnxBXlSuom0MHfFsQcREBkLQNJnIhb IOhnnuMGLBk4cTakZVprrfgbZnbptS+eSHZo4= Received: by 10.223.47.130 with SMTP id n2mr4054145faf.55.1272975277473; Tue, 04 May 2010 05:14:37 -0700 (PDT) Received: from bicker ([205.177.176.130]) by mx.google.com with ESMTPS id p17sm11180557fka.16.2010.05.04.05.14.32 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 04 May 2010 05:14:36 -0700 (PDT) Date: Tue, 4 May 2010 14:14:29 +0200 From: Dan Carpenter To: Mauro Carvalho Chehab Cc: Adams.xu@azwave.com.cn, linux-media@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch -next 1/2] media/az6027: doing dma on the stack Message-ID: <20100504121429.GW29093@bicker> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org I changed the dma buffers to use allocated memory instead of stack memory. The reason for this is documented in Documentation/DMA-API-HOWTO.txt under the section: "What memory is DMA'able?" That document was only added a couple weeks ago and there are still lots of modules which haven't been corrected yet. Btw. Smatch includes a pretty good test to find places which use stack memory as a dma buffer. That's how I found these. (http://smatch.sf.net). Signed-off-by: Dan Carpenter --- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/media/dvb/dvb-usb/az6027.c b/drivers/media/dvb/dvb-usb/az6027.c index 8934788..baaa301 100644 --- a/drivers/media/dvb/dvb-usb/az6027.c +++ b/drivers/media/dvb/dvb-usb/az6027.c @@ -417,11 +417,15 @@ static int az6027_ci_read_attribute_mem(struct dvb_ca_en50221 *ca, u16 value; u16 index; int blen; - u8 b[12]; + u8 *b; if (slot != 0) return -EINVAL; + b = kmalloc(12, GFP_KERNEL); + if (!b) + return -ENOMEM; + mutex_lock(&state->ca_mutex); req = 0xC1; @@ -438,6 +442,7 @@ static int az6027_ci_read_attribute_mem(struct dvb_ca_en50221 *ca, } mutex_unlock(&state->ca_mutex); + kfree(b); return ret; } @@ -485,11 +490,15 @@ static int az6027_ci_read_cam_control(struct dvb_ca_en50221 *ca, u16 value; u16 index; int blen; - u8 b[12]; + u8 *b; if (slot != 0) return -EINVAL; + b = kmalloc(12, GFP_KERNEL); + if (!b) + return -ENOMEM; + mutex_lock(&state->ca_mutex); req = 0xC3; @@ -510,6 +519,7 @@ static int az6027_ci_read_cam_control(struct dvb_ca_en50221 *ca, } mutex_unlock(&state->ca_mutex); + kfree(b); return ret; } @@ -556,7 +566,11 @@ static int CI_CamReady(struct dvb_ca_en50221 *ca, int slot) u16 value; u16 index; int blen; - u8 b[12]; + u8 *b; + + b = kmalloc(12, GFP_KERNEL); + if (!b) + return -ENOMEM; req = 0xC8; value = 0; @@ -570,6 +584,7 @@ static int CI_CamReady(struct dvb_ca_en50221 *ca, int slot) } else{ ret = b[0]; } + kfree(b); return ret; } @@ -667,8 +682,11 @@ static int az6027_ci_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int o u16 value; u16 index; int blen; - u8 b[12]; + u8 *b; + b = kmalloc(12, GFP_KERNEL); + if (!b) + return -ENOMEM; mutex_lock(&state->ca_mutex); req = 0xC5; @@ -692,6 +710,7 @@ static int az6027_ci_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int o } mutex_unlock(&state->ca_mutex); + kfree(b); return ret; } @@ -943,10 +962,16 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n u16 value; int length; u8 req; - u8 data[256]; + u8 *data; + + data = kmalloc(256, GFP_KERNEL); + if (!data) + return -ENOMEM; - if (mutex_lock_interruptible(&d->i2c_mutex) < 0) + if (mutex_lock_interruptible(&d->i2c_mutex) < 0) { + kfree(data); return -EAGAIN; + } if (num > 2) warn("more than 2 i2c messages at a time is not handled yet. TODO."); @@ -1016,6 +1041,7 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n } } mutex_unlock(&d->i2c_mutex); + kfree(data); return i; } @@ -1036,8 +1062,14 @@ int az6027_identify_state(struct usb_device *udev, struct dvb_usb_device_description **desc, int *cold) { - u8 b[16]; - s16 ret = usb_control_msg(udev, + u8 *b; + s16 ret; + + b = kmalloc(16, GFP_KERNEL); + if (!b) + return -ENOMEM; + + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0xb7, USB_TYPE_VENDOR | USB_DIR_IN, @@ -1048,7 +1080,7 @@ int az6027_identify_state(struct usb_device *udev, USB_CTRL_GET_TIMEOUT); *cold = ret <= 0; - + kfree(b); deb_info("cold: %d\n", *cold); return 0; }