From patchwork Thu Feb 13 08:41:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3643701 Return-Path: X-Original-To: patchwork-linux-spi@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 DDEECBF13A for ; Thu, 13 Feb 2014 08:41:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 065DA2018E for ; Thu, 13 Feb 2014 08:41:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 255742015D for ; Thu, 13 Feb 2014 08:41:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753460AbaBMIlw (ORCPT ); Thu, 13 Feb 2014 03:41:52 -0500 Received: from mail-pa0-f49.google.com ([209.85.220.49]:34417 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753158AbaBMIlw (ORCPT ); Thu, 13 Feb 2014 03:41:52 -0500 Received: by mail-pa0-f49.google.com with SMTP id hz1so10423798pad.22 for ; Thu, 13 Feb 2014 00:41:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:content-type :mime-version:content-transfer-encoding; bh=wkOmS2ErZ0JqqpkVOo7QgRVyTFRxTeC7FlQ+UWpZjFA=; b=WoQIpDVbWpXXsHlkIm13vxOLuCz66hFeOdZWzzp9HZ10/KTlh3t2GJ9Fwt8klmz6Yq tNB0xHX9fDKqzEGWVUYz9EkRiFnjE1dW3osImn/nZrW0eLBZ/uH01F4+fWO49J3O9cVR MGGeMGCOVz/yLZJMbKqfQQjCF/JZ+wPsejsCm/3lNqLG6Z0wgSzmoXbQmCMyc7BkCwvR alAbyJm/RnUy3MbCHzxc0/BanwTMswANiEkTXSjy9IWFVYn7XJ2RPNGLaIm3gAQbAvjL O84TpujpOlSyJv+f/vF0L0oTV59gQtV70pZD37ELdy03wcB+oKXEBEmGvjVjLjTiZvnN 7SoA== X-Gm-Message-State: ALoCoQmN4JlXFKw9/OeUNeSXgyIlpshRCLcK10lM7LeQgmHHpDmDIbAWleto+YyoN1LCENaNDVBZ X-Received: by 10.68.180.66 with SMTP id dm2mr202443pbc.143.1392280911592; Thu, 13 Feb 2014 00:41:51 -0800 (PST) Received: from [192.168.1.102] (111-240-56-81.dynamic.hinet.net. [111.240.56.81]) by mx.google.com with ESMTPSA id u6sm4051059pbu.16.2014.02.13.00.41.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Feb 2014 00:41:51 -0800 (PST) Message-ID: <1392280906.8200.0.camel@phoenix> Subject: [PATCH v2] spi: fsl-spi: Convert to let spi core validate xfer->bits_per_word From: Axel Lin To: Mark Brown Cc: Stefan Roese , Andreas Larsson , linux-spi@vger.kernel.org Date: Thu, 13 Feb 2014 16:41:46 +0800 X-Mailer: Evolution 3.6.4-0ubuntu1 Mime-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, 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 Set bits_per_word_mask so spi core will reject transfers that attempt to use an unsupported bits_per_word value. Signed-off-by: Axel Lin --- v2: Make sure bits_per_word can not be greater than mpc8xxx_spi->max_bits_per_word. drivers/spi/spi-fsl-spi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 4dcb292..c4f9143 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -239,10 +239,7 @@ static int fsl_spi_setup_transfer(struct spi_device *spi, if (!bits_per_word) bits_per_word = spi->bits_per_word; - /* Make sure its a bit width we support [4..16, 32] */ - if ((bits_per_word < 4) - || ((bits_per_word > 16) && (bits_per_word != 32)) - || (bits_per_word > mpc8xxx_spi->max_bits_per_word)) + if (bits_per_word > mpc8xxx_spi->max_bits_per_word) return -EINVAL; if (!hz) @@ -631,6 +628,8 @@ static struct spi_master * fsl_spi_probe(struct device *dev, master->setup = fsl_spi_setup; master->cleanup = fsl_spi_cleanup; + master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16) | + SPI_BPW_MASK(32); mpc8xxx_spi = spi_master_get_devdata(master); mpc8xxx_spi->spi_do_one_msg = fsl_spi_do_one_msg;