android_kernel_samsung_a7y1.../drivers/mtd/devices
Miquel Raynal 8a932fe9a3 mtd: spear_smi: Fix Write Burst mode
commit 69c7f4618c16b4678f8a4949b6bb5ace259c0033 upstream.

Any write with either dd or flashcp to a device driven by the
spear_smi.c driver will pass through the spear_smi_cpy_toio()
function. This function will get called for chunks of up to 256 bytes.
If the amount of data is smaller, we may have a problem if the data
length is not 4-byte aligned. In this situation, the kernel panics
during the memcpy:

    # dd if=/dev/urandom bs=1001 count=1 of=/dev/mtd6
    spear_smi_cpy_toio [620] dest c9070000, src c7be8800, len 256
    spear_smi_cpy_toio [620] dest c9070100, src c7be8900, len 256
    spear_smi_cpy_toio [620] dest c9070200, src c7be8a00, len 256
    spear_smi_cpy_toio [620] dest c9070300, src c7be8b00, len 233
    Unhandled fault: external abort on non-linefetch (0x808) at 0xc90703e8
    [...]
    PC is at memcpy+0xcc/0x330

The above error occurs because the implementation of memcpy_toio()
tries to optimize the number of I/O by writing 4 bytes at a time as
much as possible, until there are less than 4 bytes left and then
switches to word or byte writes.

Unfortunately, the specification states about the Write Burst mode:

        "the next AHB Write request should point to the next
	incremented address and should have the same size (byte,
	half-word or word)"

This means ARM architecture implementation of memcpy_toio() cannot
reliably be used blindly here. Workaround this situation by update the
write path to stick to byte access when the burst length is not
multiple of 4.

Fixes: f18dbbb1bfe0 ("mtd: ST SPEAr: Add SMI driver for serial NOR flash")
Cc: Russell King <linux@armlinux.org.uk>
Cc: Boris Brezillon <boris.brezillon@collabora.com>
Cc: stable@vger.kernel.org
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-04-07 13:06:47 +02:00
..
bcm47xxsflash.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
bcm47xxsflash.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
block2mtd.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
docg3.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
docg3.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
Kconfig A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
lart.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
m25p80.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
Makefile A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ms02-nv.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ms02-nv.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
mtd_dataflash.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
mtdram.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
phram.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
pmc551.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
powernv_flash.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
serial_flash_cmds.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
slram.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
spear_smi.c mtd: spear_smi: Fix Write Burst mode 2020-04-07 13:06:47 +02:00
sst25l.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
st_spi_fsm.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30