{"id":2228940,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2228940/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260427135841.96266-9-tzungbi@kernel.org/","project":{"id":42,"url":"http://patchwork.ozlabs.org/api/1.1/projects/42/?format=json","name":"Linux GPIO development","link_name":"linux-gpio","list_id":"linux-gpio.vger.kernel.org","list_email":"linux-gpio@vger.kernel.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260427135841.96266-9-tzungbi@kernel.org>","date":"2026-04-27T13:58:40","name":"[v9,8/9] platform/chrome: Protect cros_ec_device lifecycle with revocable","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"967877dc6cd7a2d832c257be61f06efeb8acf28b","submitter":{"id":83557,"url":"http://patchwork.ozlabs.org/api/1.1/people/83557/?format=json","name":"Tzung-Bi Shih","email":"tzungbi@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260427135841.96266-9-tzungbi@kernel.org/mbox/","series":[{"id":501655,"url":"http://patchwork.ozlabs.org/api/1.1/series/501655/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/list/?series=501655","date":"2026-04-27T13:58:32","name":"drivers/base: Introduce revocable","version":9,"mbox":"http://patchwork.ozlabs.org/series/501655/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2228940/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2228940/checks/","tags":{},"headers":{"Return-Path":"\n <linux-gpio+bounces-35581-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-gpio@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=nkOkoMTR;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-gpio+bounces-35581-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"nkOkoMTR\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g453K2LBCz1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 00:06:53 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 9EE61301C899\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 27 Apr 2026 14:00:21 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 628303D3CE3;\n\tMon, 27 Apr 2026 14:00:01 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 1754B3D3336;\n\tMon, 27 Apr 2026 14:00:01 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 16742C19425;\n\tMon, 27 Apr 2026 13:59:56 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777298401; cv=none;\n b=O0bguzkG940GhwRdJrsbAHzLdlCpF1r0182MP+ceFw0OUgxlYM/zW/yBoSQNSJijRvRocXI29KEVlyvGBB0oBVsO5lqYIxGaFdvA99yI4ya12T7KyJQm56K8f4YE/0l0D3ZzWpGJuz2a8tcLCk7gpRoLVEYZi020tvAQ90HzRgA=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777298401; c=relaxed/simple;\n\tbh=x6GmU/uqEIoUvn9KjuCPHep4bsxmmEYRRG84/GahgL0=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=InZCeLAGhmssYNpxTXpIidNbETouGVe1jzvu1OVanz+71Pcvulx2VaFuwmMcOqFL+CG+63t0nV7V+ooXUbfv698iq8b1RI/t5TVSxigz+blS2xJhSyMBiwEBPPHwXMgLhqsRocT15e/1yCxzO4QjBfDf5q2jU8PEutKVir8/rYo=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=nkOkoMTR; arc=none smtp.client-ip=10.30.226.201","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1777298400;\n\tbh=x6GmU/uqEIoUvn9KjuCPHep4bsxmmEYRRG84/GahgL0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=nkOkoMTRHVCkA5WFAQmObDCR+rqha3Ftt3wJjJTI/MQ6kwjp8XW6LNb7PHNykkDDt\n\t sb1l7kugIdIYj3kJdkSeJz5tl39oZFvybZWs2CGeTZhExvGTMk7+quMiqa6Ou7xPst\n\t qCnygcj4axMm14JxmHe+4lXiJJ/HVsiXOvpvwJUhMiNYi7tXu5wbxR3RYluscivoPk\n\t /YjXj3ZE/64xA35kSaT0mCu2jN6F9S/lRSjxhZwRZ4E0AVeExOVuuVyHs1QtneuPS3\n\t jIkXMdEl8AJTWAIecHR/o7AobqxVwkSqIuC22LFahuyg6JB69t4oPmaD9OkrfaH+Fp\n\t 0daaVWaz8OYaw==","From":"Tzung-Bi Shih <tzungbi@kernel.org>","To":"Arnd Bergmann <arnd@arndb.de>,\n\tGreg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\tBartosz Golaszewski <brgl@kernel.org>,\n\tLinus Walleij <linusw@kernel.org>","Cc":"Benson Leung <bleung@chromium.org>,\n\ttzungbi@kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\tchrome-platform@lists.linux.dev,\n\tdriver-core@lists.linux.dev,\n\tlinux-doc@vger.kernel.org,\n\tlinux-gpio@vger.kernel.org,\n\t\"Rafael J. Wysocki\" <rafael@kernel.org>,\n\tDanilo Krummrich <dakr@kernel.org>,\n\tJonathan Corbet <corbet@lwn.net>,\n\tShuah Khan <shuah@kernel.org>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tWolfram Sang <wsa+renesas@sang-engineering.com>,\n\tJason Gunthorpe <jgg@nvidia.com>,\n\tJohan Hovold <johan@kernel.org>,\n\t\"Paul E . McKenney\" <paulmck@kernel.org>,\n\tDan Williams <dan.j.williams@intel.com>","Subject":"[PATCH v9 8/9] platform/chrome: Protect cros_ec_device lifecycle with\n revocable","Date":"Mon, 27 Apr 2026 21:58:40 +0800","Message-ID":"<20260427135841.96266-9-tzungbi@kernel.org>","X-Mailer":"git-send-email 2.51.0","In-Reply-To":"<20260427135841.96266-1-tzungbi@kernel.org>","References":"<20260427135841.96266-1-tzungbi@kernel.org>","Precedence":"bulk","X-Mailing-List":"linux-gpio@vger.kernel.org","List-Id":"<linux-gpio.vger.kernel.org>","List-Subscribe":"<mailto:linux-gpio+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-gpio+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"The cros_ec_device can be unregistered when the underlying device is\nremoved.  Other kernel drivers that interact with the EC may hold a\npointer to the cros_ec_device, creating a risk of a use-after-free\nerror if the EC device is removed while still being referenced.\n\nTo prevent this, leverage the revocable and convert the underlying\ndevice drivers to resource providers of cros_ec_device.\n\nSigned-off-by: Tzung-Bi Shih <tzungbi@kernel.org>\n---\nv9:\n- New to the series.\n- Change revocable API usages accordingly.\n- Rename \"revocable_provider\" -> \"its_rev\".\n\nv5 - v8:\n- Doesn't exist.\n\nv4: https://lore.kernel.org/all/20250923075302.591026-5-tzungbi@kernel.org\n- No changes.\n\nv3: https://lore.kernel.org/all/20250912081718.3827390-5-tzungbi@kernel.org\n- Initialize the revocable provider in cros_ec_device_alloc() instead of\n  spreading in protocol device drivers.\n\nv2: https://lore.kernel.org/all/20250820081645.847919-5-tzungbi@kernel.org\n- Rename \"ref_proxy\" -> \"revocable\".\n\nv1: https://lore.kernel.org/all/20250814091020.1302888-3-tzungbi@kernel.org\n\n---\n drivers/platform/chrome/cros_ec.c           | 11 +++++++++++\n include/linux/platform_data/cros_ec_proto.h |  3 +++\n 2 files changed, 14 insertions(+)","diff":"diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c\nindex 1da79e3d215b..2702a1bbfeb5 100644\n--- a/drivers/platform/chrome/cros_ec.c\n+++ b/drivers/platform/chrome/cros_ec.c\n@@ -16,6 +16,7 @@\n #include <linux/platform_device.h>\n #include <linux/platform_data/cros_ec_commands.h>\n #include <linux/platform_data/cros_ec_proto.h>\n+#include <linux/revocable.h>\n #include <linux/slab.h>\n #include <linux/suspend.h>\n \n@@ -37,6 +38,7 @@ static void cros_ec_device_free(void *data)\n \n \tmutex_destroy(&ec_dev->lock);\n \tlockdep_unregister_key(&ec_dev->lockdep_key);\n+\trevocable_revoke(ec_dev->its_rev);\n }\n \n struct cros_ec_device *cros_ec_device_alloc(struct device *dev)\n@@ -47,6 +49,15 @@ struct cros_ec_device *cros_ec_device_alloc(struct device *dev)\n \tif (!ec_dev)\n \t\treturn NULL;\n \n+\tec_dev->its_rev = revocable_alloc(ec_dev);\n+\tif (!ec_dev->its_rev)\n+\t\treturn NULL;\n+\t/*\n+\t * Drop the extra reference for the caller as the caller is the\n+\t * resource provider.\n+\t */\n+\trevocable_put(ec_dev->its_rev);\n+\n \tec_dev->din_size = sizeof(struct ec_host_response) +\n \t\t\t   sizeof(struct ec_response_get_protocol_info) +\n \t\t\t   EC_MAX_RESPONSE_OVERHEAD;\ndiff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h\nindex de14923720a5..e8c3bd03403c 100644\n--- a/include/linux/platform_data/cros_ec_proto.h\n+++ b/include/linux/platform_data/cros_ec_proto.h\n@@ -12,6 +12,7 @@\n #include <linux/lockdep_types.h>\n #include <linux/mutex.h>\n #include <linux/notifier.h>\n+#include <linux/revocable.h>\n \n #include <linux/platform_data/cros_ec_commands.h>\n \n@@ -165,6 +166,7 @@ struct cros_ec_command {\n  * @pd: The platform_device used by the mfd driver to interface with the\n  *      PD behind an EC.\n  * @panic_notifier: EC panic notifier.\n+ * @its_rev: The revocable_provider to this device.\n  */\n struct cros_ec_device {\n \t/* These are used by other drivers that want to talk to the EC */\n@@ -211,6 +213,7 @@ struct cros_ec_device {\n \tstruct platform_device *pd;\n \n \tstruct blocking_notifier_head panic_notifier;\n+\tstruct revocable *its_rev;\n };\n \n /**\n","prefixes":["v9","8/9"]}