public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-usb@vger.kernel.org, kernel-janitors@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Jonathan Cameron <Jonathan.Cameron@Huawei.com>,
	Xin Ji <xji@analogixsemi.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Julia Lawall <julia.lawall@inria.fr>
Subject: [PATCH 2] usb: typec: anx7411: Use scope-based resource management in anx7411_typec_port_probe()
Date: Fri, 28 Jun 2024 09:26:47 +0200	[thread overview]
Message-ID: <0d2704d9-202c-457b-a83d-75a427966564@web.de> (raw)
In-Reply-To: <20240606101757.0000331f@Huawei.com>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 28 Jun 2024 08:25:34 +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 some 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: fe6d8a9c8e64 ("usb: typec: anx7411: Add Analogix PD ANX7411 support")
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---

V2:
* The change description was extended as requested by patch reviewers.

* The tag “Reviewed-by” was added according to feedback by Heikki Krogerus.

* A “stable tag” was added.


V1:
Initial patch review
https://lore.kernel.org/r/889729ac-3fc5-4666-b9f5-ce6e588a341a@web.de/
https://lkml.org/lkml/2024/6/5/1276



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



 drivers/usb/typec/anx7411.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
index b12a07edc71b..9fb52f233a30 100644
--- a/drivers/usb/typec/anx7411.c
+++ b/drivers/usb/typec/anx7411.c
@@ -16,6 +16,7 @@
 #include <linux/of_graph.h>
 #include <linux/of_platform.h>
 #include <linux/pm_runtime.h>
+#include <linux/property.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 #include <linux/types.h>
@@ -1142,11 +1143,11 @@ static int anx7411_typec_port_probe(struct anx7411_data *ctx,
 {
 	struct typec_capability *cap = &ctx->typec.caps;
 	struct typec_params *typecp = &ctx->typec;
-	struct fwnode_handle *fwnode;
 	const char *buf;
 	int ret, i;

-	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;

@@ -1237,7 +1238,7 @@ static int anx7411_typec_port_probe(struct anx7411_data *ctx,
 		typecp->caps_flags |= HAS_SINK_WATT;
 	}

-	cap->fwnode = fwnode;
+	cap->fwnode = no_free_ptr(fwnode);

 	ctx->typec.role_sw = usb_role_switch_get(dev);
 	if (IS_ERR(ctx->typec.role_sw)) {
--
2.45.2



      parent reply	other threads:[~2024-06-28  7:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-05 17:11 [PATCH] usb: typec: anx7411: Use scope-based resource management in anx7411_typec_port_probe() Markus Elfring
2024-06-06  7:50 ` Heikki Krogerus
2024-06-06  8:40   ` Markus Elfring
2024-06-06  9:17 ` [PATCH] " Jonathan Cameron
2024-06-06 11:01   ` Markus Elfring
2024-06-28  7:26   ` 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=0d2704d9-202c-457b-a83d-75a427966564@web.de \
    --to=markus.elfring@web.de \
    --cc=Jonathan.Cameron@Huawei.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=julia.lawall@inria.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=xji@analogixsemi.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