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

Hi,

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  | 24 ++++++++++++++++++++++++
 drivers/base/property.c  | 26 ++++++++++++++++++++++++++
 drivers/of/property.c    |  8 ++++++++
 include/linux/fwnode.h   |  3 +++
 include/linux/property.h |  2 ++
 5 files changed, 63 insertions(+)

-- 
2.19.1


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

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

This helper returns the name of the node. The name is
primarily expected to be returned from a new fwnode
operation meant for this purpose, but when no name is
returned, the helper will also attempt to read a device
property "name".

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

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 240ab5230ff6..f4a3270b3de6 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1156,6 +1156,32 @@ void fwnode_handle_put(struct fwnode_handle *fwnode)
 }
 EXPORT_SYMBOL_GPL(fwnode_handle_put);
 
+/**
+ * fwnode_get_name - Read the name of a node
+ * @fwnode: Pointer to the node.
+ * @buf: Buffer where the name is copied to
+ * @len: Size of the buffer
+ *
+ * Reads the node name of @fwnode with get_name fwnode op. If get_name op fails,
+ * the routine attempts to also read a property "name".
+ */
+int fwnode_get_name(const struct fwnode_handle *fwnode, char *buf, size_t len)
+{
+	const char *name;
+	int ret;
+
+	if (!fwnode_call_int_op(fwnode, get_name, buf, len))
+		return 0;
+
+	ret = fwnode_call_int_op(fwnode, property_read_string_array,
+				 "name", &name, 1);
+	if (!ret)
+		snprintf(buf, len, "%s", name);
+
+	return ret;
+}
+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 ac8a1ebc4c1b..e77f08f49c48 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.1


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

* [PATCH v3 2/3] ACPI: property: Add acpi_fwnode_name()
  2018-11-26 11:47 [PATCH v3 0/3] device property: Add fwnode_get_name() helper Heikki Krogerus
  2018-11-26 11:47 ` [PATCH v3 1/3] device property: Introduce fwnode_get_name() Heikki Krogerus
@ 2018-11-26 11:47 ` Heikki Krogerus
  2018-11-26 13:04   ` Andy Shevchenko
  2018-11-26 11:47 ` [PATCH v3 3/3] of/property: Add of_fwnode_name() Heikki Krogerus
  2 siblings, 1 reply; 8+ messages in thread
From: Heikki Krogerus @ 2018-11-26 11:47 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Mika Westerberg, Andy Shevchenko, 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 | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 8c7c4583b52d..a38daa6f32cb 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1219,6 +1219,29 @@ 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_handle handle;
+	acpi_status status;
+
+	if (is_acpi_data_node(fwnode)) {
+		snprintf(buf, len, "%s", to_acpi_data_node(fwnode)->name);
+		return 0;
+	}
+
+	handle = to_acpi_device_node(fwnode)->handle;
+
+	buffer.length = min((size_t)ACPI_NAME_SIZE + 1, len);
+	buffer.pointer = buf;
+
+	status = acpi_get_name(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))
@@ -1310,6 +1333,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.1


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

* [PATCH v3 3/3] of/property: Add of_fwnode_name()
  2018-11-26 11:47 [PATCH v3 0/3] device property: Add fwnode_get_name() helper Heikki Krogerus
  2018-11-26 11:47 ` [PATCH v3 1/3] device property: Introduce fwnode_get_name() Heikki Krogerus
  2018-11-26 11:47 ` [PATCH v3 2/3] ACPI: property: Add acpi_fwnode_name() Heikki Krogerus
@ 2018-11-26 11:47 ` Heikki Krogerus
  2018-11-26 13:05   ` Andy Shevchenko
  2 siblings, 1 reply; 8+ messages in thread
From: Heikki Krogerus @ 2018-11-26 11:47 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Mika Westerberg, Andy Shevchenko, 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 | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index f46828e3b082..253ed0e9d804 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -823,6 +823,13 @@ 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)
+{
+	snprintf(buf, len, "%pOFn", to_of_node(fwnode));
+	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 +994,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.1


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

* Re: [PATCH v3 1/3] device property: Introduce fwnode_get_name()
  2018-11-26 11:47 ` [PATCH v3 1/3] device property: Introduce fwnode_get_name() Heikki Krogerus
@ 2018-11-26 12:56   ` Andy Shevchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-11-26 12:56 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Rafael J. Wysocki, Mika Westerberg, Rob Herring, Frank Rowand,
	linux-kernel, linux-acpi, devicetree

On Mon, Nov 26, 2018 at 02:47:50PM +0300, Heikki Krogerus wrote:
> This helper returns the name of the node. The name is
> primarily expected to be returned from a new fwnode
> operation meant for this purpose, but when no name is
> returned, the helper will also attempt to read a device
> property "name".

> +int fwnode_get_name(const struct fwnode_handle *fwnode, char *buf, size_t len)
> +{
> +	const char *name;
> +	int ret;
> +
> +	if (!fwnode_call_int_op(fwnode, get_name, buf, len))
> +		return 0;
> +
> +	ret = fwnode_call_int_op(fwnode, property_read_string_array,
> +				 "name", &name, 1);
> +	if (!ret)
> +		snprintf(buf, len, "%s", name);

What are we going to do in case snprintf has found no room for entire string?

> +
> +	return ret;
> +}

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v3 2/3] ACPI: property: Add acpi_fwnode_name()
  2018-11-26 11:47 ` [PATCH v3 2/3] ACPI: property: Add acpi_fwnode_name() Heikki Krogerus
@ 2018-11-26 13:04   ` Andy Shevchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-11-26 13:04 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Rafael J. Wysocki, Mika Westerberg, Rob Herring, Frank Rowand,
	linux-kernel, linux-acpi, devicetree

On Mon, Nov 26, 2018 at 02:47:51PM +0300, Heikki Krogerus wrote:
> This implements the get_name fwnode op for ACPI.

> +static int
> +acpi_fwnode_get_name(const struct fwnode_handle *fwnode, char *buf, size_t len)
> +{
> +	struct acpi_buffer buffer;
> +	acpi_handle handle;
> +	acpi_status status;
> +
> +	if (is_acpi_data_node(fwnode)) {
> +		snprintf(buf, len, "%s", to_acpi_data_node(fwnode)->name);

Same question as per patch 1. How are we going to handle bigger strings?

> +		return 0;
> +	}
> +
> +	handle = to_acpi_device_node(fwnode)->handle;
> +

> +	buffer.length = min((size_t)ACPI_NAME_SIZE + 1, len);

Hmm...

 min_t(size_t, ...) ?


> +	buffer.pointer = buf;
> +
> +	status = acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);

And same question here. Is it possible to get length of the name and check?

Perhaps, I would return -ENAMETOOLONG (-EOVERFLOW) or alike for such cases.

> +	if (ACPI_FAILURE(status))
> +		return -ENXIO;
> +	return 0;
> +}

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v3 3/3] of/property: Add of_fwnode_name()
  2018-11-26 11:47 ` [PATCH v3 3/3] of/property: Add of_fwnode_name() Heikki Krogerus
@ 2018-11-26 13:05   ` Andy Shevchenko
  2018-11-26 13:40     ` Heikki Krogerus
  0 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2018-11-26 13:05 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Rafael J. Wysocki, Mika Westerberg, Rob Herring, Frank Rowand,
	linux-kernel, linux-acpi, devicetree

On Mon, Nov 26, 2018 at 02:47:52PM +0300, Heikki Krogerus wrote:
> This implements get_name fwnode op for DT.

> +static int of_fwnode_get_name(const struct fwnode_handle *fwnode, char *buf,
> +			      size_t len)
> +{
> +	snprintf(buf, len, "%pOFn", to_of_node(fwnode));

Same concerns.

> +	return 0;
> +}

-- 
With Best Regards,
Andy Shevchenko



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

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

On Mon, Nov 26, 2018 at 03:05:32PM +0200, Andy Shevchenko wrote:
> On Mon, Nov 26, 2018 at 02:47:52PM +0300, Heikki Krogerus wrote:
> > This implements get_name fwnode op for DT.
> 
> > +static int of_fwnode_get_name(const struct fwnode_handle *fwnode, char *buf,
> > +			      size_t len)
> > +{
> > +	snprintf(buf, len, "%pOFn", to_of_node(fwnode));
> 
> Same concerns.

OK, I'll fix all of these.

thanks,

-- 
heikki

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

end of thread, other threads:[~2018-11-26 13:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-26 11:47 [PATCH v3 0/3] device property: Add fwnode_get_name() helper Heikki Krogerus
2018-11-26 11:47 ` [PATCH v3 1/3] device property: Introduce fwnode_get_name() Heikki Krogerus
2018-11-26 12:56   ` Andy Shevchenko
2018-11-26 11:47 ` [PATCH v3 2/3] ACPI: property: Add acpi_fwnode_name() Heikki Krogerus
2018-11-26 13:04   ` Andy Shevchenko
2018-11-26 11:47 ` [PATCH v3 3/3] of/property: Add of_fwnode_name() Heikki Krogerus
2018-11-26 13:05   ` Andy Shevchenko
2018-11-26 13:40     ` Heikki Krogerus

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).