linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 0/3] device property: Add fwnode_get_name() helper
@ 2018-12-11 13:14 Heikki Krogerus
  2018-12-11 13:14 ` [PATCH v6 1/3] device property: Introduce fwnode_get_name() Heikki Krogerus
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Heikki Krogerus @ 2018-12-11 13:14 UTC (permalink / raw)
  To: Rafael J. Wysocki, Andy Shevchenko
  Cc: Mika Westerberg, Rob Herring, Frank Rowand, linux-kernel,
	linux-acpi, devicetree

Hi,

Andy, I dropped you Reviewed-by tag because of the last change to this
series, so if you could check these again I would much appreciate.

Changes since v5:
- No longer reading "name" device property as fallback.

Changes since v4:
- No changes. There was an extra patch in v3. This was just a resend
  of v3 without that extra patch.

Changes since v3:
- I'm now returning -EOVERFLOW if the buffer is not big enough as
  proposed by Andy.

This is the cover letter from v3:

This is the third version of my proposal for this helper. The
second version can be checked here:
https://lkml.org/lkml/2018/11/8/1005

I'm now passing the length as proposed by both Rob and Andy. I'm also
leaving the .get_named_child_node fwnode op untouched.

--
heikki


Heikki Krogerus (3):
  device property: Introduce fwnode_get_name()
  ACPI: property: Add acpi_fwnode_name()
  of/property: Add of_fwnode_name()

 drivers/acpi/property.c  | 28 ++++++++++++++++++++++++++++
 drivers/base/property.c  | 17 +++++++++++++++++
 drivers/of/property.c    | 13 +++++++++++++
 include/linux/fwnode.h   |  3 +++
 include/linux/property.h |  2 ++
 5 files changed, 63 insertions(+)

-- 
2.19.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v6 1/3] device property: Introduce fwnode_get_name()
  2018-12-11 13:14 [PATCH v6 0/3] device property: Add fwnode_get_name() helper Heikki Krogerus
@ 2018-12-11 13:14 ` Heikki Krogerus
  2018-12-11 13:14 ` [PATCH v6 2/3] ACPI: property: Add acpi_fwnode_name() Heikki Krogerus
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Heikki Krogerus @ 2018-12-11 13:14 UTC (permalink / raw)
  To: Rafael J. Wysocki, Andy Shevchenko
  Cc: Mika Westerberg, Rob Herring, Frank Rowand, linux-kernel,
	linux-acpi, devicetree

This helper returns the name of the node.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/base/property.c  | 17 +++++++++++++++++
 include/linux/fwnode.h   |  3 +++
 include/linux/property.h |  2 ++
 3 files changed, 22 insertions(+)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 240cd0f40605..51a32bb27551 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -679,6 +679,23 @@ void fwnode_handle_put(struct fwnode_handle *fwnode)
 }
 EXPORT_SYMBOL_GPL(fwnode_handle_put);
 
+/**
+ * fwnode_get_name - Copy the name of an fwnode to a buffer
+ * @fwnode: Pointer to the node
+ * @buf: Buffer where the name is copied to
+ * @len: Size of the buffer
+ *
+ * Copies the node name of @fwnode to @buf. NOTE: @buf must be large enough to
+ * accommodate the name and trailing '\0'.
+ *
+ * Returns 0 on success or errno in case of an error.
+ */
+int fwnode_get_name(const struct fwnode_handle *fwnode, char *buf, size_t len)
+{
+	return fwnode_call_int_op(fwnode, get_name, buf, len);
+}
+EXPORT_SYMBOL_GPL(fwnode_get_name);
+
 /**
  * fwnode_device_is_available - check if a device is available for use
  * @fwnode: Pointer to the fwnode of the device.
diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index faebf0ca0686..a211b55a5da1 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -52,6 +52,7 @@ struct fwnode_reference_args {
  * struct fwnode_operations - Operations for fwnode interface
  * @get: Get a reference to an fwnode.
  * @put: Put a reference to an fwnode.
+ * @get_name: Get the name of an fwnode
  * @device_get_match_data: Return the device driver match data.
  * @property_present: Return true if a property is present.
  * @property_read_integer_array: Read an array of integer properties. Return
@@ -72,6 +73,8 @@ struct fwnode_reference_args {
 struct fwnode_operations {
 	struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
 	void (*put)(struct fwnode_handle *fwnode);
+	int (*get_name)(const struct fwnode_handle *fwnode, char *buf,
+			size_t len);
 	bool (*device_is_available)(const struct fwnode_handle *fwnode);
 	const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
 					     const struct device *dev);
diff --git a/include/linux/property.h b/include/linux/property.h
index 3789ec755fb6..14369f36b0b1 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -109,6 +109,8 @@ struct fwnode_handle *device_get_named_child_node(struct device *dev,
 struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
 void fwnode_handle_put(struct fwnode_handle *fwnode);
 
+int fwnode_get_name(const struct fwnode_handle *fwnode, char *name, size_t len);
+
 int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index);
 
 unsigned int device_get_child_node_count(struct device *dev);
-- 
2.19.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v6 2/3] ACPI: property: Add acpi_fwnode_name()
  2018-12-11 13:14 [PATCH v6 0/3] device property: Add fwnode_get_name() helper Heikki Krogerus
  2018-12-11 13:14 ` [PATCH v6 1/3] device property: Introduce fwnode_get_name() Heikki Krogerus
@ 2018-12-11 13:14 ` Heikki Krogerus
  2018-12-11 13:14 ` [PATCH v6 3/3] of/property: Add of_fwnode_name() Heikki Krogerus
  2018-12-11 13:59 ` [PATCH v6 0/3] device property: Add fwnode_get_name() helper Andy Shevchenko
  3 siblings, 0 replies; 8+ messages in thread
From: Heikki Krogerus @ 2018-12-11 13:14 UTC (permalink / raw)
  To: Rafael J. Wysocki, Andy Shevchenko
  Cc: Mika Westerberg, Rob Herring, Frank Rowand, linux-kernel,
	linux-acpi, devicetree

This implements the get_name fwnode op for ACPI.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/acpi/property.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 77abe0ec4043..27cf3b4a6f9b 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1230,6 +1230,33 @@ acpi_graph_get_remote_endpoint(const struct fwnode_handle *__fwnode)
 	return acpi_graph_get_child_prop_value(fwnode, "endpoint", endpoint_nr);
 }
 
+static int
+acpi_fwnode_get_name(const struct fwnode_handle *fwnode, char *buf, size_t len)
+{
+	struct acpi_buffer buffer;
+	acpi_status status;
+
+	if (is_acpi_data_node(fwnode)) {
+		if (len < strlen(to_acpi_data_node(fwnode)->name) + 1)
+			return -EOVERFLOW;
+		sprintf(buf, "%s", to_acpi_data_node(fwnode)->name);
+		return 0;
+	}
+
+	if (len < ACPI_NAME_SIZE + 1)
+		return -EOVERFLOW;
+
+	buffer.length = ACPI_NAME_SIZE + 1;
+	buffer.pointer = buf;
+
+	status = acpi_get_name(to_acpi_device_node(fwnode)->handle,
+			       ACPI_SINGLE_NAME, &buffer);
+	if (ACPI_FAILURE(status))
+		return -ENXIO;
+
+	return 0;
+}
+
 static bool acpi_fwnode_device_is_available(const struct fwnode_handle *fwnode)
 {
 	if (!is_acpi_device_node(fwnode))
@@ -1321,6 +1348,7 @@ acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
 
 #define DECLARE_ACPI_FWNODE_OPS(ops) \
 	const struct fwnode_operations ops = {				\
+		.get_name = acpi_fwnode_get_name,			\
 		.device_is_available = acpi_fwnode_device_is_available, \
 		.device_get_match_data = acpi_fwnode_device_get_match_data, \
 		.property_present = acpi_fwnode_property_present,	\
-- 
2.19.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v6 3/3] of/property: Add of_fwnode_name()
  2018-12-11 13:14 [PATCH v6 0/3] device property: Add fwnode_get_name() helper Heikki Krogerus
  2018-12-11 13:14 ` [PATCH v6 1/3] device property: Introduce fwnode_get_name() Heikki Krogerus
  2018-12-11 13:14 ` [PATCH v6 2/3] ACPI: property: Add acpi_fwnode_name() Heikki Krogerus
@ 2018-12-11 13:14 ` Heikki Krogerus
  2018-12-14  9:36   ` Rafael J. Wysocki
  2018-12-11 13:59 ` [PATCH v6 0/3] device property: Add fwnode_get_name() helper Andy Shevchenko
  3 siblings, 1 reply; 8+ messages in thread
From: Heikki Krogerus @ 2018-12-11 13:14 UTC (permalink / raw)
  To: Rafael J. Wysocki, Andy Shevchenko
  Cc: Mika Westerberg, Rob Herring, Frank Rowand, linux-kernel,
	linux-acpi, devicetree

This implements get_name fwnode op for DT.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/of/property.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 08430031bd28..5c10fdded473 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -823,6 +823,18 @@ static void of_fwnode_put(struct fwnode_handle *fwnode)
 	of_node_put(to_of_node(fwnode));
 }
 
+static int of_fwnode_get_name(const struct fwnode_handle *fwnode, char *buf,
+			      size_t len)
+{
+	const struct device_node *node = to_of_node(fwnode);
+
+	if (len < snprintf(NULL, 0, "%pOFn", node) + 1)
+		return -EOVERFLOW;
+
+	sprintf(buf, "%pOFn", node);
+	return 0;
+}
+
 static bool of_fwnode_device_is_available(const struct fwnode_handle *fwnode)
 {
 	return of_device_is_available(to_of_node(fwnode));
@@ -987,6 +999,7 @@ of_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
+	.get_name = of_fwnode_get_name,
 	.device_is_available = of_fwnode_device_is_available,
 	.device_get_match_data = of_fwnode_device_get_match_data,
 	.property_present = of_fwnode_property_present,
-- 
2.19.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v6 0/3] device property: Add fwnode_get_name() helper
  2018-12-11 13:14 [PATCH v6 0/3] device property: Add fwnode_get_name() helper Heikki Krogerus
                   ` (2 preceding siblings ...)
  2018-12-11 13:14 ` [PATCH v6 3/3] of/property: Add of_fwnode_name() Heikki Krogerus
@ 2018-12-11 13:59 ` Andy Shevchenko
  3 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-12-11 13:59 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Rafael J. Wysocki, Mika Westerberg, Rob Herring, Frank Rowand,
	linux-kernel, linux-acpi, devicetree

On Tue, Dec 11, 2018 at 04:14:48PM +0300, Heikki Krogerus wrote:
> Hi,
> 
> Andy, I dropped you Reviewed-by tag because of the last change to this
> series, so if you could check these again I would much appreciate.

They all looks fine,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> 
> Changes since v5:
> - No longer reading "name" device property as fallback.
> 
> Changes since v4:
> - No changes. There was an extra patch in v3. This was just a resend
>   of v3 without that extra patch.
> 
> Changes since v3:
> - I'm now returning -EOVERFLOW if the buffer is not big enough as
>   proposed by Andy.
> 
> This is the cover letter from v3:
> 
> This is the third version of my proposal for this helper. The
> second version can be checked here:
> https://lkml.org/lkml/2018/11/8/1005
> 
> I'm now passing the length as proposed by both Rob and Andy. I'm also
> leaving the .get_named_child_node fwnode op untouched.
> 
> --
> heikki
> 
> 
> Heikki Krogerus (3):
>   device property: Introduce fwnode_get_name()
>   ACPI: property: Add acpi_fwnode_name()
>   of/property: Add of_fwnode_name()
> 
>  drivers/acpi/property.c  | 28 ++++++++++++++++++++++++++++
>  drivers/base/property.c  | 17 +++++++++++++++++
>  drivers/of/property.c    | 13 +++++++++++++
>  include/linux/fwnode.h   |  3 +++
>  include/linux/property.h |  2 ++
>  5 files changed, 63 insertions(+)
> 
> -- 
> 2.19.2
> 

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v6 3/3] of/property: Add of_fwnode_name()
  2018-12-11 13:14 ` [PATCH v6 3/3] of/property: Add of_fwnode_name() Heikki Krogerus
@ 2018-12-14  9:36   ` Rafael J. Wysocki
  2018-12-14 17:46     ` Rob Herring
  0 siblings, 1 reply; 8+ messages in thread
From: Rafael J. Wysocki @ 2018-12-14  9:36 UTC (permalink / raw)
  To: Heikki Krogerus, Rob Herring
  Cc: Rafael J. Wysocki, Andy Shevchenko, Mika Westerberg,
	Frank Rowand, Linux Kernel Mailing List, ACPI Devel Maling List,
	devicetree

On Tue, Dec 11, 2018 at 2:15 PM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> This implements get_name fwnode op for DT.
>
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

Rob, any objections here?

> ---
>  drivers/of/property.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/drivers/of/property.c b/drivers/of/property.c
> index 08430031bd28..5c10fdded473 100644
> --- a/drivers/of/property.c
> +++ b/drivers/of/property.c
> @@ -823,6 +823,18 @@ static void of_fwnode_put(struct fwnode_handle *fwnode)
>         of_node_put(to_of_node(fwnode));
>  }
>
> +static int of_fwnode_get_name(const struct fwnode_handle *fwnode, char *buf,
> +                             size_t len)
> +{
> +       const struct device_node *node = to_of_node(fwnode);
> +
> +       if (len < snprintf(NULL, 0, "%pOFn", node) + 1)
> +               return -EOVERFLOW;
> +
> +       sprintf(buf, "%pOFn", node);
> +       return 0;
> +}
> +
>  static bool of_fwnode_device_is_available(const struct fwnode_handle *fwnode)
>  {
>         return of_device_is_available(to_of_node(fwnode));
> @@ -987,6 +999,7 @@ of_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
>  const struct fwnode_operations of_fwnode_ops = {
>         .get = of_fwnode_get,
>         .put = of_fwnode_put,
> +       .get_name = of_fwnode_get_name,
>         .device_is_available = of_fwnode_device_is_available,
>         .device_get_match_data = of_fwnode_device_get_match_data,
>         .property_present = of_fwnode_property_present,
> --
> 2.19.2
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v6 3/3] of/property: Add of_fwnode_name()
  2018-12-14  9:36   ` Rafael J. Wysocki
@ 2018-12-14 17:46     ` Rob Herring
  2018-12-17 12:15       ` Heikki Krogerus
  0 siblings, 1 reply; 8+ messages in thread
From: Rob Herring @ 2018-12-14 17:46 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Heikki Krogerus, Rafael J. Wysocki, Andy Shevchenko,
	Mika Westerberg, Frank Rowand, linux-kernel, linux-acpi,
	devicetree

On Fri, Dec 14, 2018 at 3:36 AM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Tue, Dec 11, 2018 at 2:15 PM Heikki Krogerus
> <heikki.krogerus@linux.intel.com> wrote:
> >
> > This implements get_name fwnode op for DT.
> >
> > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>
> Rob, any objections here?

Yes, what I said in v5.

At one point this series had a user which was finding a matching node
by name. Now there is no user, so I can't really say whether this API
makes sense or not.

There's generally only 2 uses for 'name' at least for DT. The first is
node matching by name. ICYMI, every case of that in the tree is now
replaced with of_node_name_eq(). Now the details of matching by node
name are contained within the DT API. The 2nd use of node names is
just informational purposes or to fill some other structure's name
string (e.g. struct resource). In these cases, device_node.full_name
can be used. The only difference is full_name includes the unit
address ('@1234' part) if there is one. For these uses, the kernel
shouldn't generally care what the name actually is, but that's not
really enforceable.

Rob

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v6 3/3] of/property: Add of_fwnode_name()
  2018-12-14 17:46     ` Rob Herring
@ 2018-12-17 12:15       ` Heikki Krogerus
  0 siblings, 0 replies; 8+ messages in thread
From: Heikki Krogerus @ 2018-12-17 12:15 UTC (permalink / raw)
  To: Rob Herring
  Cc: Rafael J. Wysocki, Rafael J. Wysocki, Andy Shevchenko,
	Mika Westerberg, Frank Rowand, linux-kernel, linux-acpi,
	devicetree

On Fri, Dec 14, 2018 at 11:46:02AM -0600, Rob Herring wrote:
> On Fri, Dec 14, 2018 at 3:36 AM Rafael J. Wysocki <rafael@kernel.org> wrote:
> >
> > On Tue, Dec 11, 2018 at 2:15 PM Heikki Krogerus
> > <heikki.krogerus@linux.intel.com> wrote:
> > >
> > > This implements get_name fwnode op for DT.
> > >
> > > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> >
> > Rob, any objections here?
> 
> Yes, what I said in v5.

I did address your comment in v5? The helper no longer tries to read
"name" property if the callback fails.

> At one point this series had a user which was finding a matching node
> by name. Now there is no user, so I can't really say whether this API
> makes sense or not.

That is a fair point. I choose to not to convert
fwnode_get_named_child_node() to use this helper because it would mean
we would have to allocate the buffer there, and I don't know if it's
worth it.

Let's forget about this for now. I was planning to use this helper for
matching a requested remote-endpoint (graph) device, but I'm not sure
if the node name is usable there.

I'll resend these as part of a real user for the API, if I ever have
one.


thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-12-17 12:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-11 13:14 [PATCH v6 0/3] device property: Add fwnode_get_name() helper Heikki Krogerus
2018-12-11 13:14 ` [PATCH v6 1/3] device property: Introduce fwnode_get_name() Heikki Krogerus
2018-12-11 13:14 ` [PATCH v6 2/3] ACPI: property: Add acpi_fwnode_name() Heikki Krogerus
2018-12-11 13:14 ` [PATCH v6 3/3] of/property: Add of_fwnode_name() Heikki Krogerus
2018-12-14  9:36   ` Rafael J. Wysocki
2018-12-14 17:46     ` Rob Herring
2018-12-17 12:15       ` Heikki Krogerus
2018-12-11 13:59 ` [PATCH v6 0/3] device property: Add fwnode_get_name() helper Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).