mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: kernel-janitors@vger.kernel.org,
	Chanwoo Choi <cw00.choi@samsung.com>,
	MyungJoo Ham <myungjoo.ham@samsung.com>,
	Stanley Chang <stanley_chang@realtek.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Jonathan Cameron <Jonathan.Cameron@Huawei.com>,
	Julia Lawall <julia.lawall@inria.fr>
Subject: [PATCH v2] extcon: realtek: Prevent resource leak in extcon_rtk_type_c_init()
Date: Sat, 29 Jun 2024 11:44:43 +0200	[thread overview]
Message-ID: <a2f9f5bc-5e22-4b03-9cd7-5dad16743ca3@web.de> (raw)
In-Reply-To: <532aa50e-b8e5-4e8e-a2bd-a05fd81274dc@web.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 29 Jun 2024 11:30:06 +0200

The API documentation for the function “device_get_named_child_node”
contains the following information:
“…
The caller is responsible for calling fwnode_handle_put()
on the returned fwnode pointer.
…”

The mentioned requirement was not fulfilled so that a resource leak
will occur in error cases after a device_get_named_child_node() call
succeeded in this function implementation.

Thus apply scope-based resource management which became supported also
for this programming interface by contributions of Jonathan Cameron
on 2024-02-17.
See also the commit 59ed5e2d505bf5f9b4af64d0021cd0c96aec1f7c ("device
property: Add cleanup.h based fwnode_handle_put() scope based cleanup.").

* Use the attribute “__free(fwnode_handle)” accordingly.

* Reduce the scope for the local variable “fwnode”.

Cc: stable@vger.kernel.org
Fixes: 8a590d7371f0 ("extcon: add Realtek DHC RTD SoC Type-C driver")
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---

V2:
* The change description was extended.

* The summary phrase was adjusted.

* A “stable tag” was added.


I guess that clarifications can become interesting also for backporting concerns
because of the proposed software transformation.



 drivers/extcon/extcon-rtk-type-c.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/extcon/extcon-rtk-type-c.c b/drivers/extcon/extcon-rtk-type-c.c
index 19a01e663733..8a4b074fd745 100644
--- a/drivers/extcon/extcon-rtk-type-c.c
+++ b/drivers/extcon/extcon-rtk-type-c.c
@@ -18,6 +18,7 @@
 #include <linux/syscalls.h>
 #include <linux/suspend.h>
 #include <linux/debugfs.h>
+#include <linux/property.h>
 #include <linux/extcon.h>
 #include <linux/extcon-provider.h>
 #include <linux/sys_soc.h>
@@ -1237,7 +1238,6 @@ static int extcon_rtk_type_c_init(struct type_c_data *type_c)

 	if (!type_c->port) {
 		struct typec_capability typec_cap = { };
-		struct fwnode_handle *fwnode;
 		const char *buf;
 		int ret;

@@ -1246,7 +1246,8 @@ static int extcon_rtk_type_c_init(struct type_c_data *type_c)
 		typec_cap.driver_data = type_c;
 		typec_cap.ops = &type_c_port_ops;

-		fwnode = device_get_named_child_node(dev, "connector");
+		struct fwnode_handle *fwnode __free(fwnode_handle)
+					     = device_get_named_child_node(dev, "connector");
 		if (!fwnode)
 			return -EINVAL;

--
2.45.2


      parent reply	other threads:[~2024-06-29  9:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-04 20:06 [PATCH] extcon: realtek: Use scope-based resource management " Markus Elfring
2024-06-04 21:11 ` Andy Shevchenko
2024-06-29  9:44 ` Markus Elfring [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=a2f9f5bc-5e22-4b03-9cd7-5dad16743ca3@web.de \
    --to=markus.elfring@web.de \
    --cc=Jonathan.Cameron@Huawei.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=cw00.choi@samsung.com \
    --cc=julia.lawall@inria.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=myungjoo.ham@samsung.com \
    --cc=stanley_chang@realtek.com \
    /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

all inboxes | Powered by JetHome®