From patchwork Fri Nov 7 17:11:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Torsten Fleischer X-Patchwork-Id: 5254641 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 20CF39F3ED for ; Fri, 7 Nov 2014 17:12:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6D42B20122 for ; Fri, 7 Nov 2014 17:12:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D72B2010C for ; Fri, 7 Nov 2014 17:12:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751876AbaKGRML (ORCPT ); Fri, 7 Nov 2014 12:12:11 -0500 Received: from mail-wi0-f182.google.com ([209.85.212.182]:48179 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751480AbaKGRMJ (ORCPT ); Fri, 7 Nov 2014 12:12:09 -0500 Received: by mail-wi0-f182.google.com with SMTP id d1so5182479wiv.9 for ; Fri, 07 Nov 2014 09:12:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=4EKSDgMQIaWld2VggPI5oIcqw64/Jk5ilTeaYDyw2LQ=; b=P/UZdjeBqcNmbLStCSnmjtMXJsiilKL5PCoeGMKvlBlQco8zQvsOkjKTTwmMFbl00v An3TZ+9zGBpbqhkLJpw5zSXdE27el1iHeOLnupGDVdlGwEkvdFBthr2n6+g7tdkR803d SsMyhMfKyLFVylWVKN9Oz5hZ4trnA39kxk2d6Q8S8vNELxtkNpMPistNolo2FAp2vkG9 Z0VvG22kmGolCtS3JVFgjY38kYHdT37OjOrmCKyyrZK0pqwE3WlQupb07fJc3IW5uk/Z ijU9hPDP116DfJLb2zyoguX4bMu73bEmmYFb2ssw1pxmIWAA/5e3GTxs/hLBUS5LX/Jr LGtg== X-Received: by 10.180.81.70 with SMTP id y6mr7188331wix.6.1415380326471; Fri, 07 Nov 2014 09:12:06 -0800 (PST) Received: from linux-1fbo.site.Speedport_W723_V_Typ_A_1_01_009 (p579AB0CA.dip0.t-ipconnect.de. [87.154.176.202]) by mx.google.com with ESMTPSA id bq8sm12520493wjb.6.2014.11.07.09.12.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Nov 2014 09:12:05 -0800 (PST) From: Torsten Fleischer X-Google-Original-From: Torsten Fleischer To: Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Torsten Fleischer Subject: [PATCH 1/1] spi: spi-gpio: Fix compiler warning when building for 64 bit systems Date: Fri, 7 Nov 2014 18:11:58 +0100 Message-Id: <1415380318-2065-1-git-send-email-torfl6749@gmail.com> X-Mailer: git-send-email 1.8.4.5 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.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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 From: Torsten Fleischer The assignment of SPI_GPIO_NO_CHIPSELECT to cs_gpios[0] causes the following compiler warning, when building for 64 bit systems: "warning: overflow in implicit constant conversion [-Woverflow]". This is because the SPI_GPIO_NO_CHIPSELECT flag is a '-1' type casted to unsigned long and cs_gpios is of the type int. Furthermore the chip select's GPIO number is locally stored as unsigned int and compared with SPI_GPIO_NO_CHIPSELECT. Thus the result of the comparison is always false, if unsigned long and unsigned int have a different size. As part of the fix this patch adds a check for the device tree's cs-gpios property. Reported-by: kbuild test robot Signed-off-by: Torsten Fleischer --- drivers/spi/spi-gpio.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index f0492c9..4b600d4 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -48,7 +48,7 @@ struct spi_gpio { struct spi_bitbang bitbang; struct spi_gpio_platform_data pdata; struct platform_device *pdev; - int cs_gpios[0]; + unsigned long cs_gpios[0]; }; /*----------------------------------------------------------------------*/ @@ -220,7 +220,7 @@ static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi, static void spi_gpio_chipselect(struct spi_device *spi, int is_active) { struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); - unsigned int cs = spi_gpio->cs_gpios[spi->chip_select]; + unsigned long cs = spi_gpio->cs_gpios[spi->chip_select]; /* set initial clock polarity */ if (is_active) @@ -234,7 +234,7 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active) static int spi_gpio_setup(struct spi_device *spi) { - unsigned int cs; + unsigned long cs; int status = 0; struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); struct device_node *np = spi->master->dev.of_node; @@ -249,7 +249,7 @@ static int spi_gpio_setup(struct spi_device *spi) /* * ... otherwise, take it from spi->controller_data */ - cs = (unsigned int)(uintptr_t) spi->controller_data; + cs = (uintptr_t) spi->controller_data; } if (!spi->controller_state) { @@ -277,7 +277,7 @@ static int spi_gpio_setup(struct spi_device *spi) static void spi_gpio_cleanup(struct spi_device *spi) { struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); - unsigned int cs = spi_gpio->cs_gpios[spi->chip_select]; + unsigned long cs = spi_gpio->cs_gpios[spi->chip_select]; if (cs != SPI_GPIO_NO_CHIPSELECT) gpio_free(cs); @@ -437,7 +437,7 @@ static int spi_gpio_probe(struct platform_device *pdev) return status; master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) + - (sizeof(int) * num_devices)); + (sizeof(unsigned long) * num_devices)); if (!master) { status = -ENOMEM; goto gpio_free; @@ -470,9 +470,15 @@ static int spi_gpio_probe(struct platform_device *pdev) if (!SPI_N_CHIPSEL) spi_gpio->cs_gpios[0] = SPI_GPIO_NO_CHIPSELECT; else - for (i = 0; i < SPI_N_CHIPSEL; i++) - spi_gpio->cs_gpios[i] = - of_get_named_gpio(np, "cs-gpios", i); + for (i = 0; i < SPI_N_CHIPSEL; i++) { + status = of_get_named_gpio(np, "cs-gpios", i); + if (status < 0) { + dev_err(&pdev->dev, + "invalid cs-gpios property\n"); + goto gpio_free; + } + spi_gpio->cs_gpios[i] = status; + } } #endif