Skip to content

Commit 7329b07

Browse files
committed
gpio: sim: fix the chip_name configfs item
The chip_name configs attribute always displays the device name of the first GPIO bank because the logic of the relevant function is simply wrong. Fix it by correctly comparing the bank's swnode against the GPIO device's children. Fixes: cb8c474 ("gpio: sim: new testing module") Cc: stable@vger.kernel.org Reported-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Kent Gibson <warthog618@gmail.com> Tested-by: Kent Gibson <warthog618@gmail.com>
1 parent 3234649 commit 7329b07

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

drivers/gpio/gpio-sim.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -991,36 +991,30 @@ static struct configfs_attribute *gpio_sim_device_config_attrs[] = {
991991
};
992992

993993
struct gpio_sim_chip_name_ctx {
994-
struct gpio_sim_device *dev;
994+
struct fwnode_handle *swnode;
995995
char *page;
996996
};
997997

998998
static int gpio_sim_emit_chip_name(struct device *dev, void *data)
999999
{
10001000
struct gpio_sim_chip_name_ctx *ctx = data;
1001-
struct fwnode_handle *swnode;
1002-
struct gpio_sim_bank *bank;
10031001

10041002
/* This would be the sysfs device exported in /sys/class/gpio. */
10051003
if (dev->class)
10061004
return 0;
10071005

1008-
swnode = dev_fwnode(dev);
1006+
if (device_match_fwnode(dev, ctx->swnode))
1007+
return sprintf(ctx->page, "%s\n", dev_name(dev));
10091008

1010-
list_for_each_entry(bank, &ctx->dev->bank_list, siblings) {
1011-
if (bank->swnode == swnode)
1012-
return sprintf(ctx->page, "%s\n", dev_name(dev));
1013-
}
1014-
1015-
return -ENODATA;
1009+
return 0;
10161010
}
10171011

10181012
static ssize_t gpio_sim_bank_config_chip_name_show(struct config_item *item,
10191013
char *page)
10201014
{
10211015
struct gpio_sim_bank *bank = to_gpio_sim_bank(item);
10221016
struct gpio_sim_device *dev = gpio_sim_bank_get_device(bank);
1023-
struct gpio_sim_chip_name_ctx ctx = { dev, page };
1017+
struct gpio_sim_chip_name_ctx ctx = { bank->swnode, page };
10241018
int ret;
10251019

10261020
mutex_lock(&dev->lock);

0 commit comments

Comments
 (0)