[PATCH 1/3] of: Add prefix parameter to of_modalias_node().

Subsystems: open firmware and flattened device tree, sound, sound - soc layer / dynamic audio power management (asoc), the rest

STALE5216d

7 messages, 2 authors, 2012-05-22 · open the first message on its own page

[PATCH 1/3] of: Add prefix parameter to of_modalias_node().

From: David Daney <hidden>
Date: 2012-05-11 22:05:43

From: David Daney <redacted>

When generating MODALIASes, it is convenient to add things like "spi:"
or "i2c:" to the front of the strings.  This allows the standard
modprobe to find the right driver when automatically populating bus
children from the device tree structure.

Add a prefix parameter, and adjust callers.  For
of_register_spi_devices() use the "spi:" prefix.

Signed-off-by: David Daney <redacted>
Cc: Liam Girdwood <redacted>
Cc: Timur Tabi <redacted>
Cc: Mark Brown <redacted>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <redacted>
Cc: alsa-devel@alsa-project.org
Cc: linuxppc-dev@lists.ozlabs.org
---
 drivers/of/base.c            |   22 ++++++++++++++++------
 drivers/of/of_i2c.c          |    2 +-
 drivers/of/of_spi.c          |    2 +-
 include/linux/of.h           |    3 ++-
 sound/soc/fsl/mpc8610_hpcd.c |    2 +-
 sound/soc/fsl/p1022_ds.c     |    2 +-
 6 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 5806449..f05a520 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -575,26 +575,36 @@ EXPORT_SYMBOL(of_find_matching_node);
 /**
  * of_modalias_node - Lookup appropriate modalias for a device node
  * @node:	pointer to a device tree node
+ * @prefix:	prefix to be added to the compatible property, may be NULL
  * @modalias:	Pointer to buffer that modalias value will be copied into
  * @len:	Length of modalias value
  *
- * Based on the value of the compatible property, this routine will attempt
- * to choose an appropriate modalias value for a particular device tree node.
- * It does this by stripping the manufacturer prefix (as delimited by a ',')
- * from the first entry in the compatible list property.
+ * Based on the value of the compatible property, this routine will
+ * attempt to choose an appropriate modalias value for a particular
+ * device tree node.  It does this by stripping the manufacturer
+ * prefix (as delimited by a ',') from the first entry in the
+ * compatible list property, and appending it to the prefix.
  *
  * This routine returns 0 on success, <0 on failure.
  */
-int of_modalias_node(struct device_node *node, char *modalias, int len)
+int of_modalias_node(struct device_node *node, const char *prefix,
+		     char *modalias, int len)
 {
 	const char *compatible, *p;
 	int cplen;
 
+	if (len < 1)
+		return -EINVAL;
+
 	compatible = of_get_property(node, "compatible", &cplen);
 	if (!compatible || strlen(compatible) > cplen)
 		return -ENODEV;
 	p = strchr(compatible, ',');
-	strlcpy(modalias, p ? p + 1 : compatible, len);
+	if (prefix)
+		strlcpy(modalias, prefix, len);
+	else
+		modalias[0] = 0;
+	strlcat(modalias, p ? p + 1 : compatible, len);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(of_modalias_node);
diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c
index f37fbeb..23b05ee 100644
--- a/drivers/of/of_i2c.c
+++ b/drivers/of/of_i2c.c
@@ -37,7 +37,7 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
 
 		dev_dbg(&adap->dev, "of_i2c: register %s\n", node->full_name);
 
-		if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) {
+		if (of_modalias_node(node, NULL, info.type, sizeof(info.type)) < 0) {
 			dev_err(&adap->dev, "of_i2c: modalias failure on %s\n",
 				node->full_name);
 			continue;
diff --git a/drivers/of/of_spi.c b/drivers/of/of_spi.c
index 6dbc074..c329c6d 100644
--- a/drivers/of/of_spi.c
+++ b/drivers/of/of_spi.c
@@ -42,7 +42,7 @@ void of_register_spi_devices(struct spi_master *master)
 		}
 
 		/* Select device driver */
-		if (of_modalias_node(nc, spi->modalias,
+		if (of_modalias_node(nc, SPI_MODULE_PREFIX, spi->modalias,
 				     sizeof(spi->modalias)) < 0) {
 			dev_err(&master->dev, "cannot find modalias for %s\n",
 				nc->full_name);
diff --git a/include/linux/of.h b/include/linux/of.h
index fa7fb1d..ee34d76 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -233,7 +233,8 @@ extern int of_n_addr_cells(struct device_node *np);
 extern int of_n_size_cells(struct device_node *np);
 extern const struct of_device_id *of_match_node(
 	const struct of_device_id *matches, const struct device_node *node);
-extern int of_modalias_node(struct device_node *node, char *modalias, int len);
+extern int of_modalias_node(struct device_node *node,
+			    const char *prefix, char *modalias, int len);
 extern struct device_node *of_parse_phandle(struct device_node *np,
 					    const char *phandle_name,
 					    int index);
diff --git a/sound/soc/fsl/mpc8610_hpcd.c b/sound/soc/fsl/mpc8610_hpcd.c
index 3fea5a1..1fa0682 100644
--- a/sound/soc/fsl/mpc8610_hpcd.c
+++ b/sound/soc/fsl/mpc8610_hpcd.c
@@ -254,7 +254,7 @@ static int codec_node_dev_name(struct device_node *np, char *buf, size_t len)
 	char temp[DAI_NAME_SIZE];
 	struct i2c_client *i2c;
 
-	of_modalias_node(np, temp, DAI_NAME_SIZE);
+	of_modalias_node(np, NULL, temp, DAI_NAME_SIZE);
 
 	iprop = of_get_property(np, "reg", NULL);
 	if (!iprop)
diff --git a/sound/soc/fsl/p1022_ds.c b/sound/soc/fsl/p1022_ds.c
index 982a1c9..3ea51ec 100644
--- a/sound/soc/fsl/p1022_ds.c
+++ b/sound/soc/fsl/p1022_ds.c
@@ -257,7 +257,7 @@ static int codec_node_dev_name(struct device_node *np, char *buf, size_t len)
 	char temp[DAI_NAME_SIZE];
 	struct i2c_client *i2c;
 
-	of_modalias_node(np, temp, DAI_NAME_SIZE);
+	of_modalias_node(np, NULL, temp, DAI_NAME_SIZE);
 
 	iprop = of_get_property(np, "reg", NULL);
 	if (!iprop)
-- 
1.7.2.3

Re: [PATCH 1/3] of: Add prefix parameter to of_modalias_node().

From: Grant Likely <hidden>
Date: 2012-05-20 05:54:41

On Fri, 11 May 2012 15:05:21 -0700, David Daney [off-list ref] wrote:
From: David Daney <redacted>

When generating MODALIASes, it is convenient to add things like "spi:"
or "i2c:" to the front of the strings.  This allows the standard
modprobe to find the right driver when automatically populating bus
children from the device tree structure.

Add a prefix parameter, and adjust callers.  For
of_register_spi_devices() use the "spi:" prefix.

Signed-off-by: David Daney <redacted>
Applied, thanks.  Some notes below...
quoted hunk
Cc: Liam Girdwood <redacted>
Cc: Timur Tabi <redacted>
Cc: Mark Brown <redacted>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <redacted>
Cc: alsa-devel@alsa-project.org
Cc: linuxppc-dev@lists.ozlabs.org
---
 drivers/of/base.c            |   22 ++++++++++++++++------
 drivers/of/of_i2c.c          |    2 +-
 drivers/of/of_spi.c          |    2 +-
 include/linux/of.h           |    3 ++-
 sound/soc/fsl/mpc8610_hpcd.c |    2 +-
 sound/soc/fsl/p1022_ds.c     |    2 +-
 6 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 5806449..f05a520 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -575,26 +575,36 @@ EXPORT_SYMBOL(of_find_matching_node);
 /**
  * of_modalias_node - Lookup appropriate modalias for a device node
  * @node:	pointer to a device tree node
+ * @prefix:	prefix to be added to the compatible property, may be NULL
  * @modalias:	Pointer to buffer that modalias value will be copied into
  * @len:	Length of modalias value
  *
- * Based on the value of the compatible property, this routine will attempt
- * to choose an appropriate modalias value for a particular device tree node.
- * It does this by stripping the manufacturer prefix (as delimited by a ',')
- * from the first entry in the compatible list property.
+ * Based on the value of the compatible property, this routine will
+ * attempt to choose an appropriate modalias value for a particular
+ * device tree node.  It does this by stripping the manufacturer
+ * prefix (as delimited by a ',') from the first entry in the
+ * compatible list property, and appending it to the prefix.
Not sure why this text block was reformatted.  I've formatted it back
to the way it was so the diff shows specifically what has changed in
the content.

I don't want to discourage cleanups, but I need to be careful that
cleanups don't obscure important changes when looking at the diff.

g.

Re: [PATCH 1/3] of: Add prefix parameter to of_modalias_node().

From: Grant Likely <hidden>
Date: 2012-05-20 06:08:07

On Sat, 19 May 2012 23:54:36 -0600, Grant Likely [off-list ref] wrote:
On Fri, 11 May 2012 15:05:21 -0700, David Daney [off-list ref] wrote:
quoted
From: David Daney <redacted>

When generating MODALIASes, it is convenient to add things like "spi:"
or "i2c:" to the front of the strings.  This allows the standard
modprobe to find the right driver when automatically populating bus
children from the device tree structure.

Add a prefix parameter, and adjust callers.  For
of_register_spi_devices() use the "spi:" prefix.

Signed-off-by: David Daney <redacted>
Applied, thanks.  Some notes below...
Wait... why is this necessary?  The module type prefix isn't stored in
the modalias value for any other bus type as far as I can see, and
with this series it appears that the "spi:" prefix may or may not be
present in the modalias.  That doesn't look right.

Why isn't prefixing spi: at uevent time sufficient?  IIUC, modprobe
depends on either UEVENT or the modalias attribute to know which
driver to probe.  It does look like the attribute is missing the spi:
prefix though.  Does the following change work instead of these two
patches?
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 3d8f662..da8aac7 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -51,7 +51,7 @@ modalias_show(struct device *dev, struct device_attribute *a, char *buf)
 {
        const struct spi_device *spi = to_spi_device(dev);
 
-       return sprintf(buf, "%s\n", spi->modalias);
+       return sprintf(buf, "%s%s\n", SPI_MODULE_PREFIX, spi->modalias);
 }
So, I've dropped this patch from my tree.  If the change above works
for you then I'll push it out.

g.

Re: [PATCH 1/3] of: Add prefix parameter to of_modalias_node().

From: David Daney <hidden>
Date: 2012-05-22 19:45:13

On 05/19/2012 11:08 PM, Grant Likely wrote:
On Sat, 19 May 2012 23:54:36 -0600, Grant Likely[off-list ref]  wrote:
quoted
On Fri, 11 May 2012 15:05:21 -0700, David Daney[off-list ref]  wrote:
quoted
From: David Daney<redacted>

When generating MODALIASes, it is convenient to add things like "spi:"
or "i2c:" to the front of the strings.  This allows the standard
modprobe to find the right driver when automatically populating bus
children from the device tree structure.

Add a prefix parameter, and adjust callers.  For
of_register_spi_devices() use the "spi:" prefix.

Signed-off-by: David Daney<redacted>
Applied, thanks.  Some notes below...
Wait... why is this necessary?
Because in of_register_spi_devices() in of_spi.c, you do:

	request_module(spi->modalias);

The string passed to request_module() must have the "spi:" prefix.

The module type prefix isn't stored in
the modalias value for any other bus type as far as I can see,
It is only useful with the prefix, so I though I would add it to the 
stored value.
and
with this series it appears that the "spi:" prefix may or may not be
present in the modalias.  That doesn't look right.
Perhaps, but the with the combination of patches 1/3 and 2/3 I tried to 
ensure that the prefix would always be present for SPI devices.
Why isn't prefixing spi: at uevent time sufficient?
Because udev may not be loading the driver.
IIUC, modprobe
depends on either UEVENT or the modalias attribute to know which
driver to probe.  It does look like the attribute is missing the spi:
prefix though.  Does the following change work instead of these two
patches?
No.
quoted hunk
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 3d8f662..da8aac7 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -51,7 +51,7 @@ modalias_show(struct device *dev, struct device_attribute *a, char *buf)
  {
         const struct spi_device *spi = to_spi_device(dev);

-       return sprintf(buf, "%s\n", spi->modalias);
+       return sprintf(buf, "%s%s\n", SPI_MODULE_PREFIX, spi->modalias);
  }
So, I've dropped this patch from my tree.  If the change above works
for you then I'll push it out.

g.

Re: [PATCH 1/3] of: Add prefix parameter to of_modalias_node().

From: Grant Likely <hidden>
Date: 2012-05-22 20:10:14

On Tue, May 22, 2012 at 1:45 PM, David Daney [off-list ref] wrote:
On 05/19/2012 11:08 PM, Grant Likely wrote:
quoted
On Sat, 19 May 2012 23:54:36 -0600, Grant
Likely[off-list ref] =A0wrote:
quoted
On Fri, 11 May 2012 15:05:21 -0700, David Daney[off-list ref]
=A0wrote:
quoted
From: David Daney<redacted>

When generating MODALIASes, it is convenient to add things like "spi:"
or "i2c:" to the front of the strings. =A0This allows the standard
modprobe to find the right driver when automatically populating bus
children from the device tree structure.

Add a prefix parameter, and adjust callers. =A0For
of_register_spi_devices() use the "spi:" prefix.

Signed-off-by: David Daney<redacted>

Applied, thanks. =A0Some notes below...

Wait... why is this necessary?

Because in of_register_spi_devices() in of_spi.c, you do:

=A0 =A0 =A0 =A0request_module(spi->modalias);

The string passed to request_module() must have the "spi:" prefix.
How about modifying the call to request_module() to include the prefix
also?  I think that would be a simpler change overall.  Would that
work?

g.

Re: [PATCH 1/3] of: Add prefix parameter to of_modalias_node().

From: David Daney <hidden>
Date: 2012-05-22 22:49:48

On 05/22/2012 01:09 PM, Grant Likely wrote:
On Tue, May 22, 2012 at 1:45 PM, David Daney[off-list ref]  wrote:
quoted
On 05/19/2012 11:08 PM, Grant Likely wrote:
quoted
On Sat, 19 May 2012 23:54:36 -0600, Grant
Likely[off-list ref]    wrote:
quoted
On Fri, 11 May 2012 15:05:21 -0700, David Daney[off-list ref]
  wrote:
quoted
From: David Daney<redacted>

When generating MODALIASes, it is convenient to add things like "spi:"
or "i2c:" to the front of the strings.  This allows the standard
modprobe to find the right driver when automatically populating bus
children from the device tree structure.

Add a prefix parameter, and adjust callers.  For
of_register_spi_devices() use the "spi:" prefix.

Signed-off-by: David Daney<redacted>

Applied, thanks.  Some notes below...

Wait... why is this necessary?

Because in of_register_spi_devices() in of_spi.c, you do:

        request_module(spi->modalias);

The string passed to request_module() must have the "spi:" prefix.
How about modifying the call to request_module() to include the prefix
also?  I think that would be a simpler change overall.  Would that
work?
It seems to.  I just sent such a patch in a new thread.

David Daney

Re: [PATCH 1/3] of: Add prefix parameter to of_modalias_node().

From: Grant Likely <hidden>
Date: 2012-05-22 23:02:13

Cool, thanks.

g.

On Tue, May 22, 2012 at 4:49 PM, David Daney [off-list ref] wrote:
On 05/22/2012 01:09 PM, Grant Likely wrote:
quoted
On Tue, May 22, 2012 at 1:45 PM, David Daney[off-list ref]
=A0wrote:
quoted
On 05/19/2012 11:08 PM, Grant Likely wrote:
quoted

On Sat, 19 May 2012 23:54:36 -0600, Grant
Likely[off-list ref] =A0 =A0wrote:
quoted

On Fri, 11 May 2012 15:05:21 -0700, David Daney<ddaney.cavm@gmail.com=
quoted
quoted
quoted
quoted
=A0wrote:
quoted

From: David Daney<redacted>

When generating MODALIASes, it is convenient to add things like "spi=
:"
quoted
quoted
quoted
quoted
quoted
or "i2c:" to the front of the strings. =A0This allows the standard
modprobe to find the right driver when automatically populating bus
children from the device tree structure.

Add a prefix parameter, and adjust callers. =A0For
of_register_spi_devices() use the "spi:" prefix.

Signed-off-by: David Daney<redacted>


Applied, thanks. =A0Some notes below...


Wait... why is this necessary?


Because in of_register_spi_devices() in of_spi.c, you do:

=A0 =A0 =A0 =A0request_module(spi->modalias);

The string passed to request_module() must have the "spi:" prefix.

How about modifying the call to request_module() to include the prefix
also? =A0I think that would be a simpler change overall. =A0Would that
work?

It seems to. =A0I just sent such a patch in a new thread.

David Daney


--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help