Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp546702ybt; Wed, 1 Jul 2020 04:45:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTTU78ud11jI40+bgtx71xeV7yjiKaFKvoNc0+KzH65iuPC635lGpQAQ/75at5qzJ95jb9 X-Received: by 2002:a17:907:20af:: with SMTP id pw15mr23591219ejb.204.1593603951859; Wed, 01 Jul 2020 04:45:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593603951; cv=none; d=google.com; s=arc-20160816; b=Bg7Pkqfs6d2HIDKeiwAC5qpbsU+sdBSFwygkAXe3k6lkfeJ6h6+NT+i27oJ8EFAff/ 0UFM9hlexnFaWsml5hgsP6VzSdSUN4bQfJDc+M2bI0FggRjbhOT6V4QSjnBWzZDx9hu2 zUWjJCVrWKy5MjdlZAYBx6tVyeD76TMdBDFOJL//VLrrBXND0r+p0ET4AYpZQizIwrmd SulQ3Z6vXLQN0JngRl3SPJvuYFqkqcgl7ROXNQfRHIulDCoSHbjAmNDHWbZJDQX8Lxpl V2/Y4Xl+luYmg3+y1a7JLQKdMQOF65dRKoAYO2HojRP9XUQQ3vr0faa2CCfDdqqeVTiI 2CpQ== 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=mxwI1lTUn7Nxtf0iCNxzXR+/AQaRjKxSKkunXsPc+AM=; b=KUDDaQTfh2OTLob0ZZTCOaw5YM0kf7FTV/UZ8ICoPzh3LvbFmpG1W5Py4IiJkKNjVC lcOHH/BaWON1JLMM8RDkRIHjHwW0Od9kMC/gVb43fGzLdVX/6ePDQiNmke71apDaLmxr JGnkYoRmDYzPC4/UrpRuqHFUogysmd6A0f2Yh86O8wEJDu5gget14IPv1BTeYNhlVn4H r5vnKDFDxIOQ8RFRUbtJh9r3tYZ1zPRAr8OsJvk35bgZ2FA6/wLIaKxWwOHMO+xiTQQa nHyqD60LRysnbB3WstLH+1AvkFae5uZdqiCy1uqK+Oy3H/+e4F8s1myDx5xHtdiItYq8 524g== 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 h1si3747425ejc.200.2020.07.01.04.45.27; Wed, 01 Jul 2020 04:45:51 -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 S1730447AbgGALmU (ORCPT + 99 others); Wed, 1 Jul 2020 07:42:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730364AbgGALmT (ORCPT ); Wed, 1 Jul 2020 07:42:19 -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 356F0C03E97A for ; Wed, 1 Jul 2020 04:42:19 -0700 (PDT) Received: from ramsan ([IPv6:2a02:1810:ac12:ed20:503c:ab8:1424:9638]) by laurent.telenet-ops.be with bizsmtp id xniG2200249uj5301niG47; Wed, 01 Jul 2020 13:42:16 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1jqb84-0006Pu-92; Wed, 01 Jul 2020 13:42:16 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1jqb84-0002EF-73; Wed, 01 Jul 2020 13:42:16 +0200 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 2/2] gpio: aggregator: Use bitmap_parselist() for parsing GPIO offsets Date: Wed, 1 Jul 2020 13:42:12 +0200 Message-Id: <20200701114212.8520-3-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200701114212.8520-1-geert+renesas@glider.be> References: <20200701114212.8520-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 --- v2: - Rename mask to bitmap, - Allocate bitmap dynamically. --- drivers/gpio/gpio-aggregator.c | 59 +++++++++++++++------------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c index 62a3fcbd4b4bb106..424a3d25350bf50d 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,55 +112,45 @@ 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; char *args = aggr->args; - int error; + unsigned long *bitmap; + unsigned int i, n = 0; + char *name, *offsets; + int error = 0; + + bitmap = bitmap_alloc(ARCH_NR_GPIOS, GFP_KERNEL); + if (!bitmap) + return -ENOMEM; for (name = get_arg(&args), offsets = get_arg(&args); name; offsets = get_arg(&args)) { if (IS_ERR(name)) { pr_err("Cannot get GPIO specifier: %pe\n", name); - return PTR_ERR(name); + error = PTR_ERR(name); + goto free_bitmap; } if (!isrange(offsets)) { /* Named GPIO line */ error = aggr_add_gpio(aggr, name, U16_MAX, &n); if (error) - return error; + goto free_bitmap; name = offsets; continue; } /* 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, bitmap, ARCH_NR_GPIOS); + if (error) { + pr_err("Cannot parse %s: %d\n", offsets, error); + goto free_bitmap; + } + + for_each_set_bit(i, bitmap, ARCH_NR_GPIOS) { + error = aggr_add_gpio(aggr, name, i, &n); + if (error) + goto free_bitmap; } name = get_arg(&args); @@ -167,10 +158,12 @@ static int aggr_parse(struct gpio_aggregator *aggr) if (!n) { pr_err("No GPIOs specified\n"); - return -EINVAL; + error = -EINVAL; } - return 0; +free_bitmap: + bitmap_free(bitmap); + return error; } static ssize_t new_device_store(struct device_driver *driver, const char *buf, -- 2.17.1