From patchwork Fri Dec 11 21:36:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 58310 Delivered-To: patch@linaro.org Received: by 10.112.73.68 with SMTP id j4csp141341lbv; Fri, 11 Dec 2015 13:36:25 -0800 (PST) X-Received: by 10.98.31.216 with SMTP id l85mr5154962pfj.132.1449869784952; Fri, 11 Dec 2015 13:36:24 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 81si3221773pfr.79.2015.12.11.13.36.24; Fri, 11 Dec 2015 13:36:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753374AbbLKVgY (ORCPT + 4 others); Fri, 11 Dec 2015 16:36:24 -0500 Received: from mail-lb0-f171.google.com ([209.85.217.171]:33755 "EHLO mail-lb0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753058AbbLKVgX (ORCPT ); Fri, 11 Dec 2015 16:36:23 -0500 Received: by lbbkw15 with SMTP id kw15so77682013lbb.0 for ; Fri, 11 Dec 2015 13:36:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=wwG8UAWRseE53yrjsHeCq5zkDGbhOTGLU9q7JxwloO4=; b=m8S9WXZV8frONaDHxnev0SAMC3JzsZ+jx92vliXA2/AXY4Rf3+ys3ikJnzoc7ieXIZ TqYsgJrtnoG9PX869XAyppv3bN4BfGEh4f8ObrGCZ9zo6xPTd6wf6pdIIcrpaJxyEIFO 1KrSvWT8zq8TME0xDOUKxa2PoVyBPpnMxcrRMyogTgLQk/rjNwab9GmatXKZuJr2VRCv 619C9LP9lZsjxJnFZGfzbXV7uAl/RORI4XvkJiw2TVQNxyIKUFm6f2xytar7FG7OZaMH dNL4Vg55JyUnk5SLqQJXMJHJlEvD4cZ5P+tgutM0bZEMsDKrLSaR+5afwJO8wQGNZQyK fO4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=wwG8UAWRseE53yrjsHeCq5zkDGbhOTGLU9q7JxwloO4=; b=XYKaNtyxywp+8diGO5uqG/ItCyt7sDFKa61ixriQLRsHrESeZvL38zjGMmtqOIE+g8 1g2P1r1ZQ6EPRRhL99jfPnFNXlX4SiPyL+56/wqdMNY9TvpQH00DtvHGD9ExoOiwalSW 5jAvM5uXCi3+ifXaSKs732Eer7pY/Lm4ztW/m8VSUpa0tcDFT8BpOuAUCrdjbKpez6s0 0CUXC+EjuW83OWNl8IPOfvLf02VOlIG0vLXiHoLv2shWQMWiFmjaBgXKQZ7MsCNb+o44 GzajpUdr9miqEjq+4gKP6OzWUGdWm61WJvAgUdQf2F8iOxbvtvzIcPnAxbnM/LOC9awi BX6g== X-Gm-Message-State: ALoCoQnAuK3Cx7e0wgN/pc8mGOdKMQpPFVPWawQgVZDp4J0yLxh6qHp+BJ1ZBx05oL7KGI9ivCEdQkAK95xxpmJLiTBA+UL/qw== X-Received: by 10.112.166.102 with SMTP id zf6mr9044347lbb.75.1449869782209; Fri, 11 Dec 2015 13:36:22 -0800 (PST) Received: from localhost.localdomain.localdomain (c-297471d5.01-192-6c756e10.cust.bredbandsbolaget.se. [213.113.116.41]) by smtp.gmail.com with ESMTPSA id h82sm1668893lfh.27.2015.12.11.13.36.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Dec 2015 13:36:21 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot Cc: Linus Walleij , kernel@pengutronix.de, Vladimir Zapolskiy Subject: [PATCH] gpio: generic: clamp values from bgpio_get_set() Date: Fri, 11 Dec 2015 22:36:18 +0100 Message-Id: <1449869778-6974-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The bgpio_get_set() call should return a value clamped to [0,1], the current code will return a negative value if reading bit 31, which turns the value negative as this is a signed value and thus gets interpreted as an error by the gpiolib core. Found on the gpio-mxc but applies to any MMIO driver. Fixes: b19e7f51a55f "gpio: gpio-generic: add flag to read out output value from reg_set" Cc: kernel@pengutronix.de Cc: Vladimir Zapolskiy Reported-by: Clemens Gruber Signed-off-by: Linus Walleij --- drivers/gpio/gpio-generic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" 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/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c index 72088028d7a9..ea581dc23d44 100644 --- a/drivers/gpio/gpio-generic.c +++ b/drivers/gpio/gpio-generic.c @@ -141,9 +141,9 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio) unsigned long pinmask = bgc->pin2mask(bgc, gpio); if (bgc->dir & pinmask) - return bgc->read_reg(bgc->reg_set) & pinmask; + return !!(bgc->read_reg(bgc->reg_set) & pinmask); else - return bgc->read_reg(bgc->reg_dat) & pinmask; + return !!(bgc->read_reg(bgc->reg_dat) & pinmask); } static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)