• Fabio Estevam's avatar
    mtd: fsl-quadspi: Fix module unbound · cfe4af3a
    Fabio Estevam authored
    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: default avatarFabio Estevam <fabio.estevam@freescale.com>
    Acked-by: default avatarHuang Shijie <shijie.huang@intel.com>
    Tested-by: default avatarFrank Li <Frank.Li@freescale.com>
    Acked-by: default avatarAllen Xu <han.xu@freescale.com>
    Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
    cfe4af3a
fsl-quadspi.c 24.8 KB