From nobody Fri Dec 19 20:36:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1DE34285CBC; Thu, 6 Nov 2025 15:27:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762442848; cv=none; b=p4vMJdNcr+CJNM4CcFNiULiuy7aCEvEuRz0SB9t23hu022D/Bhs735t1OGAq8rKBXY9nxXqt7xfxX36tMJc0PrlyGxvIXn/UjJdhNFzFEQpqLqb22m7inhNI4lePG3iLERj7GfA3/Tw9dYxUl9iTsRPdinsJG1ZG9UzWR2LLRjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762442848; c=relaxed/simple; bh=pDW3PIbVUN0hwhMWLObPrf02JXtVWHIKLhJ/XRKRmYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p2ZnW17wM5YXhLOyDGuVtNrG5Yh5gutG3ioki/Ir41RzZSw2Iw15DPm9xpYE5MvKtTSO9PiKZfE88td8RpS0k4ujaHewPnuO1ooNENsmJ8n+iRFKMR5wNrUeMGXYgaygBTmeJc/m2c/pTtpUl1j4tvMdn7iiX/HmzAHkNvInF98= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j0TX162G; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="j0TX162G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDF8CC4CEF7; Thu, 6 Nov 2025 15:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1762442847; bh=pDW3PIbVUN0hwhMWLObPrf02JXtVWHIKLhJ/XRKRmYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j0TX162GToisQ7H3IIvj6EXwpgipnUqEPMAyv5c8iFmiUEaNmFFgFDJq3UZ7pZzhc n8c2Q3tue/suw7YdxQR1tMGZIONLVNr8HLSrONNshuCKOYll/7f6dLG0/05Z0ePQwr NHqrC5uHyG6PPwoZrRVr0qxANOAzzc1o/RyxKfXws3s7RTqa30dHWTaaw7lEtZELUl BrDuSczsfhNPYsoC8KFyoPHFf1uVACJ9/6PZ45ZjFLjWeDiLZdnVl5feZ0miXXBAMF WxSJBfFGjAGcA3dtxhIhs246cZXJFiigCETLwxTgiIWV5wEu0vcfFcf1UUlDFD1dXm zD/EiAzXr73kg== From: Tzung-Bi Shih To: Benson Leung , Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich Cc: Jonathan Corbet , Shuah Khan , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, linux-kselftest@vger.kernel.org, tzungbi@kernel.org, Laurent Pinchart , Bartosz Golaszewski , Wolfram Sang , Simona Vetter , Dan Williams , Jason Gunthorpe Subject: [PATCH v6 2/3] char: misc: Leverage revocable fops replacement Date: Thu, 6 Nov 2025 23:27:11 +0800 Message-ID: <20251106152712.11850-3-tzungbi@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251106152712.11850-1-tzungbi@kernel.org> References: <20251106152712.11850-1-tzungbi@kernel.org> 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" Leverage revocable fops replacement if the driver requests. The "resource" in the context means presence of the miscdevice. It prevents file operations (except .release()) in drivers to be called if the miscdevice no longer exists. Signed-off-by: Tzung-Bi Shih --- v6: - Call fs_revocable_replace() after f_op->open() and modify the API usage accordingly. - Use presence of miscdevice as a virtual resource. v5: https://lore.kernel.org/chrome-platform/20251016054204.1523139-7-tzungb= i@kernel.org - No primary changes but modify the API usage accordingly to support multiple revocable providers. v4: https://lore.kernel.org/chrome-platform/20250923075302.591026-7-tzungbi= @kernel.org - New in the series. drivers/char/misc.c | 18 ++++++++++++++++-- include/linux/miscdevice.h | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/char/misc.c b/drivers/char/misc.c index 726516fb0a3b..e0106270c188 100644 --- a/drivers/char/misc.c +++ b/drivers/char/misc.c @@ -50,6 +50,8 @@ #include #include #include +#include +#include =20 /* * Head entry for the doubly linked miscdevice list @@ -157,10 +159,16 @@ static int misc_open(struct inode *inode, struct file= *file) */ file->private_data =3D c; =20 - err =3D 0; replace_fops(file, new_fops); - if (file->f_op->open) + + if (file->f_op->open) { err =3D file->f_op->open(inode, file); + if (err) + goto fail; + } + + if (c->revocable) + err =3D fs_revocable_replace(c->rp, file); fail: mutex_unlock(&misc_mtx); return err; @@ -218,6 +226,10 @@ int misc_register(struct miscdevice *misc) return -EINVAL; } =20 + misc->rp =3D revocable_provider_alloc(misc); + if (!misc->rp) + return -ENOMEM; + INIT_LIST_HEAD(&misc->list); =20 mutex_lock(&misc_mtx); @@ -290,6 +302,8 @@ void misc_deregister(struct miscdevice *misc) if (misc->minor > MISC_DYNAMIC_MINOR) misc->minor =3D MISC_DYNAMIC_MINOR; mutex_unlock(&misc_mtx); + + revocable_provider_revoke(misc->rp); } EXPORT_SYMBOL(misc_deregister); =20 diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h index 7d0aa718499c..85fac108e485 100644 --- a/include/linux/miscdevice.h +++ b/include/linux/miscdevice.h @@ -92,6 +92,8 @@ struct miscdevice { const struct attribute_group **groups; const char *nodename; umode_t mode; + bool revocable; + struct revocable_provider *rp; }; =20 extern int misc_register(struct miscdevice *misc); --=20 2.48.1