Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3668847ybt; Tue, 23 Jun 2020 08:01:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKxU8VeJ2YQ9TkHRZUsiSicnkTw2Uc8YGMMncg0ika9QvloJ0r1XQcgjmBM1oOGzKHavDh X-Received: by 2002:a17:906:1386:: with SMTP id f6mr20687407ejc.66.1592924505503; Tue, 23 Jun 2020 08:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592924505; cv=none; d=google.com; s=arc-20160816; b=ZUNS8Sorw47HXD8rolnrVezn95O5rpP5sUNtrw0fwo4OT7fT//dnKzY9Mdz73vX1vi dbG3ZKt5Ds19RfYnCOmk5cKnXZpkito0A75Y8PUQEjDJipFXUyJc8zKsV99x5TrUBYGD Y24bLvfnguYaGnmgL5ST8BPaZnXdugkrfyNt7fNL6EX0GG9TqdI//8QD67ls6b+k56gs GTLnxf5VQJpXmF10Cc8vXfidMqv0jbQQ/TD5LODZh8lyIXFDxfAO25LY61YiETavgTl4 aO8xgYLTZliegNS9WCjeUvLdPkyaY1ZSMiBbO1rLN1eE6YZ5outne37jbKJZFb1BVgUf VgGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=G8/0y4BDnXGsO+Zeqn1J9PBnsrlblYajGJfRYN0/Vp0=; b=FzOs7YFwQserjm8634mxwT0/B1qh/fVZJBZhhcO+CJociwiOGrC4+KO25cX1rEmimv 1VcM+7Qrni5tQqgJDcOuDn1vNJ6J1DK8NGCy8opiDHtCHvvEK/dEx+jZwtl3DNuCyB/g rfMzbcedyBRddp5IfuVV9ZVzRP/rwMSkR02/Cdj2JrTIbKjJYA6QuBSShatH2o5kYHc4 Vr8myeRPe55/xNN6XLB1mElYPzC3UkByVSnraGilzRxwITNsSTsimNiNQKnPUx8hqnUk JLQv1/OdgbMSdDMRvicHHtQfXzSqBgTxm5f5IOJF3Zpm8c1oNigdJX6LPYIuXwh1k3/4 w+ZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id se20si11903919ejb.165.2020.06.23.08.01.22; Tue, 23 Jun 2020 08:01:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732919AbgFWO55 (ORCPT + 99 others); Tue, 23 Jun 2020 10:57:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732851AbgFWO5z (ORCPT ); Tue, 23 Jun 2020 10:57:55 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DC9EC061797 for ; Tue, 23 Jun 2020 07:57:54 -0700 (PDT) Received: from ramsan ([IPv6:2a02:1810:ac12:ed20:26:93a1:ff06:f8b0]) by laurent.telenet-ops.be with bizsmtp id uexs2200Q4qCYS801exsSu; Tue, 23 Jun 2020 16:57:52 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1jnkMy-0007VB-Li; Tue, 23 Jun 2020 16:57:52 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1jnkMy-0007Wa-Kf; Tue, 23 Jun 2020 16:57:52 +0200 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 2/2] gpio: aggregator: Use bitmap_parselist() for parsing GPIO offsets Date: Tue, 23 Jun 2020 16:57:48 +0200 Message-Id: <20200623145748.28877-3-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200623145748.28877-1-geert+renesas@glider.be> References: <20200623145748.28877-1-geert+renesas@glider.be> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace the custom code to parse GPIO offsets and/or GPIO offset ranges by a call to bitmap_parselist(), and an iteration over the returned bit mask. This should have no impact on the format of the configuration parameters written to the "new_device" virtual file in sysfs. Suggested-by: Andy Shevchenko Signed-off-by: Geert Uytterhoeven --- I'm not super happy with the mask[] array, which is on the stack. But there is no real limit on the number of GPIO lines provided by a single gpiochip, except for the global ARCH_NR_GPIOS. --- drivers/gpio/gpio-aggregator.c | 42 ++++++++++++---------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c index 62a3fcbd4b4bb106..7b2e7abaece9cdb1 100644 --- a/drivers/gpio/gpio-aggregator.c +++ b/drivers/gpio/gpio-aggregator.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -111,9 +112,10 @@ static int aggr_add_gpio(struct gpio_aggregator *aggr, const char *key, static int aggr_parse(struct gpio_aggregator *aggr) { - unsigned int first_index, last_index, i, n = 0; - char *name, *offsets, *first, *last, *next; + DECLARE_BITMAP(mask, ARCH_NR_GPIOS); char *args = aggr->args; + unsigned int i, n = 0; + char *name, *offsets; int error; for (name = get_arg(&args), offsets = get_arg(&args); name; @@ -134,32 +136,16 @@ static int aggr_parse(struct gpio_aggregator *aggr) } /* GPIO chip + offset(s) */ - for (first = offsets; *first; first = next) { - next = strchrnul(first, ','); - if (*next) - *next++ = '\0'; - - last = strchr(first, '-'); - if (last) - *last++ = '\0'; - - if (kstrtouint(first, 10, &first_index)) { - pr_err("Cannot parse GPIO index %s\n", first); - return -EINVAL; - } - - if (!last) { - last_index = first_index; - } else if (kstrtouint(last, 10, &last_index)) { - pr_err("Cannot parse GPIO index %s\n", last); - return -EINVAL; - } - - for (i = first_index; i <= last_index; i++) { - error = aggr_add_gpio(aggr, name, i, &n); - if (error) - return error; - } + error = bitmap_parselist(offsets, mask, ARCH_NR_GPIOS); + if (error) { + pr_err("Cannot parse %s: %d\n", offsets, error); + return error; + } + + for_each_set_bit(i, mask, ARCH_NR_GPIOS) { + error = aggr_add_gpio(aggr, name, i, &n); + if (error) + return error; } name = get_arg(&args); -- 2.17.1