From patchwork Tue Jan 5 08:27:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 356798 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp15620701jai; Tue, 5 Jan 2021 00:30:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxA15buUTL7zizeU0udN+VrKl4L5ZjZoFf4B+itkN7izqArpoS4poPTvWQijCSiPc51Jptg X-Received: by 2002:a05:6402:2074:: with SMTP id bd20mr20629480edb.326.1609835444119; Tue, 05 Jan 2021 00:30:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609835444; cv=none; d=google.com; s=arc-20160816; b=l1mvI3pjaGQgOkk7X1VdipGPX1jc25urQqTRvnT+gxdmm0DcffCN4ffXA7rrXR6rTt avtZVcH6md/ZgCvyZPMiDCYgHSUO6N8hTwWDVkVNXdZ0NQFTRFErS3QyubxAyaec2/4E VQYr9V7Nj01nLKC/921zx1IiNF4nmJuN0EyDeQTgPSL3z6ypZottHliI8sJHZbs80d0Z 3R3m6AAX2ec6MqhbBnJUPAx8qmlZbWrOQvja8PzK+mqowivi6Pzl34yWFzJbVJB98VP0 7oVEDgtob7ok3FsfkDcBrf6unN9sEDXnnTjfTHcKRhAWPeT7ZWR6D7e/r1wbVB+7rlJy z1rg== 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=XCq0CKJP4XYbct7XxQnom8AWCp4/ufcTG2LyUmvpIA8=; b=JoeX3ylf8AV77rLRjavWZ1de8ur748Ikfc7MFjHDzZp6dGeNtgteClLug2otQr62WI l0mp0Dny4R0Yt82h1xy6NInSfvCDVFNOjKaRwQmOE+rC6mF8Liu2Dm2P7s1zCO7q0B6o 31j65Sa4f1ICpYiEM0AtCU54C5uV6zTWjpeZyIuB8H19b1aChBkK5xdBgFpY5RwoOE6l cZFqrJ0Cu1mBF09FvVx7JZVhvqWUu9OfplOMKXcxWwSRNdooN05BuXoi6+juKdVH6AOK VBotl9AfZkaziY3RehbBeLLuOXJPHDvQ421vIeEXUlMr6Cxo8CFNkIDH7KhWH/96OqIF WD0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZPm2Hr2X; 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 h14si29086825eji.737.2021.01.05.00.30.43; Tue, 05 Jan 2021 00:30:44 -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=ZPm2Hr2X; 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 S1726599AbhAEIan (ORCPT + 3 others); Tue, 5 Jan 2021 03:30:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726097AbhAEIan (ORCPT ); Tue, 5 Jan 2021 03:30:43 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2324C061574 for ; Tue, 5 Jan 2021 00:30:02 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id m25so70637515lfc.11 for ; Tue, 05 Jan 2021 00:30:02 -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=XCq0CKJP4XYbct7XxQnom8AWCp4/ufcTG2LyUmvpIA8=; b=ZPm2Hr2X2vPGAyPcI7KHmRgkr0eHtHGQUn3j9XaU9d08RLW3zjTKj43ziKpiGgHuZz SM0FEUX9cmSkF0VpLBL4rxi5DAXynqbRorYZkoPJ8hqvczTlyuCJC9ecGq0Umohv57Zb T+6Cr+QKQ6h9oWrxBiLnSUKbmYNOGPTvl/SlumI1quycB5kMzzFPX8Z+hEdc7gK2uD1m QfVGcBehO2pmlIufsqFHxAn11MF0rNY/R2xxAoasfLPiVcbOmiH2Tgy5JyTdr2uGNz8W c/4IJeOy1c5FostLAmCCVQ18dk23uMUT++4YEbUeTRPrqiUoHZT1b3RyMhjqr/bWiecG lLIA== 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=XCq0CKJP4XYbct7XxQnom8AWCp4/ufcTG2LyUmvpIA8=; b=WUO62M6ATmCrrJylDyvt/IOzUEud2gNHygz4hFM0eOIVUrtT71psAzA/b/WvSuh9oK iJNsI4zd8dvclupsJZeiNQgc7z31E9VXcvYZkjnivTHS4tM/5N5HdCCqacHOniQoTw3E MEkwsvnYxh2r1XgrKLj9GAcQjPOLEnvHjzOV6jWn7klYJaXTvAxkRzllrg0CxppxiSdG +zJHG8Vs7MGZVWnDzzMz+ACf3t4BBU1sUQG8J3epbCh2+qOBXmaZncxoMbfryL9tvl2B +1hgIpr5Cwk+TusFL6fqiP5O0087xpcODE6lAXz4YsXRyX08PYhu7Assl+z0VHRCY+QY EsEw== X-Gm-Message-State: AOAM530BsYaXX7/SKBGBANfvPQsWFoBukvA6eVoa+rHFkU69Xas0v6uh jof/C92g9bik71wny0rFM8de23oh5FzSRw== X-Received: by 2002:a05:651c:124c:: with SMTP id h12mr39358378ljh.294.1609835401016; Tue, 05 Jan 2021 00:30:01 -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 c25sm7559778lfm.52.2021.01.05.00.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 00:30:00 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Bartosz Golaszewski , Linus Walleij , Geert Uytterhoeven , Johan Hovold Subject: [PATCH v2] gpiolib: Disallow identical line names in the same chip Date: Tue, 5 Jan 2021 09:27:58 +0100 Message-Id: <20210105082758.77762-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.29.2 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. This does not affect device tree and other gpiochips that get named from device properties: the uniqueness per-chip however affect all hotplugged devices such as GPIO expanders on USB. Cc: Geert Uytterhoeven Cc: Johan Hovold Link: https://lore.kernel.org/r/20201212003447.238474-1-linus.walleij@linaro.org [Dropped warning for globally unique] Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Do NOT enforce unique line names on device tree instances. Devicetrees know what they are doing and will make sure not to create conflicting naming. --- drivers/gpio/gpiolib.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) -- 2.29.2 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index b02cc2abd3b6..8c0c8c5306d2 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,14 @@ 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) - dev_warn(&gdev->dev, - "Detected name collision for GPIO name '%s'\n", - gc->names[i]); + gpiod = gpio_name_to_desc(gc->names[i]); + if (gpiod && (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 -EEXIST; + } } /* Then add all names to the GPIO descriptors */