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: 10333247 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 546546053C for ; Tue, 10 Apr 2018 14:18:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 432612015F for ; Tue, 10 Apr 2018 14:18:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37B8820174; Tue, 10 Apr 2018 14:18:41 +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=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D69A12015F for ; Tue, 10 Apr 2018 14:18:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=Wo4uuQjySOtzfvsvvIlNRSQ/xl6lA0vSnVUzNTbwqdc=; b=MV8 QmCqzduIG6IIZNCp6z5BvX/NGBoN/xGbeviXYQbQl7biJ3drUeB6jmGOYITyHxth8jkdWpTWzAG+9 wCMBHmLwuLBsiVMRykFUqzrTBaVrokxQLDjmItRDDeKG7rFCtWe72c9HIeRUhBa9+/VD/EPVpmb0j 6eH3VV6BJ5VT1reL2cXaKgOdpM7RRsgyyOF8hGBU/2TkPR7S4cHBChET9bv6qrgpH+5e130m6XrZq ualNbLayRQkbtv5ca0203R/rvO5AHBv6JJ6O65BYiDMyJGNNGKicE0DW34F/+l4wY33yXUOza8MMP +u48Bthm+r8kDAL9+CYoylHPO6uiEbw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5u6V-0007ZU-RF; Tue, 10 Apr 2018 14:18:35 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5u6S-0007Wt-30 for linux-arm-kernel@lists.infradead.org; Tue, 10 Apr 2018 14:18:33 +0000 Received: by mail-wm0-x243.google.com with SMTP id t67so26681474wmt.0 for ; Tue, 10 Apr 2018 07:18:21 -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=XtHV+HNFWIXva8N8TIPD16ETbLafVtQdcb806jf637n154mVS5zdTjl5jyDvRpoD1v MBaSMFS12isr9nxC8Ns/l4CbDRN5PKfAeNim9Q5IPKVEPz0GIufu3MRFwxp7dt+0qpYs 9NlFCd03pitzRkSI9s5bVowaLPSXt/Qtu1cfwfMrLu7Rbqfz2NnASCN/R4i7F3xP6cgj w3S/4o1p8rgQv4qVhKNccd9pFt57OisYFBsvV6UgmvmC8DitvSLFF+i84tbnJ/11Qu9r QerYAi2RhOqK6FEYhyjPp2Duw6hGPQAwAhvWBr+y5Udd/IgNdShFLXpH76+kwiauv8I+ Zy2Q== X-Gm-Message-State: ALQs6tBnSYO44UaRHv9ilhNAtsMPBk5JEaYs+QzY0ZVqJU8gEOLNveze BGWNSXZsh+q051ZOBc3pJVJm0npk 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180410_071832_180680_7AAF8F52 X-CRM114-Status: GOOD ( 13.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andy Gross , David Brown , Linus Walleij , Sven Eckelmann , Bjorn Andersson MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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");