From nobody Wed Dec 17 16:30:01 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 DE2152459ED; Thu, 16 Oct 2025 05:43:03 +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=1760593384; cv=none; b=M6C4sK+lmpvYNKDIL2ed2qI3EsIPzbKb+maMwNLRGk9W5xv4DfdtkIVl8OrjtVdo6gEdzoq4aoqG+szE5sdtsPXamBycArHc6DDu31s+wTi3VoxtSmKhS9IVxT7TRh9hGgLMTPwGH0UHXCnkdhpHPEfrQCCg6qFywRIJi1iB8S0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760593384; c=relaxed/simple; bh=XRROXfFgCgBPt8A6SqNymPJ90XRaZ5e3kZHr9tE4vXs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YGJruG7l6ga0MyaX1hAeyPxSh9VSpOBFZb9DP4xwmCmIM0GJGhlqwqlul8ThHkHalHoEKEWqu49TePyjeRsEYjPbhUXl6/FjH/lu6s9aSffmtSQwKRKSET46dchxs9JB25/lAPMy4+mpxFqT0qJ9m68p0+XZUoumkYgdQVtU2M0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o2LoO9XD; 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="o2LoO9XD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30171C4CEFE; Thu, 16 Oct 2025 05:43:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760593383; bh=XRROXfFgCgBPt8A6SqNymPJ90XRaZ5e3kZHr9tE4vXs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o2LoO9XDGvNzglIKrvnX4JhNVvJtVwYpl4Q4GVfQPZ9TO08vCbUsPx/OOejz33+vc aKp95sXhQwwlYGG1peoIUTM3QCw9vyJgImBYX8vgRy0UBk0V/VszLS71Jb4yGpKb+d NOBRzfCe1D8bVSOvBlr2yEl0IdLusBSHS94Hp7HuAus4EtdUKK1z4sRdJ+0fH/4rUx 0RBnx7m3S56suXBI6PBRztvMphHqnI5N5B0Y4uV3aPTD2sslTPRvfkPJ//7r9QWlPf x6dKZj8ezQUYDx9APHuyhXZBjyTguROF/WUPqKJD/RqCCkKqvxv80O6dX4AQaRiNn+ D57tpE/1vuNeg== 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 v5 4/7] platform/chrome: Protect cros_ec_device lifecycle with revocable Date: Thu, 16 Oct 2025 05:42:01 +0000 Message-ID: <20251016054204.1523139-5-tzungbi@kernel.org> X-Mailer: git-send-email 2.51.0.788.g6d19910ace-goog In-Reply-To: <20251016054204.1523139-1-tzungbi@kernel.org> References: <20251016054204.1523139-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 --- v5: - No changes. v4: https://lore.kernel.org/chrome-platform/20250923075302.591026-5-tzungbi= @kernel.org - No changes. v3: https://lore.kernel.org/chrome-platform/20250912081718.3827390-5-tzungb= i@kernel.org - 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.788.g6d19910ace-goog