All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] modpost: fix module autoloading for OF devices with generic compatible property
@ 2016-05-02 15:35 Philipp Zabel
  2016-05-02 21:53 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Philipp Zabel @ 2016-05-02 15:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: Javier Martinez Canillas, Brian Norris, Sjoerd Simons,
	Rusty Russell, Andrew Morton, Greg Kroah-Hartman, kernel,
	Philipp Zabel

Since the wildcard at the end of OF module aliases is gone, autoloading
of modules that don't match a device's last (most generic) compatible value
fails.

For example the CODA960 VPU on i.MX6Q has the SoC specific compatible
"fsl,imx6q-vpu" and the generic compatible "cnm,coda960". Since the driver
currently only works with knowledge about the SoC specific integration,
it doesn't list "cnm,cod960" in the module device table.
This results in the device compatible
"of:NvpuT<NULL>Cfsl,imx6q-vpuCcnm,coda960" not matching the module alias
"of:N*T*Cfsl,imx6q-vpu" anymore, whereas before commit 2f632369ab79
("modpost: don't add a trailing wildcard for OF module aliases") it
matched the module alias "of:N*T*Cfsl,imx6q-vpu*".

This patch adds two module aliases for each compatible, one without the
wildcard and one with "C*" appended.

  $ modinfo coda | grep imx6q
  alias:          of:N*T*Cfsl,imx6q-vpuC*
  alias:          of:N*T*Cfsl,imx6q-vpu

Fixes: 2f632369ab79 ("modpost: don't add a trailing wildcard for OF module aliases")
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 scripts/mod/file2alias.c | 69 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 45 insertions(+), 24 deletions(-)

diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 161dd0d..f35b21d 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -371,6 +371,49 @@ static void do_usb_table(void *symval, unsigned long size,
 		do_usb_entry_multi(symval + i, mod);
 }
 
+static void do_of_entry_multi(void *symval, struct module *mod)
+{
+	char alias[500];
+	int len;
+	char *tmp;
+
+	DEF_FIELD_ADDR(symval, of_device_id, name);
+	DEF_FIELD_ADDR(symval, of_device_id, type);
+	DEF_FIELD_ADDR(symval, of_device_id, compatible);
+
+	len = sprintf(alias, "of:N%sT%s", (*name)[0] ? *name : "*",
+		      (*type)[0] ? *type : "*");
+
+	if (compatible[0])
+		sprintf(&alias[len], "%sC%s", (*type)[0] ? "*" : "",
+			*compatible);
+
+	/* Replace all whitespace with underscores */
+	for (tmp = alias; tmp && *tmp; tmp++)
+		if (isspace(*tmp))
+			*tmp = '_';
+
+	buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias);
+	strcat(alias, "C");
+	add_wildcard(alias);
+	buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias);
+}
+
+static void do_of_table(void *symval, unsigned long size,
+			struct module *mod)
+{
+	unsigned int i;
+	const unsigned long id_size = SIZE_of_device_id;
+
+	device_id_check(mod->name, "of", size, id_size, symval);
+
+	/* Leave last one: it's the terminator. */
+	size -= id_size;
+
+	for (i = 0; i < size; i += id_size)
+		do_of_entry_multi(symval + i, mod);
+}
+
 /* Looks like: hid:bNvNpN */
 static int do_hid_entry(const char *filename,
 			     void *symval, char *alias)
@@ -684,30 +727,6 @@ static int do_pcmcia_entry(const char *filename,
 }
 ADD_TO_DEVTABLE("pcmcia", pcmcia_device_id, do_pcmcia_entry);
 
-static int do_of_entry (const char *filename, void *symval, char *alias)
-{
-	int len;
-	char *tmp;
-	DEF_FIELD_ADDR(symval, of_device_id, name);
-	DEF_FIELD_ADDR(symval, of_device_id, type);
-	DEF_FIELD_ADDR(symval, of_device_id, compatible);
-
-	len = sprintf(alias, "of:N%sT%s", (*name)[0] ? *name : "*",
-		      (*type)[0] ? *type : "*");
-
-	if (compatible[0])
-		sprintf(&alias[len], "%sC%s", (*type)[0] ? "*" : "",
-			*compatible);
-
-	/* Replace all whitespace with underscores */
-	for (tmp = alias; tmp && *tmp; tmp++)
-		if (isspace (*tmp))
-			*tmp = '_';
-
-	return 1;
-}
-ADD_TO_DEVTABLE("of", of_device_id, do_of_entry);
-
 static int do_vio_entry(const char *filename, void *symval,
 		char *alias)
 {
@@ -1348,6 +1367,8 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
 	/* First handle the "special" cases */
 	if (sym_is(name, namelen, "usb"))
 		do_usb_table(symval, sym->st_size, mod);
+	if (sym_is(name, namelen, "of"))
+		do_of_table(symval, sym->st_size, mod);
 	else if (sym_is(name, namelen, "pnp"))
 		do_pnp_device_entry(symval, sym->st_size, mod);
 	else if (sym_is(name, namelen, "pnp_card"))
-- 
2.8.0.rc3

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

* Re: [PATCH] modpost: fix module autoloading for OF devices with generic compatible property
  2016-05-02 15:35 [PATCH] modpost: fix module autoloading for OF devices with generic compatible property Philipp Zabel
@ 2016-05-02 21:53 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2016-05-02 21:53 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: linux-kernel, Javier Martinez Canillas, Brian Norris,
	Sjoerd Simons, Rusty Russell, Greg Kroah-Hartman, kernel

On Mon,  2 May 2016 17:35:39 +0200 Philipp Zabel <p.zabel@pengutronix.de> wrote:

> Since the wildcard at the end of OF module aliases is gone, autoloading
> of modules that don't match a device's last (most generic) compatible value
> fails.
> 
> For example the CODA960 VPU on i.MX6Q has the SoC specific compatible
> "fsl,imx6q-vpu" and the generic compatible "cnm,coda960". Since the driver
> currently only works with knowledge about the SoC specific integration,
> it doesn't list "cnm,cod960" in the module device table.
> This results in the device compatible
> "of:NvpuT<NULL>Cfsl,imx6q-vpuCcnm,coda960" not matching the module alias
> "of:N*T*Cfsl,imx6q-vpu" anymore, whereas before commit 2f632369ab79
> ("modpost: don't add a trailing wildcard for OF module aliases") it
> matched the module alias "of:N*T*Cfsl,imx6q-vpu*".
> 
> This patch adds two module aliases for each compatible, one without the
> wildcard and one with "C*" appended.
> 
>   $ modinfo coda | grep imx6q
>   alias:          of:N*T*Cfsl,imx6q-vpuC*
>   alias:          of:N*T*Cfsl,imx6q-vpu

I added this:

Cc: <stable@vger.kernel.org>    [4.5+]

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

end of thread, other threads:[~2016-05-02 21:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-02 15:35 [PATCH] modpost: fix module autoloading for OF devices with generic compatible property Philipp Zabel
2016-05-02 21:53 ` Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.