mtd: m25p80: fix module autoloading for "jedec, spi-nor" and "spi-nor"

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Tue Jan 12 15:59:08 PST 2016


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=de57732da86288cae9a84bd6ce7cf1d1e21f8329
Commit:     de57732da86288cae9a84bd6ce7cf1d1e21f8329
Parent:     0501f2e5ff28a02295e42fc9e7164a20ef4c30d5
Author:     Brian Norris <computersforpeace at gmail.com>
AuthorDate: Mon Nov 16 14:34:50 2015 -0800
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Thu Nov 19 16:46:42 2015 -0800

    mtd: m25p80: fix module autoloading for "jedec, spi-nor" and "spi-nor"
    
    Commit 43163022927b ("mtd: m25p80: allow arbitrary OF matching for
    "jedec,spi-nor"") moved the "jedec,spi-nor" handling from the
    spi_device_id table to the of_match_table, to better handle matching
    complex device tree compatible strings. With that patch, device tree
    support works as expected when m25p80.c is built into the kernel.
    
    However, that commit ignored the fact that:
    
     (1) (non-DT) platform devices might want to use the "spi-nor" string
         for matching with this driver, rather than picking an arbitrary one
         like "m25p80"
     (2) the core SPI uevent/modalias code doesn't yet support kernel module
         autoloading via of_match_table strings; so for DT-based devices, it
         will only report (part of) the first compatible string used
    
    Problem (1) has been reported previously, and I forgot to patch it up
    afterward.
    
    Problem (2) was noticed recently here:
    http://lists.infradead.org/pipermail/linux-mtd/2015-October/062369.html
    https://lkml.org/lkml/2015/11/12/574
    
    Specifically, this patch fixes m25p80.ko module autoloading for cases
    like this:
    
    	flash at xxx {
    		compatible = "jedec,spi-nor";
    		...
    	};
    
    because modalias of "spi:spi-nor" (the only module loading info provided
    by the SPI core for this device) will now be listed as an alias in
    m25p80.ko.
    
    Notably, it does *not* help cases like this:
    
    	flash at xxx {
    		compatible = "vendor,shiny-new-device", "jedec,spi-nor";
    		...
    	};
    
    unless we also list "shiny-new-device" in m25p_ids[]. There has been
    discussion on future work for this issue here:
    https://lkml.org/lkml/2015/11/12/574
    
    Cc: Heiner Kallweit <hkallweit1 at gmail.com>
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
    Reviewed-by: Javier Martinez Canillas <javier at osg.samsung.com>
---
 drivers/mtd/devices/m25p80.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 6077c4a..1275357 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -163,7 +163,7 @@ static int m25p_probe(struct spi_device *spi)
 	struct m25p *flash;
 	struct spi_nor *nor;
 	enum read_mode mode = SPI_NOR_NORMAL;
-	char *flash_name = NULL;
+	char *flash_name;
 	int ret;
 
 	data = dev_get_platdata(&spi->dev);
@@ -202,6 +202,8 @@ static int m25p_probe(struct spi_device *spi)
 	 */
 	if (data && data->type)
 		flash_name = data->type;
+	else if (!strcmp(spi->modalias, "spi-nor"))
+		flash_name = NULL; /* auto-detect */
 	else
 		flash_name = spi->modalias;
 
@@ -236,6 +238,13 @@ static int m25p_remove(struct spi_device *spi)
  */
 static const struct spi_device_id m25p_ids[] = {
 	/*
+	 * Allow non-DT platform devices to bind to the "spi-nor" modalias, and
+	 * hack around the fact that the SPI core does not provide uevent
+	 * matching for .of_match_table
+	 */
+	{"spi-nor"},
+
+	/*
 	 * Entries not used in DTs that should be safe to drop after replacing
 	 * them with "nor-jedec" in platform data.
 	 */



More information about the linux-mtd-cvs mailing list