public inbox for chrome-platform@lists.linux.dev
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: bleung@chromium.org
Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org,
	dawidn@google.com, gregkh@linuxfoundation.org
Subject: [PATCH v2 6/6] platform/chrome: Manage struct cros_ec_device lifecycle by its refcount
Date: Tue,  8 Jul 2025 08:00:34 +0000	[thread overview]
Message-ID: <20250708080034.3425427-7-tzungbi@kernel.org> (raw)
In-Reply-To: <20250708080034.3425427-1-tzungbi@kernel.org>

Stop delegating the memory to dev-managed.  Use its own refcount for
managing the lifecycle.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
New patch in the v2 series.

 drivers/platform/chrome/cros_ec_proto.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index f23d0522da96..097ef1fb3658 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -1166,7 +1166,7 @@ EXPORT_SYMBOL_GPL(cros_ec_get_cmd_versions);
  */
 struct cros_ec_device *cros_ec_device_alloc(struct device *dev)
 {
-	struct cros_ec_device *ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
+	struct cros_ec_device *ec_dev = kzalloc(sizeof(*ec_dev), GFP_KERNEL);
 
 	if (ec_dev) {
 		ec_dev->dev = dev;
@@ -1190,7 +1190,9 @@ EXPORT_SYMBOL_GPL(cros_ec_device_get);
 
 static void cros_ec_device_release(struct kref *kref)
 {
-	/* Do nothing as the cros_ec_device is still dev-managed. */
+	struct cros_ec_device *ec_dev = container_of(kref, struct cros_ec_device, kref);
+
+	kfree(ec_dev);
 }
 
 /**
-- 
2.50.0.727.gbf7dc18ff4-goog


      parent reply	other threads:[~2025-07-08  8:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-08  8:00 [PATCH v2 0/6] platform/chrome: cros_ec_chardev: Fix a possible UAF Tzung-Bi Shih
2025-07-08  8:00 ` [PATCH v2 1/6] platform/chrome: cros_ec_chardev: Remove redundant struct field Tzung-Bi Shih
2025-07-08  8:00 ` [PATCH v2 2/6] platform/chrome: cros_ec_chardev: Decouple fops from struct cros_ec_dev Tzung-Bi Shih
2025-07-08  8:00 ` [PATCH v2 3/6] platform/chrome: Disallow sending commands through unregistered ec_dev Tzung-Bi Shih
2025-07-08  8:00 ` [PATCH v2 4/6] platform/chrome: Introduce cros_ec_device_alloc() Tzung-Bi Shih
2025-07-08  8:00 ` [PATCH v2 5/6] platform/chrome: cros_ec_chardev: Hold refcount of struct cros_ec_device Tzung-Bi Shih
2025-07-08  8:00 ` Tzung-Bi Shih [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250708080034.3425427-7-tzungbi@kernel.org \
    --to=tzungbi@kernel.org \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=dawidn@google.com \
    --cc=gregkh@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox