Skip to contentSkip to conversation

mtd: m25p80: make command buffer DMA-safe

PATCH Applied Johannes Stezenbach 2 participants 4 messages Oct 28, 2009 – Nov 10, 2009 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: m25p80: make command buffer DMA-safe

spi_write() requires the buffer to be DMA-safe, kmalloc() it seperately to ensure this.

drivers/mtd/devices/m25p80.c +9 -2
index 4c19269..21dd4d9 100644
@@ -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;
+	}
 
 	flash->spi = spi;
 	mutex_init(&flash->lock);
@@ -888,8 +893,10 @@ static int __devexit m25p_remove(struct spi_device *spi)
 		status = del_mtd_partitions(&flash->mtd);
 	else
 		status = del_mtd_device(&flash->mtd);
-	if (status == 0)
+	if (status == 0) {
+		kfree(flash->command);
 		kfree(flash);
+	}
 	return 0;
 }
 
#1 lore raw
Quoted 20 lines · Johannes Stezenbach

spi_write() requires the buffer to be DMA-safe, kmalloc() it seperately to ensure this.

drivers/mtd/devices/m25p80.c +1 -1
index 4c19269..21dd4d9 100644
@@ -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)

drivers/mtd/devices/m25p80.c static int __devinit m25p_probe(struct spi_device *spi) · line 777

Quoted 8 lines
drivers/mtd/devices/m25p80.c +5 -0
@@ -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.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#2 lore raw
Quoted 9 lines · Artem Bityutskiy
Quoted 2 lines · Johannes Stezenbach

spi_write() requires the buffer to be DMA-safe, kmalloc() it seperately to ensure this.

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.

It fixes a real error -- with an out-of-tree driver and ancient kernel. For the flash read/write case it is used with list-DMA (e.g. write 4 bytes, read 64KB). There are extensive comments in include/linux/spi/spi.h which document the DMA-safe requirement of the buffers.

Thanks
Johannes

#3 lore raw
Quoted 8 lines · Johannes Stezenbach
Quoted 7 lines · Artem Bityutskiy
Quoted 2 lines · Johannes Stezenbach

spi_write() requires the buffer to be DMA-safe, kmalloc() it seperately to ensure this.

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?

Quoted 7 lines
Quoted 2 lines

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.

It fixes a real error -- with an out-of-tree driver and ancient kernel. For the flash read/write case it is used with list-DMA (e.g. write 4 bytes, read 64KB). There are extensive comments in include/linux/spi/spi.h which document the DMA-safe requirement of the buffers.

Pushed to my l2-mtd-2.6 tree, thanks.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)