gpio: sim: lock up configfs that an instantiated device depends on
BugLink: https://bugs.launchpad.net/bugs/2107449 [ Upstream commit 8bd76b3d3f3af7ac2898b6a27ad90c444fec418f ] 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 <koichiro.den@canonical.com> Link: https://lore.kernel.org/r/20250103141829.430662-5-koichiro.den@canonical.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Signed-off-by: Sasha Levin <sashal@kernel.org> [koichiroden: adjusted context due to the missing commit: 11498d99008f ("gpio: sim: add lockdep asserts")] Signed-off-by: Koichiro Den <koichiro.den@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
This commit is contained in:
committed by
Stefan Bader
parent
f74fe113f3
commit
a538e6eb0c
+41
-7
@@ -1009,6 +1009,30 @@ static void gpio_sim_device_deactivate_unlocked(struct gpio_sim_device *dev)
|
||||
dev->pdev = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gpio_sim_device_lockup_configfs(struct gpio_sim_device *dev, bool lock)
|
||||
{
|
||||
struct configfs_subsystem *subsys = dev->group.cg_subsys;
|
||||
struct gpio_sim_bank *bank;
|
||||
struct gpio_sim_line *line;
|
||||
|
||||
/*
|
||||
* The device only needs to depend on leaf line entries. This is
|
||||
* sufficient to lock up all the configfs entries that the
|
||||
* instantiated, alive device depends on.
|
||||
*/
|
||||
list_for_each_entry(bank, &dev->bank_list, siblings) {
|
||||
list_for_each_entry(line, &bank->line_list, siblings) {
|
||||
if (lock)
|
||||
WARN_ON(configfs_depend_item_unlocked(
|
||||
subsys, &line->group.cg_item));
|
||||
else
|
||||
configfs_undepend_item_unlocked(
|
||||
&line->group.cg_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
gpio_sim_device_config_live_store(struct config_item *item,
|
||||
const char *page, size_t count)
|
||||
@@ -1021,14 +1045,24 @@ gpio_sim_device_config_live_store(struct config_item *item,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
guard(mutex)(&dev->lock);
|
||||
if (live)
|
||||
gpio_sim_device_lockup_configfs(dev, true);
|
||||
|
||||
if (live == gpio_sim_device_is_live_unlocked(dev))
|
||||
ret = -EPERM;
|
||||
else if (live)
|
||||
ret = gpio_sim_device_activate_unlocked(dev);
|
||||
else
|
||||
gpio_sim_device_deactivate_unlocked(dev);
|
||||
scoped_guard(mutex, &dev->lock) {
|
||||
if (live == gpio_sim_device_is_live_unlocked(dev))
|
||||
ret = -EPERM;
|
||||
else if (live)
|
||||
ret = gpio_sim_device_activate_unlocked(dev);
|
||||
else
|
||||
gpio_sim_device_deactivate_unlocked(dev);
|
||||
}
|
||||
|
||||
/*
|
||||
* Undepend is required only if device disablement (live == 0)
|
||||
* succeeds or if device enablement (live == 1) fails.
|
||||
*/
|
||||
if (live == !!ret)
|
||||
gpio_sim_device_lockup_configfs(dev, false);
|
||||
|
||||
return ret ?: count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user