From nobody Thu Oct 2 20:27:49 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 F17A52D7DDF; Fri, 12 Sep 2025 08:18:24 +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=1757665105; cv=none; b=qThG4SIVZp3Mabp2mxXtqCjVNVXNl/t1VPN6aPCTzUiJLOovJ161IjQX7X3E23BOMloy8Pl7blYH7U8oMuChtKzJN6fHUSN+Iu0nIz95IDzk63oNJIIrWCzPg1pct2mcIeXurtzY+HnTkrH7oZMoVJbQJHRtTgyFk4ODUf1xg/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757665105; c=relaxed/simple; bh=Rbg3cLqijdLmtkNpgyEe7p44E/PCsoI9YpDR32oNjK4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LF+hBU95Clnevt3bZDIuQqjO4caIP/hBcypGCbpft1m6/fOJMVXafBD6ooDeZAeA4F3zqirMTCP5gqYH6NnGN92TGFTk9v6BmprimbUEPu1Zdd0WtasrOsqJZf4u1X9xtYuXP+5cN267ZT15uc4MrpM5YltZBesR4kWpmkuW+zc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k0eGVbdC; 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="k0eGVbdC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DD17C4CEFA; Fri, 12 Sep 2025 08:18:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757665104; bh=Rbg3cLqijdLmtkNpgyEe7p44E/PCsoI9YpDR32oNjK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k0eGVbdCVLF+MqeBrWVV1I3lZMJU6lu5pAuKsnFjigafi8L0zy0iqwSdV3NA+BxCX h/FLKYSRtaH/3TnZ97PLJJsW0K1jcDhvbjmMpNP9DLQvhEoDbeGQUA4Gb9fL4TtoRJ qvMST/w5D9o/eRGSUv8/laG6fS2Z3b9zLTYcZhonH1TbwVQwq56kOTOUjz5hvvkUp9 DFud4LYF2AskbHlIzK2AowMviL7MzZZ8X6A0pxrFWqx6wkYHGUfqyThOnzFDmi7Dli O4oL4x+zwk+Fghu46W9eWSHq4c9nVmBhmaz3aQKOOihBj/CJqi3kBZrTUS9QoXaeA3 3yLDbnYIpLVYw== From: Tzung-Bi Shih To: Benson Leung , Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich Cc: Jonathan Corbet , Shuah Khan , Dawid Niedzwiecki , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, linux-kselftest@vger.kernel.org, tzungbi@kernel.org Subject: [PATCH v3 4/5] platform/chrome: Protect cros_ec_device lifecycle with revocable Date: Fri, 12 Sep 2025 08:17:16 +0000 Message-ID: <20250912081718.3827390-5-tzungbi@kernel.org> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog In-Reply-To: <20250912081718.3827390-1-tzungbi@kernel.org> References: <20250912081718.3827390-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" The cros_ec_device can be unregistered when the underlying device is removed. Other kernel drivers that interact with the EC may hold a pointer to the cros_ec_device, creating a risk of a use-after-free error if the EC device is removed while still being referenced. To prevent this, leverage the revocable and convert the underlying device drivers to resource providers of cros_ec_device. Signed-off-by: Tzung-Bi Shih --- v3: - Initialize the revocable provider in cros_ec_device_alloc() instead of spreading in protocol device drivers. v2: https://lore.kernel.org/chrome-platform/20250820081645.847919-5-tzungbi= @kernel.org - Rename "ref_proxy" -> "revocable". v1: https://lore.kernel.org/chrome-platform/20250814091020.1302888-3-tzungb= i@kernel.org drivers/platform/chrome/cros_ec.c | 5 +++++ include/linux/platform_data/cros_ec_proto.h | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cr= os_ec.c index 1da79e3d215b..95e3e898e3da 100644 --- a/drivers/platform/chrome/cros_ec.c +++ b/drivers/platform/chrome/cros_ec.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include =20 @@ -47,6 +48,10 @@ struct cros_ec_device *cros_ec_device_alloc(struct devic= e *dev) if (!ec_dev) return NULL; =20 + ec_dev->revocable_provider =3D devm_revocable_provider_alloc(dev, ec_dev); + if (!ec_dev->revocable_provider) + return NULL; + ec_dev->din_size =3D sizeof(struct ec_host_response) + sizeof(struct ec_response_get_protocol_info) + EC_MAX_RESPONSE_OVERHEAD; diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/pl= atform_data/cros_ec_proto.h index de14923720a5..fbb6ca34a40f 100644 --- a/include/linux/platform_data/cros_ec_proto.h +++ b/include/linux/platform_data/cros_ec_proto.h @@ -12,6 +12,7 @@ #include #include #include +#include =20 #include =20 @@ -165,6 +166,7 @@ struct cros_ec_command { * @pd: The platform_device used by the mfd driver to interface with the * PD behind an EC. * @panic_notifier: EC panic notifier. + * @revocable_provider: The revocable_provider to this device. */ struct cros_ec_device { /* These are used by other drivers that want to talk to the EC */ @@ -211,6 +213,8 @@ struct cros_ec_device { struct platform_device *pd; =20 struct blocking_notifier_head panic_notifier; + + struct revocable_provider *revocable_provider; }; =20 /** --=20 2.51.0.384.g4c02a37b29-goog