From patchwork Sat Dec 12 00:34:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 342865 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp1046572jai; Fri, 11 Dec 2020 16:39:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzajjx7xbVBOBV8uvtg9+jmyZp7vetY1G73ix2vdWlOhb+NKSeGDYRy/IJPxTXhw2yVI13K X-Received: by 2002:a05:6402:202e:: with SMTP id ay14mr14982677edb.102.1607733553731; Fri, 11 Dec 2020 16:39:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607733553; cv=none; d=google.com; s=arc-20160816; b=Y9M7GiQ/3IS9EHnTjueMaVLhnswKxXWkeDKlOoGF9EvSYj1u67R5hqRvjmthkXmDpN dv15dxAxqiimyYKL1GffaX/tAVi+ke2Nb/g37DxuRevEFT8cLVTiQAMmMI5lAxga9ZDw lJeE5zm4CYtF5+la8/Xv81asgB20wkgQ+psZWow7YWSGajgIdLmhRVrgkxNtstP3Lsu/ YirOnsPzccmxiuUt+/liFmSQc/w4eaO8MiedOKKpPqxt8Nc3BYCAc1H/tGTBWwfu0jRW cc8mqUvJju8citPR2S//pyXzGCgRXQz1SCrOUfYljqyDSk2mhmIDY5lqZWfWZ/+R0JXk 1p3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ttjqXhxQi+pNizwAm4tpfBYhH9e2m0KKEEwUkI5pPkw=; b=DUv1Kwr1k3iFZQUdiUvbQBkPwmUELrtYPQTVVVnT5UEVg0RdCrTKwjE6KiRG2Dv+QG QIitD2AjTIvAtNQsGyvLuDZ/XxvPIhD6LtqV2no2tgVQx7CwpmxnPw/RZGJKfh3hNgbl 1iTcUnTPUr1PtJh8RZtb35ZBUoftUIlX0Cy/XJOVElIlTSPxCq3eqrtUecx700g0HrM1 UewSxz3KrnPrhNQIiZ6t1Xmh5nz86rkelJ9SLk14E3UtKj69QmU3owLjIkMfXjYamlcg qjxqLpvfn8ONkV3P94XpZ4T4YXe+1qvI5pH16cJ7PZJIQkBI1xZLiuqz6KvH9Jsv4WKL Uuqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=V4rIX9tG; spf=pass (google.com: domain of linux-gpio-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id c22si5513453ejx.290.2020.12.11.16.39.13; Fri, 11 Dec 2020 16:39:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-gpio-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=V4rIX9tG; spf=pass (google.com: domain of linux-gpio-owner@vger.kernel.org designates 23.128.96.18 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 S1728503AbgLLAhx (ORCPT + 3 others); Fri, 11 Dec 2020 19:37:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437765AbgLLAhc (ORCPT ); Fri, 11 Dec 2020 19:37:32 -0500 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1E78C0613D3 for ; Fri, 11 Dec 2020 16:36:51 -0800 (PST) Received: by mail-lf1-x144.google.com with SMTP id 23so15847632lfg.10 for ; Fri, 11 Dec 2020 16:36:51 -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:mime-version :content-transfer-encoding; bh=ttjqXhxQi+pNizwAm4tpfBYhH9e2m0KKEEwUkI5pPkw=; b=V4rIX9tGub7KABlVbhEWkOc8JyvTIimSGi9ZCxXgEZXicY8lL22Tl+8wTUixpT+KJd MpCVltyw5Y6xAKfXa8Zn7UD78JWuknfQtyceOftl7xEY7r1HuFI5NrI1FW928ihY1onJ +o24L3HgNMdhfBhCqY/9YAXGj0h1eFxHMXYpXxZie/Z0EOHV5IX/oF5qJEq2WOcV+OKN XFE0Nn1DjkxIDVOgJZTGTuWi9Px2Pav3TIh9iVJjFweC6L3wke4qPCI02F9jztRcPEbK pI4noO24N4EB+oqhpUgZ6Vys74oViN6siVIka5EoXXFK04XkQRnu9eVN1L9ICWxW+duT xRgw== 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=ttjqXhxQi+pNizwAm4tpfBYhH9e2m0KKEEwUkI5pPkw=; b=WKGIFtRNgWAWEmqOUepc0QaYfR5fZuETDmiiwVyJu72ULUBncJHjFz0v2uVBsSXYJo HFaN7BiU9MGxpeJKyOoRm/7+2bNJ8xIOe2WCsBBSE76Mc/PMPucf8O2uo+QNpcQYJH4W 9B9KEvy2D6zCHVEPJ0LClQvgDVQb8HLxMUvYqN2ASmFl7xx4+inj58kJHqh11ZkFeN/0 1WpyMMrmBwNtMbUcK/JrbQ2C1xefnQoLSnjOVgo7C2wgBZZeMKKTQIv3gXgAJ9eaE/la 84h4N9fmve7viZehyWi3lhQ+JnfihwjKH3QaJRpiyy9Yj5PEJunHYQZ7JQakONg+CYCR W4uw== X-Gm-Message-State: AOAM530neryfCOiYtje8mBoyMg+ucggP/szA7T5DGldalRJgoxkNRsyD HNSg+dfOikEHa3VlIOLIQpVQYJVY6YbbQMnw X-Received: by 2002:a2e:5018:: with SMTP id e24mr6218830ljb.425.1607733410214; Fri, 11 Dec 2020 16:36:50 -0800 (PST) Received: from localhost.localdomain (c-92d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.146]) by smtp.gmail.com with ESMTPSA id i29sm1053519lfc.193.2020.12.11.16.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 16:36:49 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Bartosz Golaszewski , Linus Walleij , Geert Uytterhoeven , Johan Hovold Subject: [PATCH] gpiolib: Disallow identical line names in the same chip Date: Sat, 12 Dec 2020 01:34:47 +0100 Message-Id: <20201212003447.238474-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org We need to make this namespace hierarchical: at least do not allow two lines on the same chip to have the same name, this is just too much flexibility. If we name a line on a chip, name it uniquely on that chip. I don't know what happens if we just apply this, I *hope* there are not a lot of systems out there breaking this simple and intuitive rule. As a side effect, this makes the device tree naming code scream a bit if names are not globally unique. I think there are not super-many device trees out there naming their lines so let's fix this before the problem becomes widespread. Cc: Geert Uytterhoeven Cc: Johan Hovold Signed-off-by: Linus Walleij --- This may be just the first step in tightening this up. Googling gives at hand that the colission warning doesn't happen much so we might go as far as to say the name can be required to be globally unique, but that creates a flat namespace so I don't know if that is desireable. --- drivers/gpio/gpiolib.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) -- 2.28.0 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 5ce0c14c637b..be4b3e9032b2 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -330,11 +330,9 @@ static struct gpio_desc *gpio_name_to_desc(const char * const name) /* * Take the names from gc->names and assign them to their GPIO descriptors. - * Warn if a name is already used for a GPIO line on a different GPIO chip. * - * Note that: - * 1. Non-unique names are still accepted, - * 2. Name collisions within the same GPIO chip are not reported. + * - Fail if a name is already used for a GPIO line on the same chip. + * - Allow names to not be globally unique but warn about it. */ static int gpiochip_set_desc_names(struct gpio_chip *gc) { @@ -343,13 +341,19 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) /* First check all names if they are unique */ for (i = 0; i != gc->ngpio; ++i) { - struct gpio_desc *gpio; + struct gpio_desc *gpiod; - gpio = gpio_name_to_desc(gc->names[i]); - if (gpio) + gpiod = gpio_name_to_desc(gc->names[i]); + if (gpiod) { dev_warn(&gdev->dev, "Detected name collision for GPIO name '%s'\n", gc->names[i]); + if (gpiod->gdev == gdev) { + dev_err(&gdev->dev, + "GPIO name collision on the same chip, this is not allowed, fix all lines on the chip to have unique names\n"); + return -EINVAL; + } + } } /* Then add all names to the GPIO descriptors */ @@ -402,8 +406,22 @@ static int devprop_gpiochip_set_names(struct gpio_chip *chip) return ret; } - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { + struct gpio_desc *gpiod; + + gpiod = gpio_name_to_desc(names[i]); + if (gpiod) { + dev_warn(&gdev->dev, + "Detected name collision for GPIO name '%s'\n", + names[i]); + if (gpiod->gdev == gdev) { + dev_err(&gdev->dev, + "GPIO name collision on the same chip, this is not allowed, fix all lines on the chip to have unique names\n"); + return -EINVAL; + } + } gdev->descs[i].name = names[i]; + } kfree(names);