{"id":2234945,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2234945/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260508105448.31799-9-tzungbi@kernel.org/","project":{"id":42,"url":"http://patchwork.ozlabs.org/api/1.2/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":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260508105448.31799-9-tzungbi@kernel.org>","list_archive_url":null,"date":"2026-05-08T10:54:47","name":"[v10,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.2/people/83557/?format=json","name":"Tzung-Bi Shih","email":"tzungbi@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260508105448.31799-9-tzungbi@kernel.org/mbox/","series":[{"id":503368,"url":"http://patchwork.ozlabs.org/api/1.2/series/503368/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/list/?series=503368","date":"2026-05-08T10:54:39","name":"drivers/base: Introduce revocable","version":10,"mbox":"http://patchwork.ozlabs.org/series/503368/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2234945/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2234945/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-gpio+bounces-36452-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=sXJGYRyx;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.105.105.114; helo=tor.lore.kernel.org;\n envelope-from=linux-gpio+bounces-36452-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=\"sXJGYRyx\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])\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 4gBmKr40yNz1yCg\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 08 May 2026 20:57:36 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 2F96F307B062\n\tfor <incoming@patchwork.ozlabs.org>; Fri,  8 May 2026 10:56:07 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 4490936166A;\n\tFri,  8 May 2026 10:55:52 +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 ED1F6318BB3;\n\tFri,  8 May 2026 10:55:51 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 30407C2BCB0;\n\tFri,  8 May 2026 10:55:48 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1778237752; cv=none;\n b=J5mFSKVdGnRAFBmCaYiOPxVfaGofJ8QBd1Lom6uJle/+r+VAFnyTu1+pcDJBWLigS8mWe0VrWdchY+1sUogB2qK03RO3jUl37D1iEGUqIuvPHjTFa8LXfrKnubqtr/FC8mQVoGhyZMf8rhhWQyF3/txBPUDhmtYUvjGu3aeaE8Q=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1778237752; c=relaxed/simple;\n\tbh=1DmEc2GErHK0mCxvKEZD9XQqL2KQLPzOSBbYLDoi/+c=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=ADJPS+7+MTwULpeGWr4QMpOeKQhxKXX5EPyeNuaKRmYLdLwuVJbfgdlTIxQtTBKsTDJA5GukO2VmbJW/CezREGjxmqIFTXRcH+H00NpyIuqVJOk19x7H9TufgX0VEhxWUkKK7Zm2KBtOLBa31RCTYqQLvNznmGxdgxtkTB/eotY=","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=sXJGYRyx; 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=1778237751;\n\tbh=1DmEc2GErHK0mCxvKEZD9XQqL2KQLPzOSBbYLDoi/+c=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=sXJGYRyxgVUlE9u1TeueMhuBakpCo3M0BlG9TiZDZAF3n+vKWYBstijRzTI4KCD3A\n\t Xi/WZuXJ9JFk8YA2qXce+Err4rAFrxIhaSATVKapJIU5MTLpGhg65GjjJyd9UBLWW9\n\t 2Ul/T3mIdnwPMShbfpAmp1UiYEh33i3CfiQnuSOlji2QiAXAZU0FjW672T4wtNQrMW\n\t a5+nROgh99YrX7Lqdl+5bMMMyna8m9Zm1RS5Yxwl+mKgoLu8F/sR9Pahi7TSa8ybln\n\t RH6UFoztm8Iwzjdinn5+lRsy4RJSCeSiAwZMUC9kaXusc/hGh1D6DZ1QJHPP36n4pT\n\t RqJ4jsbzmUMmw==","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>","Subject":"[PATCH v10 8/9] platform/chrome: Protect cros_ec_device lifecycle\n with revocable","Date":"Fri,  8 May 2026 18:54:47 +0800","Message-ID":"<20260508105448.31799-9-tzungbi@kernel.org>","X-Mailer":"git-send-email 2.51.0","In-Reply-To":"<20260508105448.31799-1-tzungbi@kernel.org>","References":"<20260508105448.31799-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---\nv10:\n- No changes.\n\nv9: https://lore.kernel.org/all/20260427135841.96266-9-tzungbi@kernel.org\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":["v10","8/9"]}