mtd: fsl-quadspi: Fix module unbound
authorFabio Estevam <fabio.estevam@freescale.com>
Tue, 13 Jan 2015 22:14:15 +0000 (20:14 -0200)
committerBrian Norris <computersforpeace@gmail.com>
Tue, 20 Jan 2015 20:37:57 +0000 (12:37 -0800)
commitcfe4af3aac3bd63e9caf548157805ca46ad7b073
tree8432c64db6f009425799a7e09c22b2321a1b12c9
parentfcc87a95195236b0935183361a72e4a98bf577d8
mtd: fsl-quadspi: Fix module unbound

When removing the fsl-quadspi module and running 'cat /proc/mtd' afterwards,
we see garbage data like:

$ rmmod  fsl-quadspi
$ cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00000000 00000000 "(null)"
mtd0: 00000000 00000000 "(null)"
mtd0: 00000000 00000000 "(null)"
...
mtd0: a22296c6c756e28 00000000 "(null)"
mtd0: a22296c6c756e28 3064746d "(null)"

If we continue doing multiple module load/unload operations, then it will also
lead to a kernel crash.

The reason for this is due to the wrong mtd index used in
mtd_device_unregister() in the remove function.

We need to keep the mtd unregister index aligned with the one used in the probe
function, which means we need to take into account the 'has_second_chip'
property. By doing so we can guarantee that the mtd index is the same in the
registration and unregistration functions.

With this patch applied we can load/unload the fsl-quadspi driver several times
and it will result in no crash.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Huang Shijie <shijie.huang@intel.com>
Tested-by: Frank Li <Frank.Li@freescale.com>
Acked-by: Allen Xu <han.xu@freescale.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
drivers/mtd/spi-nor/fsl-quadspi.c