Previously, there is no way to assign names to GPIO lines exported through an aggregator. Allow users to set custom line names via a 'name' attribute. Signed-off-by: Koichiro Den <koichiro.den@xxxxxxxxxxxxx> --- drivers/gpio/gpio-aggregator.c | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c index 76d3a8677308..3263d99bfe69 100644 --- a/drivers/gpio/gpio-aggregator.c +++ b/drivers/gpio/gpio-aggregator.c @@ -63,6 +63,8 @@ struct gpio_aggregator_line { /* Line index within the aggregator device */ int idx; + /* Custom name for the virtual line */ + char *name; /* GPIO chip label or line name */ char *key; /* Can be negative to indicate lookup by line name */ @@ -678,6 +680,44 @@ gpio_aggr_line_key_store(struct config_item *item, const char *page, CONFIGFS_ATTR(gpio_aggr_line_, key); +static ssize_t +gpio_aggr_line_name_show(struct config_item *item, char *page) +{ + struct gpio_aggregator_line *line = to_gpio_aggregator_line(item); + struct gpio_aggregator *aggr = line->parent; + + guard(mutex)(&aggr->lock); + + return sprintf(page, "%s\n", line->name ?: ""); +} + +static ssize_t +gpio_aggr_line_name_store(struct config_item *item, const char *page, + size_t count) +{ + struct gpio_aggregator_line *line = to_gpio_aggregator_line(item); + struct gpio_aggregator *aggr = line->parent; + + char *name __free(kfree) = kstrndup(skip_spaces(page), count, + GFP_KERNEL); + if (!name) + return -ENOMEM; + + strim(name); + + guard(mutex)(&aggr->lock); + + if (aggr_is_active(aggr)) + return -EBUSY; + + kfree(line->name); + line->name = no_free_ptr(name); + + return count; +} + +CONFIGFS_ATTR(gpio_aggr_line_, name); + static ssize_t gpio_aggr_line_offset_show(struct config_item *item, char *page) { @@ -728,6 +768,7 @@ CONFIGFS_ATTR(gpio_aggr_line_, offset); static struct configfs_attribute *gpio_aggr_line_attrs[] = { &gpio_aggr_line_attr_key, + &gpio_aggr_line_attr_name, &gpio_aggr_line_attr_offset, NULL }; @@ -813,6 +854,7 @@ gpio_aggr_line_release(struct config_item *item) aggr_line_del(aggr, line); kfree(line->key); + kfree(line->name); kfree(line); } -- 2.45.2