[PATCH] mtd: m25p80: make command buffer DMA-safe

Artem Bityutskiy dedekind1 at gmail.com
Tue Nov 3 01:36:05 EST 2009


On Wed, 2009-10-28 at 14:21 +0100, Johannes Stezenbach wrote:
> spi_write() requires the buffer to be DMA-safe, kmalloc()
> it seperately to ensure this.
> 
> Signed-off-by: Johannes Stezenbach <js at sig21.net>
> 
> 
> diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
> index 4c19269..21dd4d9 100644
> --- a/drivers/mtd/devices/m25p80.c
> +++ b/drivers/mtd/devices/m25p80.c
> @@ -79,7 +79,7 @@ struct m25p {
>  	struct mtd_info		mtd;
>  	unsigned		partitioned:1;
>  	u8			erase_opcode;
> -	u8			command[CMD_SIZE + FAST_READ_DUMMY_BYTE];
> +	u8			*command;
>  };
>  
>  static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
> @@ -770,6 +770,11 @@ static int __devinit m25p_probe(struct spi_device *spi)
>  	flash = kzalloc(sizeof *flash, GFP_KERNEL);
>  	if (!flash)
>  		return -ENOMEM;
> +	flash->command = kmalloc(CMD_SIZE + FAST_READ_DUMMY_BYTE, GFP_KERNEL);
> +	if (!flash->command) {
> +		kfree(flash);
> +		return -ENOMEM;
> +	}

Even though it is just 4 or 5 bytes it can do DMA? Does not sound too
sane to use DMA in that case. Does this patch fix a real error?

I do not know much about SPI, but for me it sounds like there should be
a method to ask SPI to avoid using DMA, and you should use that method.

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)




More information about the linux-mtd mailing list