Skip to content

Commit 8bd76b3

Browse files
lkpdnBartosz Golaszewski
authored andcommitted
gpio: sim: lock up configfs that an instantiated device depends on
Once a sim device is instantiated and actively used, allowing rmdir for its configfs serves no purpose and can be confusing. Effectively, arbitrary users start depending on its existence. Make the subsystem itself depend on the configfs entry for a sim device while it is in active use. Signed-off-by: Koichiro Den <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent c7c434c commit 8bd76b3

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

drivers/gpio/gpio-sim.c

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,30 @@ static void gpio_sim_device_deactivate(struct gpio_sim_device *dev)
10271027
dev->pdev = NULL;
10281028
}
10291029

1030+
static void
1031+
gpio_sim_device_lockup_configfs(struct gpio_sim_device *dev, bool lock)
1032+
{
1033+
struct configfs_subsystem *subsys = dev->group.cg_subsys;
1034+
struct gpio_sim_bank *bank;
1035+
struct gpio_sim_line *line;
1036+
1037+
/*
1038+
* The device only needs to depend on leaf line entries. This is
1039+
* sufficient to lock up all the configfs entries that the
1040+
* instantiated, alive device depends on.
1041+
*/
1042+
list_for_each_entry(bank, &dev->bank_list, siblings) {
1043+
list_for_each_entry(line, &bank->line_list, siblings) {
1044+
if (lock)
1045+
WARN_ON(configfs_depend_item_unlocked(
1046+
subsys, &line->group.cg_item));
1047+
else
1048+
configfs_undepend_item_unlocked(
1049+
&line->group.cg_item);
1050+
}
1051+
}
1052+
}
1053+
10301054
static ssize_t
10311055
gpio_sim_device_config_live_store(struct config_item *item,
10321056
const char *page, size_t count)
@@ -1039,14 +1063,24 @@ gpio_sim_device_config_live_store(struct config_item *item,
10391063
if (ret)
10401064
return ret;
10411065

1042-
guard(mutex)(&dev->lock);
1066+
if (live)
1067+
gpio_sim_device_lockup_configfs(dev, true);
10431068

1044-
if (live == gpio_sim_device_is_live(dev))
1045-
ret = -EPERM;
1046-
else if (live)
1047-
ret = gpio_sim_device_activate(dev);
1048-
else
1049-
gpio_sim_device_deactivate(dev);
1069+
scoped_guard(mutex, &dev->lock) {
1070+
if (live == gpio_sim_device_is_live(dev))
1071+
ret = -EPERM;
1072+
else if (live)
1073+
ret = gpio_sim_device_activate(dev);
1074+
else
1075+
gpio_sim_device_deactivate(dev);
1076+
}
1077+
1078+
/*
1079+
* Undepend is required only if device disablement (live == 0)
1080+
* succeeds or if device enablement (live == 1) fails.
1081+
*/
1082+
if (live == !!ret)
1083+
gpio_sim_device_lockup_configfs(dev, false);
10501084

10511085
return ret ?: count;
10521086
}

0 commit comments

Comments
 (0)