From patchwork Tue Apr 10 14:18:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 10333245 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C5A836053F for ; Tue, 10 Apr 2018 14:18:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6A6B200E7 for ; Tue, 10 Apr 2018 14:18:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB64F20134; Tue, 10 Apr 2018 14:18:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B79D32015F for ; Tue, 10 Apr 2018 14:18:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753575AbeDJOSV (ORCPT ); Tue, 10 Apr 2018 10:18:21 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35716 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753508AbeDJOSU (ORCPT ); Tue, 10 Apr 2018 10:18:20 -0400 Received: by mail-wm0-f65.google.com with SMTP id r82so23897583wme.0; Tue, 10 Apr 2018 07:18:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=bg8Nym3wYk8RRlFL6dgXCjePG8Bju8++Ajpynys4SLE=; b=C9lJWHDgNupLMroY8Vw7yN89PctK/ACNDscjZ572hY3OSl3VnS1ye2wUk9EMDZQB3/ ppUgI2k1ggLMJgFFkc99h2p95/8mEXfQ4W+PRTlkQK+8sWqq3Vho9TPIRcsy+zSA+2BI frmHp/I1Z3gi5NPwak8pI1y6EEHykIz0v3oiTQgnirVfEaaxkwiVTO/1HQTthWKqxroR JaHPizlCsD5F04viy6ljdIK3ILGfiAPn7gX/cyH7y/bk0uNgaeMEEKLXQ7TPuReEziQf gpgQ/zREvBfnz8QVPmxJgLSI4VPLc0DTJh8o+NjfdduiohjvJg7ytLnCqA+GlJixPayJ i4pA== 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; bh=bg8Nym3wYk8RRlFL6dgXCjePG8Bju8++Ajpynys4SLE=; b=HA0ATW5w7daUs4hbC+/CTrzbELXXf6wB/ehG68oDyMkwpXCf9dXymxD5/lQvO/EHYt rHUUGQjtUH4zKalAhWw75zLjOrZf5wsJd+ABLsfpILAWjBbJaMlgbGGTvhv5oaU4/myZ /WP7xhS1WcLaPu2Xm0d4hml4mkJGGdnifXldbemKzUq5zbU3ob3rq43XgH+lQnDQC5kJ pkgJ7X1myNnXOCz1uccE9RAaqet6qLDkAgKb8QgZTXxfurRn0GAXWeraglNp0XkF9nqC hEIyomogzHLXttbw/c6tu6TlZm/qxt7/B1VxUkSTzeLvCEQM6DgGDy/VgjaI7fUehf/0 v+PQ== X-Gm-Message-State: ALQs6tDgAkIRXwrqJ5ScwvMkpwGG9eAXOS3ZGq0YwjtpmMxXPfsUTWbd t8IzUj7lOjjpWn3pksCe64OAs1gs X-Google-Smtp-Source: AIpwx4+vFwKv0gUWd3ZZSfKXmiILKaZNKZV9xuP7iVGfvRXE6zW7D514UC2/vjqsMctJpaGBo8B3BQ== X-Received: by 10.28.116.20 with SMTP id p20mr1951602wmc.24.1523369899535; Tue, 10 Apr 2018 07:18:19 -0700 (PDT) Received: from debian64.daheim (p200300D5FBC56CFC0000000000000830.dip0.t-ipconnect.de. [2003:d5:fbc5:6cfc::830]) by smtp.gmail.com with ESMTPSA id e10sm5094214wri.23.2018.04.10.07.18.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Apr 2018 07:18:17 -0700 (PDT) Received: from chuck by debian64.daheim with local (Exim 4.90_1) (envelope-from ) id 1f5u6D-0007vu-0q; Tue, 10 Apr 2018 16:18:17 +0200 From: Christian Lamparter To: linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Cc: Bjorn Andersson , Linus Walleij , David Brown , Andy Gross , Sven Eckelmann Subject: [PATCH v3 1/2] gpiolib: do not add duplicated GPIO Pin ranges Date: Tue, 10 Apr 2018 16:18:15 +0200 Message-Id: <20180410141816.30452-1-chunkeey@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP look if a GPIO range with the same ID has already been registered. For pinctrls that are set up through devicetree, the GPIO Range might be already set by the the gpio-ranges property. (see Documentation/devicetree/bindings/gpio/gpio.txt) Signed-off-by: Christian Lamparter --- drivers/gpio/gpiolib.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 43aeb07343ec..3882e1ff85fa 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2069,6 +2069,19 @@ int gpiochip_generic_config(struct gpio_chip *chip, unsigned offset, } EXPORT_SYMBOL_GPL(gpiochip_generic_config); +static struct gpio_pin_range *gpiochip_find_by_id(struct gpio_chip *chip, + unsigned int id) +{ + struct gpio_pin_range *pin_range; + struct gpio_device *gdev = chip->gpiodev; + + list_for_each_entry(pin_range, &gdev->pin_ranges, node) { + if (pin_range->range.id == id) + return pin_range; + } + return NULL; +} + #ifdef CONFIG_PINCTRL /** @@ -2086,6 +2099,20 @@ int gpiochip_add_pingroup_range(struct gpio_chip *chip, struct gpio_device *gdev = chip->gpiodev; int ret; + /* + * look if a GPIO range with the same ID has already been registered. + * For pinctrls that are set up through devicetree, the GPIO Range + * might be already set by the the gpio-ranges property. + * (see Documentation/devicetree/bindings/gpio/gpio.txt) + */ + pin_range = gpiochip_find_by_id(chip, gpio_offset); + if (pin_range) { + chip_dbg(chip, "found existing GPIO range %d->%d - skipping\n", + gpio_offset, + gpio_offset + pin_range->range.npins - 1); + return 0; + } + pin_range = kzalloc(sizeof(*pin_range), GFP_KERNEL); if (!pin_range) { chip_err(chip, "failed to allocate pin ranges\n"); @@ -2139,6 +2166,20 @@ int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, struct gpio_device *gdev = chip->gpiodev; int ret; + /* + * look if a GPIO range with the same ID has already been registered. + * For pinctrls that are set up through devicetree, the GPIO Range + * might be already set by the the gpio-ranges property. + * (see Documentation/devicetree/bindings/gpio/gpio.txt) + */ + pin_range = gpiochip_find_by_id(chip, gpio_offset); + if (pin_range) { + chip_dbg(chip, "found existing GPIO range %d->%d - skipping\n", + gpio_offset, + gpio_offset + pin_range->range.npins - 1); + return 0; + } + pin_range = kzalloc(sizeof(*pin_range), GFP_KERNEL); if (!pin_range) { chip_err(chip, "failed to allocate pin ranges\n");