public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Koichiro Den <koichiro.den@canonical.com>,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
	Sasha Levin <sashal@kernel.org>,
	linus.walleij@linaro.org, brgl@bgdev.pl,
	linux-gpio@vger.kernel.org
Subject: [PATCH AUTOSEL 6.12 11/20] gpio: sim: lock up configfs that an instantiated device depends on
Date: Mon, 13 Jan 2025 13:34:16 -0500	[thread overview]
Message-ID: <20250113183425.1783715-11-sashal@kernel.org> (raw)
In-Reply-To: <20250113183425.1783715-1-sashal@kernel.org>

From: Koichiro Den <koichiro.den@canonical.com>

[ 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>
---
 drivers/gpio/gpio-sim.c | 48 +++++++++++++++++++++++++++++++++++------
 1 file changed, 41 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index dcca1d7f173e..deedacdeb239 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -1030,6 +1030,30 @@ static void gpio_sim_device_deactivate(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)
@@ -1042,14 +1066,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(dev))
-		ret = -EPERM;
-	else if (live)
-		ret = gpio_sim_device_activate(dev);
-	else
-		gpio_sim_device_deactivate(dev);
+	scoped_guard(mutex, &dev->lock) {
+		if (live == gpio_sim_device_is_live(dev))
+			ret = -EPERM;
+		else if (live)
+			ret = gpio_sim_device_activate(dev);
+		else
+			gpio_sim_device_deactivate(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;
 }
-- 
2.39.5


  parent reply	other threads:[~2025-01-13 18:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-13 18:34 [PATCH AUTOSEL 6.12 01/20] mac802154: check local interfaces before deleting sdata list Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 02/20] hfs: Sanity check the root record Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 03/20] fs/qnx6: Fix building with GCC 15 Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 04/20] iomap: pass byte granular end position to iomap_add_to_ioend Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 05/20] fs: fix missing declaration of init_files Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 06/20] kheaders: Ignore silly-rename files Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 07/20] netfs: Fix non-contiguous donation between completed reads Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 08/20] cachefiles: Parse the "secctx" immediately Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 09/20] scsi: ufs: core: Honor runtime/system PM levels if set by host controller drivers Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 10/20] gpio: virtuser: lock up configfs that an instantiated device depends on Sasha Levin
2025-01-13 18:34 ` Sasha Levin [this message]
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 12/20] selftests: tc-testing: reduce rshift value Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 13/20] ovl: pass realinode to ovl_encode_real_fh() instead of realdentry Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 14/20] platform/x86/intel: power-domains: Add Clearwater Forest support Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 15/20] platform/x86: ISST: Add Clearwater Forest to support list Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 16/20] ACPI: resource: acpi_dev_irq_override(): Check DMI match last Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 17/20] sched_ext: keep running prev when prev->scx.slice != 0 Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 18/20] iomap: avoid avoid truncating 64-bit offset to 32 bits Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 19/20] afs: Fix merge preference rule failure condition Sasha Levin
2025-01-13 18:34 ` [PATCH AUTOSEL 6.12 20/20] poll_wait: add mb() to fix theoretical race between waitqueue_active() and .poll() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250113183425.1783715-11-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=koichiro.den@canonical.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox