summaryrefslogtreecommitdiff
path: root/drivers/gpio/gpio-aggregator.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2020-08-06 14:15:47 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2020-08-06 14:15:47 +0300
commit94fb1afb14c4f0ceb8c5508ddddac6819f662e95 (patch)
tree4988e5769dc7482caa7f441475ae31f50bbd37ef /drivers/gpio/gpio-aggregator.c
parentc4735d990268399da9133b0ad445e488ece009ad (diff)
parent47ec5303d73ea344e84f46660fff693c57641386 (diff)
downloadlinux-94fb1afb14c4f0ceb8c5508ddddac6819f662e95.tar.xz
Mgerge remote-tracking branch 'torvalds/master' into perf/core
To sync headers, for instance, in this case tools/perf was ahead of upstream till Linus merged tip/perf/core to get the PERF_RECORD_TEXT_POKE changes: Warning: Kernel ABI header at 'tools/include/uapi/linux/perf_event.h' differs from latest version at 'include/uapi/linux/perf_event.h' diff -u tools/include/uapi/linux/perf_event.h include/uapi/linux/perf_event.h Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'drivers/gpio/gpio-aggregator.c')
-rw-r--r--drivers/gpio/gpio-aggregator.c63
1 files changed, 28 insertions, 35 deletions
diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index 9b0adbdddbfc..424a3d25350b 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -10,6 +10,7 @@
#include <linux/bitmap.h>
#include <linux/bitops.h>
#include <linux/ctype.h>
+#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/driver.h>
#include <linux/gpio/machine.h>
@@ -38,9 +39,9 @@ static DEFINE_IDR(gpio_aggregator_idr);
static char *get_arg(char **args)
{
- char *start = *args, *end;
+ char *start, *end;
- start = skip_spaces(start);
+ start = skip_spaces(*args);
if (!*start)
return NULL;
@@ -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,