From patchwork Mon Sep 3 08:14:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland Stigge X-Patchwork-Id: 1398941 Return-Path: X-Original-To: patchwork-spi-devel-general@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by patchwork1.kernel.org (Postfix) with ESMTP id C74733FC71 for ; Mon, 3 Sep 2012 08:14:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1T8Ro7-0003yy-85; Mon, 03 Sep 2012 08:14:55 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1T8Ro5-0003yr-J6 for spi-devel-general@lists.sourceforge.net; Mon, 03 Sep 2012 08:14:53 +0000 X-ACL-Warn: Received: from mail.work-microwave.de ([62.245.205.51] helo=work-microwave.de) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1T8Rnz-0008Oi-GN for spi-devel-general@lists.sourceforge.net; Mon, 03 Sep 2012 08:14:53 +0000 Received: from rst-pc1.lan.work-microwave.de ([192.168.11.78]) (authenticated bits=0) by mail.work-microwave.de with ESMTP id q838EVhM029281 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 3 Sep 2012 09:14:32 +0100 Received: by rst-pc1.lan.work-microwave.de (Postfix, from userid 1000) id EC9C4AE06D; Mon, 3 Sep 2012 10:14:30 +0200 (CEST) From: Roland Stigge To: linus.walleij@linaro.org, shiraz.linux.kernel@gmail.com, aletes.xgr@gmail.com, broonie@opensource.wolfsonmicro.com, grant.likely@secretlab.ca, rob.herring@calxeda.com, rob@landley.net, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, spi-devel-general@lists.sourceforge.net, gabriel.fernandez@stericsson.com, lee.jones@linaro.org, viresh.kumar@linaro.org, sachin.verma@st.co Subject: [PATCH] spi/pl022: Fix chipselects pointer computation Date: Mon, 3 Sep 2012 10:14:29 +0200 Message-Id: <1346660069-16049-1-git-send-email-stigge@antcom.de> X-Mailer: git-send-email 1.7.10.4 X-FEAS-SYSTEM-WL: rst@work-microwave.de, 192.168.11.78 X-Spam-Score: -0.2 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -0.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1T8Rnz-0008Oi-GN Cc: Roland Stigge X-BeenThere: spi-devel-general@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux SPI core/device drivers discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: spi-devel-general-bounces@lists.sourceforge.net The new chip select handling via GPIO introduced a pointer computation bug: (int *) pl022 + sizeof(struct pl022) doesn't point to the data immediately after the actual struct pl022 (as was intended) but to a multiple of bytes after it because of the (int *) type. Replacing the kludgy pointer arithmetic with managed memory allocation for the chip selects. Signed-off-by: Roland Stigge Reviewed-by: Linus Walleij Reported-by: Shiraz Hashim --- drivers/spi/spi-pl022.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ --- linux-2.6.orig/drivers/spi/spi-pl022.c +++ linux-2.6/drivers/spi/spi-pl022.c @@ -2053,8 +2053,7 @@ pl022_probe(struct amba_device *adev, co } /* Allocate master with space for data */ - master = spi_alloc_master(dev, sizeof(struct pl022) + sizeof(int) * - num_cs); + master = spi_alloc_master(dev, sizeof(struct pl022)); if (master == NULL) { dev_err(&adev->dev, "probe - cannot alloc SPI master\n"); status = -ENOMEM; @@ -2066,8 +2065,8 @@ pl022_probe(struct amba_device *adev, co pl022->master_info = platform_info; pl022->adev = adev; pl022->vendor = id->data; - /* Point chipselects to allocated memory beyond the main struct */ - pl022->chipselects = (int *) pl022 + sizeof(struct pl022); + pl022->chipselects = devm_kzalloc(dev, num_cs * sizeof(int), + GFP_KERNEL); /* * Bus Number Which has been Assigned to this SSP controller