From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Xu Yang <xu.yang_2@nxp.com>,
linux-acpi@vger.kernel.org, driver-core@lists.linux.dev,
linux-kernel@vger.kernel.org
Cc: Daniel Scally <djrscally@gmail.com>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>
Subject: [PATCH v4 2/3] device property: Refactor to use RAII approach
Date: Thu, 11 Jun 2026 22:31:07 +0200 [thread overview]
Message-ID: <20260611203537.1786399-3-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20260611203537.1786399-1-andriy.shevchenko@linux.intel.com>
In a couple of functions code can be made cleaner with help of
__free() macro. Refactor these to use RAII approach.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/base/property.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/drivers/base/property.c b/drivers/base/property.c
index f7b30d9c8716..808e8a90c125 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -7,10 +7,10 @@
* Mika Westerberg <mika.westerberg@linux.intel.com>
*/
+#include <linux/cleanup.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/export.h>
-#include <linux/kconfig.h>
#include <linux/of.h>
#include <linux/property.h>
#include <linux/phy.h>
@@ -517,7 +517,6 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_string);
int fwnode_property_match_string(const struct fwnode_handle *fwnode,
const char *propname, const char *string)
{
- const char **values;
int nval, ret;
nval = fwnode_property_string_array_count(fwnode, propname);
@@ -527,20 +526,18 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode,
if (nval == 0)
return -ENODATA;
- values = kcalloc(nval, sizeof(*values), GFP_KERNEL);
+ const char **values __free(kfree) = kcalloc(nval, sizeof(*values), GFP_KERNEL);
if (!values)
return -ENOMEM;
ret = fwnode_property_read_string_array(fwnode, propname, values, nval);
if (ret < 0)
- goto out_free;
+ return ret;
ret = match_string(values, nval, string);
if (ret < 0)
- ret = -ENODATA;
+ return -ENODATA;
-out_free:
- kfree(values);
return ret;
}
EXPORT_SYMBOL_GPL(fwnode_property_match_string);
@@ -1128,8 +1125,9 @@ struct fwnode_handle *
fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode,
struct fwnode_handle *prev)
{
- struct fwnode_handle *ep, *port_parent = NULL;
const struct fwnode_handle *parent;
+ struct fwnode_handle *port_parent __free(fwnode_handle) = NULL;
+ struct fwnode_handle *ep;
/*
* If this function is in a loop and the previous iteration returned
@@ -1147,13 +1145,9 @@ fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode,
ep = fwnode_call_ptr_op(parent, graph_get_next_endpoint, prev);
if (ep)
- goto out_put_port_parent;
+ return ep;
- ep = fwnode_graph_get_next_endpoint(parent->secondary, NULL);
-
-out_put_port_parent:
- fwnode_handle_put(port_parent);
- return ep;
+ return fwnode_graph_get_next_endpoint(parent->secondary, NULL);
}
EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
--
2.50.1
next prev parent reply other threads:[~2026-06-11 20:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 20:31 [PATCH v4 0/3] device property: fix child iteration issues with secondary fwnodes Andy Shevchenko
2026-06-11 20:31 ` [PATCH v4 1/3] device property: fix infinite loop in fwnode_for_each_child_node() Andy Shevchenko
2026-06-12 6:47 ` Xu Yang
2026-06-11 20:31 ` Andy Shevchenko [this message]
2026-06-11 20:46 ` [PATCH v4 2/3] device property: Refactor to use RAII approach Rafael J. Wysocki
2026-06-11 21:12 ` Andy Shevchenko
2026-06-11 20:31 ` [PATCH v4 3/3] device property: add test cases for fwnode_for_each_child_node() Andy Shevchenko
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=20260611203537.1786399-3-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=dakr@kernel.org \
--cc=djrscally@gmail.com \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=xu.yang_2@nxp.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