From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Cc: Daniel Scally <djrscally@gmail.com>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Bartosz Golaszewski <brgl@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Johan Hovold <johan@kernel.org>,
Hans Verkuil <hverkuil@kernel.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>,
Len Brown <lenb@kernel.org>, Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@kernel.org>,
Linus Walleij <linusw@kernel.org>,
linux-acpi@vger.kernel.org, driver-core@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
devicetree@vger.kernel.org, linux-gpio@vger.kernel.org
Subject: Re: [PATCH 4/9] device property: provide fwnode_property_get_names()
Date: Wed, 4 Nov 2026 23:17:37 +0200 [thread overview]
Message-ID: <auug8QoQ62ETGg1D@ashevche-desk.local> (raw)
In-Reply-To: <20261104-fwnode-for-each-prop-v1-4-6e28fe1c72c4@oss.qualcomm.com>
On Wed, Nov 04, 2026 at 03:03:46PM +0100, Bartosz Golaszewski wrote:
> Provide fwnode_property_get_names() - a new fwnode function that allows
> callers to retrieve the list of all properties of given firmware node.
...
> #include <linux/device.h>
> #include <linux/err.h>
> #include <linux/export.h>
> +#include <linux/minmax.h>
> #include <linux/of.h>
> #include <linux/property.h>
> #include <linux/phy.h>
> #include <linux/slab.h>
> #include <linux/string.h>
> +#include <linux/string_helpers.h>
You can replace string.h with string_helpers.h.
We already rely on the fact that the latter includes the former
elsewhere in the kernel.
> #include <linux/types.h>
> +/**
> + * fwnode_property_get_names - get the list of all properties of this fwnode
> + * @fwnode: Firmware node to get the list of properties for
> + * @props: Pointer to an array of strings. It will contain the address of the
> + * string list containing the property names.
> + *
> + * Return: Number of property names written into *props. If > 0, the caller must
> + * free the array with kfree_strarray(). *props is only valid for
> + * a positive return value.
> + * %-EINVAL if arguments are not valid
> + * %-ENXIO if no suitable firmware interface is present
> + * %-ENOMEM if memory allocation failed
> + * The list also includes the properties of the secondary firmware node, if
> + * any. Properties present in both nodes are listed once.
I don't know if this paragraph is for Return section or not. If not, it should
go before as the Return section must be the last one in the kernel-doc (it's
documented). Otherwise I'm not sure it belongs to the Return section. I think
it would be better as a part of the description which should elaborate on the
returning values in the parameter.
> + */
> +int fwnode_property_get_names(const struct fwnode_handle *fwnode, char ***props)
Triple indirection is rare. Do we really need it?
> +{
> + int ret1, ret2 = -ENXIO, n1, n2, i, j, count;
> + char **prim = NULL, **sec = NULL, **merged;
> +
> + if (IS_ERR_OR_NULL(fwnode))
> + return -EINVAL;
> +
> + ret1 = fwnode_call_int_op(fwnode, property_get_names, &prim);
> + if (!IS_ERR_OR_NULL(fwnode->secondary))
> + ret2 = fwnode_call_int_op(fwnode->secondary, property_get_names, &sec);
> +
> + if (ret1 == -ENXIO && ret2 == -ENXIO)
> + return -ENXIO;
> +
> + n1 = max(ret1, 0);
> + n2 = max(ret2, 0);
> +
> + CLASS(strarray, prim_props)(prim, n1);
> + CLASS(strarray, sec_props)(sec, n2);
> +
> + if (ret1 < 0 && ret1 != -ENXIO)
> + return ret1;
> +
> + if (ret2 < 0 && ret2 != -ENXIO)
> + return ret2;
> + if (n1 == 0 && n2 == 0)
> + return 0;
Shouldn't these checks be before any CLASS()? Otherwise seems strange to me.
> + merged = kcalloc(n1 + n2, sizeof(*merged), GFP_KERNEL);
Shouldn't here be something from overflow.h?
> + if (!merged)
> + return -ENOMEM;
> +
> + /* The strings are now owned by merged, only free the container. */
> + for (i = 0; i < n1; i++) {
> + merged[i] = prim_props.array[i];
> + prim_props.array[i] = NULL;
> + }
> + count = n1;
> +
> + /* Properties from the primary node take precedence. */
> + for (i = 0; i < n2; i++) {
> + for (j = 0; j < n1; j++) {
> + if (!strcmp(merged[j], sec_props.array[i]))
> + break;
> + }
match_string() ?
> + if (j >= n1) {
> + merged[count++] = sec_props.array[i];
> + sec_props.array[i] = NULL;
> + }
> + }
> +
> + *props = merged;
> + return count;
> +}
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-04 21:17 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 14:03 [PATCH 0/9] gpio: make gpiolib-shared more fwnode-centric Bartosz Golaszewski
2026-11-04 14:03 ` [PATCH 1/9] device property: fix fwnode_name_eq() for empty node names Bartosz Golaszewski
2026-11-04 14:03 ` [PATCH 2/9] lib: string_helpers: implement a CLASS() for string arrays Bartosz Golaszewski
2026-11-04 21:07 ` Andy Shevchenko
2026-11-04 14:03 ` [PATCH 3/9] fwnode: define the property_get_names() operation Bartosz Golaszewski
2026-11-04 14:03 ` [PATCH 4/9] device property: provide fwnode_property_get_names() Bartosz Golaszewski
2026-11-04 21:17 ` Andy Shevchenko [this message]
2026-11-04 14:03 ` [PATCH 5/9] of: property: implement the .property_get_names() fwnode operation Bartosz Golaszewski
2026-11-04 21:21 ` Andy Shevchenko
2026-11-04 14:03 ` [PATCH 6/9] fwnode: define the count_references() " Bartosz Golaszewski
2026-11-04 14:03 ` [PATCH 7/9] device property: provide fwnode_property_count_references() Bartosz Golaszewski
2026-11-04 14:03 ` [PATCH 8/9] of: property: implement the count_references() fwnode operation Bartosz Golaszewski
2026-11-04 15:33 ` Rob Herring
2026-11-04 14:03 ` [PATCH 9/9] gpio: shared: generalize most code to firmware nodes Bartosz Golaszewski
2026-11-04 21:33 ` Andy Shevchenko
2026-11-05 6:28 ` kernel test robot
2026-11-05 7:34 ` kernel test robot
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=auug8QoQ62ETGg1D@ashevche-desk.local \
--to=andriy.shevchenko@linux.intel.com \
--cc=andy@kernel.org \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=brgl@kernel.org \
--cc=dakr@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=djrscally@gmail.com \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=hverkuil@kernel.org \
--cc=johan@kernel.org \
--cc=kees@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=lenb@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=saravanak@kernel.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
all inboxes | Powered by JetHome®