From patchwork Wed Jun 26 22:54:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Jiang X-Patchwork-Id: 2783761 Return-Path: X-Original-To: patchwork-spi-devel-general@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 95DF9C0AB1 for ; Wed, 26 Jun 2013 10:08:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 613CC20370 for ; Wed, 26 Jun 2013 10:08:08 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1D93420368 for ; Wed, 26 Jun 2013 10:08:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Urmdy-0005rn-0L; Wed, 26 Jun 2013 10:08:06 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Urmdv-0005rb-Us for spi-devel-general@lists.sourceforge.net; Wed, 26 Jun 2013 10:08:03 +0000 Received-SPF: neutral (sog-mx-1.v43.ch3.sourceforge.com: 213.199.154.186 is neither permitted nor denied by domain of gmail.com) client-ip=213.199.154.186; envelope-from=scott.jiang.linux@gmail.com; helo=db8outboundpool.messaging.microsoft.com; Received: from mail-db8lp0186.outbound.messaging.microsoft.com ([213.199.154.186] helo=db8outboundpool.messaging.microsoft.com) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1Urmdu-0003XH-3K for spi-devel-general@lists.sourceforge.net; Wed, 26 Jun 2013 10:08:03 +0000 Received: from mail167-db8-R.bigfish.com (10.174.8.254) by DB8EHSOBE031.bigfish.com (10.174.4.94) with Microsoft SMTP Server id 14.1.225.23; Wed, 26 Jun 2013 09:52:45 +0000 Received: from mail167-db8 (localhost [127.0.0.1]) by mail167-db8-R.bigfish.com (Postfix) with ESMTP id 1B1F0C8019D; Wed, 26 Jun 2013 09:52:45 +0000 (UTC) X-Forefront-Antispam-Report: CIP:137.71.25.57; KIP:(null); UIP:(null); IPV:NLI; H:nwd2mta2.analog.com; RD:nwd2mail11.analog.com; EFVD:NLI X-SpamScore: 12 X-BigFish: VS12(zzzz1f42h1ee6h1ce5h1fdah201ch1202h1fd0h1e76h1d1ah1cabh1d2ah1fc6hzz8275bhz2ei87h2a8h668h839hd24he5bh1288h12a5h12a9h12bdh12e5h1354h137ah139eh13b6h13eah1441h1504h1537h15a8h162dh1631h1758h17eeh1898h18e1h1946h19b5h1b0ah1d0ch1d2eh1d3fh1dc1h1dfeh1dffh1e23hff4m1355m129fi1155h) Received-SPF: neutral (mail167-db8: 137.71.25.57 is neither permitted nor denied by domain of gmail.com) client-ip=137.71.25.57; envelope-from=scott.jiang.linux@gmail.com; helo=nwd2mta2.analog.com ; 2.analog.com ; X-FB-DOMAIN-IP-MATCH: fail Received: from mail167-db8 (localhost.localdomain [127.0.0.1]) by mail167-db8 (MessageSwitch) id 1372240363361581_8331; Wed, 26 Jun 2013 09:52:43 +0000 (UTC) Received: from DB8EHSMHS012.bigfish.com (unknown [10.174.8.250]) by mail167-db8.bigfish.com (Postfix) with ESMTP id 431E8B00049; Wed, 26 Jun 2013 09:52:43 +0000 (UTC) Received: from nwd2mta2.analog.com (137.71.25.57) by DB8EHSMHS012.bigfish.com (10.174.4.22) with Microsoft SMTP Server (TLS) id 14.16.227.3; Wed, 26 Jun 2013 09:52:42 +0000 Received: from NWD2HUBCAS6.ad.analog.com (nwd2hubcas6.ad.analog.com [10.64.72.159]) by nwd2mta2.analog.com (8.13.8/8.13.8) with ESMTP id r5QBU0kB028697 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 26 Jun 2013 07:30:00 -0400 Received: from zeus.spd.analog.com (10.64.82.11) by NWD2HUBCAS6.ad.analog.com (10.64.72.159) with Microsoft SMTP Server id 14.3.123.3; Wed, 26 Jun 2013 05:51:22 -0400 Received: from linux.site ([10.99.22.20]) by zeus.spd.analog.com (8.14.6/8.14.6) with ESMTP id r5Q9pLLq000374; Wed, 26 Jun 2013 05:51:21 -0400 Received: from localhost.localdomain (unknown [10.99.24.72]) by linux.site (Postfix) with ESMTP id 96AA74265F86; Tue, 25 Jun 2013 20:26:13 -0600 (MDT) From: Scott Jiang To: Grant Likely , Mark Brown Subject: [PATCH] spi: add bits_per_word_mask check in spi_setup Date: Wed, 26 Jun 2013 18:54:46 -0400 Message-ID: <1372287286-12682-1-git-send-email-scott.jiang.linux@gmail.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% X-Spam-Score: 1.9 (+) X-Headers-End: 1Urmdu-0003XH-3K Cc: spi-devel-general@lists.sourceforge.net, Scott Jiang , uclinux-dist-devel@blackfin.uclinux.org 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: , Errors-To: spi-devel-general-bounces@lists.sourceforge.net X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00, DATE_IN_FUTURE_06_12, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The spi_setup should fail if underlying controller or its driver does not support requested bits_per_word. So if the master driver set mask and let core do bits_per_word check then we should also test this mask in spi_setup. Signed-off-by: Scott Jiang --- drivers/spi/spi.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 45cb6a9..dc8fde0 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1326,6 +1326,15 @@ int spi_setup(struct spi_device *spi) if (!spi->bits_per_word) spi->bits_per_word = 8; + if (spi->master->bits_per_word_mask) { + /* Only 32 bits fit in the mask */ + if (spi->bits_per_word > 32) + return -EINVAL; + if (!(spi->master->bits_per_word_mask & + BIT(spi->bits_per_word - 1))) + return -EINVAL; + } + if (spi->master->setup) status = spi->master->setup(spi);