From patchwork Wed Jul 31 22:42:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 170271 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4575214ile; Wed, 31 Jul 2019 15:42:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPE3OnpVP/gjBWbjsaQDv/ntIjwJYP32+57QKSvaNKXshs4oaSvkq5DqCW0lDpbfiO5fhw X-Received: by 2002:aa7:8b52:: with SMTP id i18mr50544708pfd.194.1564612936813; Wed, 31 Jul 2019 15:42:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564612936; cv=none; d=google.com; s=arc-20160816; b=nSx4IjZj6T83/ulzb9mSD0YEKDWvcF7GYl4nAYD7cfoxhjLSRujrpA39KpVDUkFvFJ g79TPnXlDeyLo4Q/vFpwzMeNxVf+47a340XsTxGNotjj4d6skXp6zCNTi+cHq7B6/h8B ERWw8xcZvkd57wSpieh4uND3Wio01dgDO6V/WJffJb/Yv06zls6mYN5YV7xOMlFa96H+ UF2hjDBkuxaCkhDLEXNFpDOlDQDrgFiGsogEr6dUPhJ4p86pil98mBK+wy6+358sauiG oZyELR+T3MFM8KZIOUTEvfm+ohmg8CU7FFOe5wtLntQ1kMxDoic/G9Jod0zvvcwMKurh FKcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ssponi8HFghnoIL2FD87rDXrsR8CDf6ns5qoDwZ/ELA=; b=HA2mCoKcgC8/aZJt/aBMRR6Kq6AUCcpULk5HdbEsjCSO3yERc4D9PbiIELEMhmn0SO Xp3+f6CFyBSVIiWvo4BqbDlc5+9t1pmiKiEr1Gm5ZnpX+BFG/iafTt2ui/ySYV3zkhjK hBDyu4aSw3KGqBaiqbJ+zaKSWAvj1/nw8ozsB7xQhXXQtJEA12nQKypuJSZW+cvznRte WSaEtA66Mvv1bKllvVxSVkLT/ynCDpm189PuIe1yRzDNzAYD10iwOP1XC3EqEJH4tHFN jDwnG1LW6CI9PLOwJaIkezZeb0dasJWYVo220VjVuKTBiIZ4Svyxenqv6W7Kn4pJS1oQ nxhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m6MjpgSK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a19si24465017pgv.180.2019.07.31.15.42.16; Wed, 31 Jul 2019 15:42:16 -0700 (PDT) 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=pass header.i=@linaro.org header.s=google header.b=m6MjpgSK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729578AbfGaWmQ (ORCPT + 5 others); Wed, 31 Jul 2019 18:42:16 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:32977 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727837AbfGaWmP (ORCPT ); Wed, 31 Jul 2019 18:42:15 -0400 Received: by mail-lf1-f66.google.com with SMTP id x3so48742063lfc.0 for ; Wed, 31 Jul 2019 15:42:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ssponi8HFghnoIL2FD87rDXrsR8CDf6ns5qoDwZ/ELA=; b=m6MjpgSKUn4CX7tquDk3cuP97sYkSjQEaxRtS0He/0ahxlj/SpRCRz/CoOU2Cbh2xn W6P16tYTC2Q4jdlK5+YJY2UJQ1OKVvh/P4JSd3VybD3eXP68y0vJ14/2WjZZxsNz7dTd CGifXklsMSD5Q7EXAYeZqVIG67I18CgwwSvtjNxiEzlbOaK49UnjabjjD4QZCPVpQRU9 aMeVO0yDtEkvw9rYWI/yAvk05PwqjVmxMZs/g31OcjxZe+KKrwYvFZLekgeQzbGOs6aa DpKAxxdteO+Rc8eQyit3RG90XRmuHgENlOnFJNslP8em0OHayfsfJRcM/cb34W0xzAK6 o3bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ssponi8HFghnoIL2FD87rDXrsR8CDf6ns5qoDwZ/ELA=; b=PQdPL0hMqDUagQ2Le9dZUQWzWJCVeieYZ2eleV9eO9hDpF+A5WLK/6ckhZW96Hadzl 8QKMep/w7t8bVpfkFhasPlDhvX+ymH0OVztNzohir2P37bEMMoUuurZ4Le8THFn9VqQU qMoKoLHrcPNrOZ9BIvjxyhOumqHRlvOBQIubLpI9ANdTVjw/yzLFFZx9PxdlSSMni1pE Xsjlqp02fC2NINEnvVPlSMvEdMbobitfnOtXyOfqw567VWmvRwevsQwl9QSn+TFRdilZ h2H437MjO/6zmm7JnIPpMhcwqhWnsOHQFRTGG9WD80niNi3enS2aPMvYShcz/nsE4neR jO2w== X-Gm-Message-State: APjAAAVmvUwzQRZHWcP7Vu/083Kz/Lr0mb1/712hTMv76NANYyAneTLJ FX4kChDwht8EcvVyat/Fv/bWNou9L48= X-Received: by 2002:ac2:414d:: with SMTP id c13mr8411385lfi.47.1564612934013; Wed, 31 Jul 2019 15:42:14 -0700 (PDT) Received: from genomnajs.lan (94-137-108-110.customers.ownit.se. [94.137.108.110]) by smtp.gmail.com with ESMTPSA id p76sm14189708ljb.49.2019.07.31.15.42.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 15:42:12 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Bartosz Golaszewski , Stephen Boyd , Mark Brown , Bjorn Andersson , Linus Walleij Subject: [PATCH] gpio: of: Fix hard-assigned valid_mask for OF case Date: Thu, 1 Aug 2019 00:42:08 +0200 Message-Id: <20190731224208.30429-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Stephen Boyd The recent refactoring to break out OF code to its own file contained a bug by yours truly letting the need_valid_mask be overridden by the need of the device tree range check, and if there were no ranges, but device tree was active and the reserved GPIO used in another way, things likely crash. Cc: Mark Brown Cc: Bjorn Andersson Cc: Stephen Boyd Reported-by: Mark Brown Suggested-by: Stephen Boyd Signed-off-by: Stephen Boyd Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib-of.c | 2 +- drivers/gpio/gpiolib-of.h | 4 ++-- drivers/gpio/gpiolib.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) -- 2.21.0 diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index b10d04dd9296..e39b4290b80c 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -87,7 +87,7 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, * @dev: the device for the GPIO provider * @return: true if the valid mask needs to be set */ -bool of_gpio_need_valid_mask(struct gpio_chip *gc) +bool of_gpio_need_valid_mask(const struct gpio_chip *gc) { int size; struct device_node *np = gc->of_node; diff --git a/drivers/gpio/gpiolib-of.h b/drivers/gpio/gpiolib-of.h index 34954921d96e..454d1658ee2d 100644 --- a/drivers/gpio/gpiolib-of.h +++ b/drivers/gpio/gpiolib-of.h @@ -16,7 +16,7 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, int of_gpiochip_add(struct gpio_chip *gc); void of_gpiochip_remove(struct gpio_chip *gc); int of_gpio_get_count(struct device *dev, const char *con_id); -bool of_gpio_need_valid_mask(struct gpio_chip *gc); +bool of_gpio_need_valid_mask(const struct gpio_chip *gc); #else static inline struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, @@ -36,7 +36,7 @@ static inline int of_gpio_get_count(struct device *dev, const char *con_id) { return 0; } -static inline bool of_gpio_need_valid_mask(struct gpio_chip *gc) +static inline bool of_gpio_need_valid_mask(const struct gpio_chip *gc) { return false; } diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f83870a18ae7..20f13129cdaa 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -363,8 +363,8 @@ static unsigned long *gpiochip_allocate_mask(struct gpio_chip *chip) static int gpiochip_alloc_valid_mask(struct gpio_chip *gc) { - if (IS_ENABLED(CONFIG_OF_GPIO)) - gc->need_valid_mask = of_gpio_need_valid_mask(gc); + if (of_gpio_need_valid_mask(gc)) + gc->need_valid_mask = true; if (!gc->need_valid_mask) return 0;