Skip to content

Commit c162ca0

Browse files
committed
gpio: sim: fix hogs with custom chip labels
We always assign the default device name as the chip_label in hog structures which makes it impossible to assign hogs to chips. Let's first check if a custom label was set and then copy it instead of the default device name. Fixes: cb8c474 ("gpio: sim: new testing module") Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]>
1 parent cc38ef9 commit c162ca0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

drivers/gpio/gpio-sim.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,11 @@ static struct gpio_sim_bank *to_gpio_sim_bank(struct config_item *item)
570570
return container_of(group, struct gpio_sim_bank, group);
571571
}
572572

573+
static bool gpio_sim_bank_has_label(struct gpio_sim_bank *bank)
574+
{
575+
return bank->label && *bank->label;
576+
}
577+
573578
static struct gpio_sim_device *
574579
gpio_sim_bank_get_device(struct gpio_sim_bank *bank)
575580
{
@@ -770,9 +775,15 @@ static int gpio_sim_add_hogs(struct gpio_sim_device *dev)
770775
* point the device doesn't exist yet and so dev_name()
771776
* is not available.
772777
*/
773-
hog->chip_label = kasprintf(GFP_KERNEL,
774-
"gpio-sim.%u-%s", dev->id,
775-
fwnode_get_name(bank->swnode));
778+
if (gpio_sim_bank_has_label(bank))
779+
hog->chip_label = kstrdup(bank->label,
780+
GFP_KERNEL);
781+
else
782+
hog->chip_label = kasprintf(GFP_KERNEL,
783+
"gpio-sim.%u-%s",
784+
dev->id,
785+
fwnode_get_name(
786+
bank->swnode));
776787
if (!hog->chip_label) {
777788
gpio_sim_remove_hogs(dev);
778789
return -ENOMEM;
@@ -816,7 +827,7 @@ gpio_sim_make_bank_swnode(struct gpio_sim_bank *bank,
816827

817828
properties[prop_idx++] = PROPERTY_ENTRY_U32("ngpios", bank->num_lines);
818829

819-
if (bank->label && (strlen(bank->label) > 0))
830+
if (gpio_sim_bank_has_label(bank))
820831
properties[prop_idx++] = PROPERTY_ENTRY_STRING("gpio-sim,label",
821832
bank->label);
822833

0 commit comments

Comments
 (0)