From patchwork Wed Sep 23 23:27:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 54086 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id 65B8822E14 for ; Wed, 23 Sep 2015 23:27:42 +0000 (UTC) Received: by wicmn1 with SMTP id mn1sf32328299wic.1 for ; Wed, 23 Sep 2015 16:27:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=p80GiMHj8QmkaF32PR0CLGqpSuQPNPUlBFTso5KN3Ds=; b=VuQUxfVbzii8CnzSvp3AZj5fpnpPlhsREIw0MCFV/PBCeDz4QrpilD/qRxuRK4Djms JbSUSU6dtot8XADKbqlpesKbawiYZbsIiOmqFw68m0Ja5QU4ucXFCHPO5jOntcp2/9iZ L/Sm2b+e+EaHNr7Lcd4evOtfWKTxHst9OQ+Da9PDoPFWhtgzz09X4H4AbJ3dMgb9iB4f 8JmeaY8W0HIq5dlt39EzsZGFzjKaAS6o6XVMblVT33miLYWGABz6xdHhXtA/U5UGjCjx PXGkOTVyQ+HdLjEk0RYRE330EhG9ffq2ohFDbGYdjvggdbD28dRoW3ADAJpxOfO0Tf+6 1Q9w== X-Gm-Message-State: ALoCoQlkQHGDVLRxeYJU+wS/G5OoQFC9ah0t279h+lHYOc5hLJRCuL1PsV1ysVB32AqLfUxuQ5eD X-Received: by 10.194.93.198 with SMTP id cw6mr5701744wjb.3.1443050861708; Wed, 23 Sep 2015 16:27:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.98 with SMTP id m2ls74165lae.47.gmail; Wed, 23 Sep 2015 16:27:41 -0700 (PDT) X-Received: by 10.112.150.201 with SMTP id uk9mr10786993lbb.102.1443050861416; Wed, 23 Sep 2015 16:27:41 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id du4si5270885lac.145.2015.09.23.16.27.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2015 16:27:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lagj9 with SMTP id j9so68822596lag.2 for ; Wed, 23 Sep 2015 16:27:41 -0700 (PDT) X-Received: by 10.112.35.130 with SMTP id h2mr10822239lbj.36.1443050861289; Wed, 23 Sep 2015 16:27:41 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp37681lbq; Wed, 23 Sep 2015 16:27:40 -0700 (PDT) X-Received: by 10.68.69.17 with SMTP id a17mr40232908pbu.10.1443050859996; Wed, 23 Sep 2015 16:27:39 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nq1si13930968pbc.127.2015.09.23.16.27.39; Wed, 23 Sep 2015 16:27:39 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756174AbbIWX1j (ORCPT + 2 others); Wed, 23 Sep 2015 19:27:39 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:33651 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756172AbbIWX1i (ORCPT ); Wed, 23 Sep 2015 19:27:38 -0400 Received: by pacex6 with SMTP id ex6so53599947pac.0 for ; Wed, 23 Sep 2015 16:27:38 -0700 (PDT) X-Received: by 10.66.175.7 with SMTP id bw7mr41337097pac.155.1443050858051; Wed, 23 Sep 2015 16:27:38 -0700 (PDT) Received: from localhost.localdomain.localdomain ([70.35.39.2]) by smtp.gmail.com with ESMTPSA id pe5sm10013485pac.17.2015.09.23.16.27.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2015 16:27:37 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Alexandre Courbot , Linus Walleij , Johan Hovold , Markus Pargmann Subject: [PATCH] gpio: keep the GPIO line names internal Date: Wed, 23 Sep 2015 16:27:33 -0700 Message-Id: <1443050853-24601-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-gpio@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This refactors the changes to the GPIO line naming mechanism to not have so widespread effects, instead we conclude the patch series by having created a name attribute in the GPIO descriptor, that need not be globally unique, and it will be initialized from the old .names array in struct gpio_chip if it exists, then used in the legacy sysfs code like the array was used previously. The associated changes to name lines from the device tree are controversial and need to stand alone from this. Resulting changes: 1. Remove the export and the header for the gpio_name_to_desc() as so far the only use is inside gpiolib.c. Staticize gpio_name_to_desc() and move it above the only function using it. 2. Only print a warning if there are two GPIO lines with the same name. The reason is to preserve current behaviour: before the previous changes to the naming mechanism this would not reject probing the driver, instead the error would occur when trying to export the line in sysfs, so restore this behaviour, but print a friendly warning if names collide. Cc: Johan Hovold Cc: Markus Pargmann Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 72 +++++++++++++++++++++---------------------- include/linux/gpio/consumer.h | 1 - 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 764845c3a4b2..efe8a1072ed0 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -90,38 +90,6 @@ struct gpio_desc *gpio_to_desc(unsigned gpio) EXPORT_SYMBOL_GPL(gpio_to_desc); /** - * Convert a GPIO name to its descriptor - */ -struct gpio_desc *gpio_name_to_desc(const char * const name) -{ - struct gpio_chip *chip; - unsigned long flags; - - spin_lock_irqsave(&gpio_lock, flags); - - list_for_each_entry(chip, &gpio_chips, list) { - int i; - - for (i = 0; i != chip->ngpio; ++i) { - struct gpio_desc *gpio = &chip->desc[i]; - - if (!gpio->name) - continue; - - if (!strcmp(gpio->name, name)) { - spin_unlock_irqrestore(&gpio_lock, flags); - return gpio; - } - } - } - - spin_unlock_irqrestore(&gpio_lock, flags); - - return NULL; -} -EXPORT_SYMBOL_GPL(gpio_name_to_desc); - -/** * Get the GPIO descriptor corresponding to the given hw number for this chip. */ struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, @@ -250,6 +218,37 @@ static int gpiochip_add_to_list(struct gpio_chip *chip) return err; } +/** + * Convert a GPIO name to its descriptor + */ +static struct gpio_desc *gpio_name_to_desc(const char * const name) +{ + struct gpio_chip *chip; + unsigned long flags; + + spin_lock_irqsave(&gpio_lock, flags); + + list_for_each_entry(chip, &gpio_chips, list) { + int i; + + for (i = 0; i != chip->ngpio; ++i) { + struct gpio_desc *gpio = &chip->desc[i]; + + if (!gpio->name) + continue; + + if (!strcmp(gpio->name, name)) { + spin_unlock_irqrestore(&gpio_lock, flags); + return gpio; + } + } + } + + spin_unlock_irqrestore(&gpio_lock, flags); + + return NULL; +} + /* * Takes the names from gc->names and checks if they are all unique. If they * are, they are assigned to their gpio descriptors. @@ -268,11 +267,10 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) struct gpio_desc *gpio; gpio = gpio_name_to_desc(gc->names[i]); - if (gpio) { - dev_err(gc->dev, "Detected name collision for GPIO name '%s'\n", - gc->names[i]); - return -EEXIST; - } + if (gpio) + dev_warn(gc->dev, "Detected name collision for " + "GPIO name '%s'\n", + gc->names[i]); } /* Then add all names to the GPIO descriptors */ diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 366a3fdbdbea..a879e3e62379 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -130,7 +130,6 @@ int gpiod_to_irq(const struct gpio_desc *desc); /* Convert between the old gpio_ and new gpiod_ interfaces */ struct gpio_desc *gpio_to_desc(unsigned gpio); int desc_to_gpio(const struct gpio_desc *desc); -struct gpio_desc *gpio_name_to_desc(const char *name); /* Child properties interface */ struct fwnode_handle;