From patchwork Sun Nov 13 22:02:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 81975 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp748274qge; Sun, 13 Nov 2016 14:02:52 -0800 (PST) X-Received: by 10.99.55.79 with SMTP id g15mr24649953pgn.65.1479074572163; Sun, 13 Nov 2016 14:02:52 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w10si1090203pgo.111.2016.11.13.14.02.51; Sun, 13 Nov 2016 14:02:52 -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; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964791AbcKMWCv (ORCPT + 4 others); Sun, 13 Nov 2016 17:02:51 -0500 Received: from mail-lf0-f45.google.com ([209.85.215.45]:35935 "EHLO mail-lf0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964784AbcKMWCu (ORCPT ); Sun, 13 Nov 2016 17:02:50 -0500 Received: by mail-lf0-f45.google.com with SMTP id t196so46282507lff.3 for ; Sun, 13 Nov 2016 14:02:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=VM99ZvSEC3m2n1xn8s3siC3ltSjv/9vBR1hSVnmPlpg=; b=MwJvUKit4VKv+7386EmUEK+GgoZUikoiq9kPP+0rCBFMXH0p7su5T0FHCyi0oQWbdS I/zi2oNqJwnNh11m91uWUVv/X7DIdlYkqNX43ujiIp6VViluHexHT7qIlBW+Djj1qd/y Ug9ZQhvJTdmgOvvtj/EKhBanF8n3XGPtiE5/g= 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=VM99ZvSEC3m2n1xn8s3siC3ltSjv/9vBR1hSVnmPlpg=; b=FKqcxqxfvaLBKgXoIkobhJiw7OtsQTH2kPeDvX2myGrFF90YwCTLX6FR/qe9nOq35D zqOvOYwwYIZMKPLJoemxWT++cd+Vqx9U4Ngkiciycm/aAhrRxAgtAJ7gQOc3fnwXqNA9 KSj7oom/lEYrE7TBaT7WnSokpKtumKiQ1XCVJUJM+FkwcWwT7vBlnc25K0j47x5PCbH+ 9DcwxJ8iBJG4NUe5szzwP7gM5gtBbmk0OBp8T6gRD6mB+T+7kpLjzoXfGCCLn0OrT87T MLSqXL4/0pB9C+LEPHwckESkHCxWBP7JfUGYlfk9GkcjJp/YH1YQTmi1xSy6OzeklBxT YhHg== X-Gm-Message-State: ABUngvcXvy2QRkenMR9YWCOWjVDUqlfj4kH3FOu7DgxAnH1b4lkzuorRQLkbseJFNPEXhEfc X-Received: by 10.25.202.6 with SMTP id a6mr6854190lfg.30.1479074568460; Sun, 13 Nov 2016 14:02:48 -0800 (PST) Received: from fecusa.localdomain (c-357171d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.113.53]) by smtp.gmail.com with ESMTPSA id e37sm4524311lji.42.2016.11.13.14.02.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Nov 2016 14:02:47 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot Cc: Linus Walleij Subject: [PATCH] gpio: clamp values on gpio[d]_direction_output() Date: Sun, 13 Nov 2016 23:02:44 +0100 Message-Id: <1479074564-5466-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org I saw weird values != [0,1] being passed down to drivers in their .set_direction_output() callbacks. Go over the gpiolib and make sure to hammer it to [0,1] before hitting the driver to avoid undesired side effects. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) -- 2.7.4 -- 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/gpiolib.c b/drivers/gpio/gpiolib.c index 4575c2c5f293..26ce0743adae 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2150,6 +2150,7 @@ EXPORT_SYMBOL_GPL(gpiod_direction_input); static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value) { struct gpio_chip *gc = desc->gdev->chip; + int val = !!value; int ret; /* GPIOs used for IRQs shall not be set as output */ @@ -2169,7 +2170,7 @@ static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value) goto set_output_value; } /* Emulate open drain by not actively driving the line high */ - if (value) + if (val) return gpiod_direction_input(desc); } else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { @@ -2180,7 +2181,7 @@ static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value) goto set_output_value; } /* Emulate open source by not actively driving the line low */ - if (!value) + if (!val) return gpiod_direction_input(desc); } else { /* Make sure to disable open drain/source hardware, if any */ @@ -2198,10 +2199,10 @@ static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value) return -EIO; } - ret = gc->direction_output(gc, gpio_chip_hwgpio(desc), value); + ret = gc->direction_output(gc, gpio_chip_hwgpio(desc), val); if (!ret) set_bit(FLAG_IS_OUT, &desc->flags); - trace_gpio_value(desc_to_gpio(desc), 0, value); + trace_gpio_value(desc_to_gpio(desc), 0, val); trace_gpio_direction(desc_to_gpio(desc), 0, ret); return ret; } @@ -2241,6 +2242,8 @@ int gpiod_direction_output(struct gpio_desc *desc, int value) VALIDATE_DESC(desc); if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) value = !value; + else + value = !!value; return _gpiod_direction_output_raw(desc, value); } EXPORT_SYMBOL_GPL(gpiod_direction_output); @@ -3097,7 +3100,7 @@ static int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, /* Process flags */ if (dflags & GPIOD_FLAGS_BIT_DIR_OUT) status = gpiod_direction_output(desc, - dflags & GPIOD_FLAGS_BIT_DIR_VAL); + !!(dflags & GPIOD_FLAGS_BIT_DIR_VAL)); else status = gpiod_direction_input(desc);