From nobody Fri Feb 13 00:23:25 2026 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8DDA1B0F38 for ; Fri, 3 Jan 2025 03:04:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873462; cv=none; b=FPCtbsS3yCrIrkqyQWGJlWylIKNlqJNEYgxaCmpFRfA+WP+Tyi0q+7ohqdacOje4uihXeID48140u252LIceX5PEzeChgPUU7RFLzEyWZiFpHTKfRuXslaoXx9F1RVL1t4X+LoDowI3Jqp/Q7g8LcOZlTzP316/AAkySeJleIxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873462; c=relaxed/simple; bh=cMG1/1MMnZC5j0tafg83V1P3/epd9tHHHNaDsyBmqgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nwCLHbrHe6WPmJRYQ/v6TLzSMZHeAwj01WSr5OvvBBRGHXkSRRjIq/fmROvFXHCDFNMFjbiPpV7QcqMTpyePVGud7VelX6T58WKtHiBxymzGgAkUSqvSHEQts98QatPGrHzFYkAHfVWRtx9CmDaZiAVvYbzcUZcxaBCbFhIc04w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=Kzgyafz4; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="Kzgyafz4" Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 3C72F40FA6 for ; Fri, 3 Jan 2025 03:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735873459; bh=KnRRrmEz3ZlIIsMVIhLEqcdV5rbJka1OKmEC4NqPpMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kzgyafz4DbtPFf7gB3fK0kIZCDTE8fGazVBLBO/pd78BF8sjhlj66wVpKfUVFbj2z t8QWWoC4Bh8PHWUHMQlfVOhzQELjwIkWMWTSYqxZvXuhX2vZcx9F3GsRQByBu64oAI /06vbxyktZxGSpLbZmM6IAShDNZ7Gq00OyYd4vZXrUKGXq5XCIywysVTcr5jliKoaf Y6zVCSVMC1pozihVukmf5t075DBMTqltZyYxoIF3pRuottamrzv+zLp1/bJATh44Sw r0UNmtOkYIY4iIL3S85M6/CqxPS9V7PRxJ2sAMiw+aitPpshOY2Pn695Cjr4wQQwK/ RKPck2JuCpi3g== Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-216430a88b0so161639115ad.0 for ; Thu, 02 Jan 2025 19:04:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735873458; x=1736478258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KnRRrmEz3ZlIIsMVIhLEqcdV5rbJka1OKmEC4NqPpMo=; b=Qa0IqzhoVH1jvCrBx2ucZ59pqvQpiBGP1qX0MM6s1Y5CXug9YxSMjVn1FhnS2OoxNn RYxrqyMZhbVHwEkxctrFCV1dYpCaocszsf9FTz3Zg8qHPNVh3a4ngnJ2ob5ATYoxJ1Ze AJ3nyMf/qxml83EgPXoTyUdchfWGa1gbJazoajr9eYiD77bFIb6Z8ItmdPgzwKpSW+7C e39s8MrWO6r96/0LF5ncOVR+4UkO1oaOMAKA3r74a/wmP0wk6cjPGSvegi+EfXRiNrwW Q6lerRe5UHPPl09Xg626uWGDk3wRHIZ4DJ1tkRcStPX8ifzzGmnjKmR4zymNohIiwLYL jLSw== X-Forwarded-Encrypted: i=1; AJvYcCWsqiZFP39mbTHU3fFmAYiO5Yo2GKp14JihX6NX9WodrPMGcvMqAvDiPuIyk7BuqCDK9ptRZ0FMuESeUnw=@vger.kernel.org X-Gm-Message-State: AOJu0Yytb+CxjW5L179Z6p+L/90l8fMozA+at2Y2RSHIRkSvEd5gm1D9 wfzpD7c+WCaktpPr+STNRB2AlGSVIqSsEKCupSRyrDodm74YNyT85XtZzJwUYn6Pbi/T3eXinmS I7u58xNWgsUiH3t/hQmPq1jXj7DgVuyflqpE64ofHKRCFw1sSyaznq4kxX5ydAjc0hW50BBACd9 d3cQ== X-Gm-Gg: ASbGncv6UVN4pQvyCnUpJPgvmLlU9Ck0Akukk6oYGStOoBU2BIG/fP8CKxEH+1mR1LN xs0swKSffqySCcb52OaX8OGv+k18/PRYT8ye7Q0xxCcDqoQtBPwHKvz/dDh5Y4OA/z/mN5rH3+D 7qPfycmlObRvlyZ204ahHKoWhP9ARbi5ZL/S6dZyuJid2hAaajtJghgPY16odXdnEJ/MG8u1+3/ r3/++/33tB3I5wooryIWeP8Dq5DkDC1yKrB1Qwt6OCyiPoCTmpPBaeS7w== X-Received: by 2002:a17:902:ec82:b0:215:827e:3a6 with SMTP id d9443c01a7336-219e6f1447fmr669964305ad.40.1735873457818; Thu, 02 Jan 2025 19:04:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9RNUp94jEV9P+9MrJZxWB37Wjl05/hcGuQKUx1SF53mS16El8k6M6J16/Z4u8N3wsbGWoQw== X-Received: by 2002:a17:902:ec82:b0:215:827e:3a6 with SMTP id d9443c01a7336-219e6f1447fmr669964005ad.40.1735873457444; Thu, 02 Jan 2025 19:04:17 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:cb9e:69af:fb16:54f4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc964e92sm234468215ad.18.2025.01.02.19.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 19:04:17 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: linus.walleij@linaro.org, brgl@bgdev.pl, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] gpio: sim: lock up configfs that an instantiated device depends on Date: Fri, 3 Jan 2025 12:04:02 +0900 Message-ID: <20250103030402.81954-5-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250103030402.81954-1-koichiro.den@canonical.com> References: <20250103030402.81954-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 f387dad81f29..686ae3d11ba3 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -1027,6 +1027,30 @@ static void gpio_sim_device_deactivate(struct gpio_s= im_device *dev) dev->pdev =3D NULL; } =20 +static void +gpio_sim_device_lockup_configfs(struct gpio_sim_device *dev, bool lock) +{ + struct configfs_subsystem *subsys =3D 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) @@ -1039,14 +1063,24 @@ gpio_sim_device_config_live_store(struct config_ite= m *item, if (ret) return ret; =20 - guard(mutex)(&dev->lock); + if (live) + gpio_sim_device_lockup_configfs(dev, true); =20 - if (live =3D=3D gpio_sim_device_is_live(dev)) - ret =3D -EPERM; - else if (live) - ret =3D gpio_sim_device_activate(dev); - else - gpio_sim_device_deactivate(dev); + scoped_guard(mutex, &dev->lock) { + if (live =3D=3D gpio_sim_device_is_live(dev)) + ret =3D -EPERM; + else if (live) + ret =3D gpio_sim_device_activate(dev); + else + gpio_sim_device_deactivate(dev); + } + + /* + * Undepend is required only if device disablement (live =3D=3D 0) + * succeeds or if device enablement (live =3D=3D 1) fails. + */ + if (live =3D=3D !!ret) + gpio_sim_device_lockup_configfs(dev, false); =20 return ret ?: count; } --=20 2.43.0