All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: m25p80: make command buffer DMA-safe
@ 2009-10-28 13:21 Johannes Stezenbach
  2009-11-03  6:36   ` Artem Bityutskiy
  0 siblings, 1 reply; 7+ messages in thread
From: Johannes Stezenbach @ 2009-10-28 13:21 UTC (permalink / raw)
  To: David Woodhouse, David Brownell; +Cc: linux-mtd, linux-kernel

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

Signed-off-by: Johannes Stezenbach <js@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;
+	}
 
 	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;
 }
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] mtd: m25p80: make command buffer DMA-safe
  2009-10-28 13:21 [PATCH] mtd: m25p80: make command buffer DMA-safe Johannes Stezenbach
@ 2009-11-03  6:36   ` Artem Bityutskiy
  0 siblings, 0 replies; 7+ messages in thread
From: Artem Bityutskiy @ 2009-11-03  6:36 UTC (permalink / raw)
  To: Johannes Stezenbach
  Cc: David Woodhouse, David Brownell, linux-mtd, linux-kernel

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@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 (Артём Битюцкий)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mtd: m25p80: make command buffer DMA-safe
@ 2009-11-03  6:36   ` Artem Bityutskiy
  0 siblings, 0 replies; 7+ messages in thread
From: Artem Bityutskiy @ 2009-11-03  6:36 UTC (permalink / raw)
  To: Johannes Stezenbach
  Cc: linux-mtd, David Brownell, David Woodhouse, linux-kernel

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@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 (Артём Битюцкий)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mtd: m25p80: make command buffer DMA-safe
  2009-11-03  6:36   ` Artem Bityutskiy
@ 2009-11-03 10:00     ` Johannes Stezenbach
  -1 siblings, 0 replies; 7+ messages in thread
From: Johannes Stezenbach @ 2009-11-03 10:00 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: David Woodhouse, David Brownell, linux-mtd, linux-kernel

On Tue, Nov 03, 2009 at 08:36:05AM +0200, Artem Bityutskiy wrote:
> 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.
> 
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mtd: m25p80: make command buffer DMA-safe
@ 2009-11-03 10:00     ` Johannes Stezenbach
  0 siblings, 0 replies; 7+ messages in thread
From: Johannes Stezenbach @ 2009-11-03 10:00 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: linux-mtd, David Brownell, David Woodhouse, linux-kernel

On Tue, Nov 03, 2009 at 08:36:05AM +0200, Artem Bityutskiy wrote:
> 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.
> 
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mtd: m25p80: make command buffer DMA-safe
  2009-11-03 10:00     ` Johannes Stezenbach
@ 2009-11-10 14:54       ` Artem Bityutskiy
  -1 siblings, 0 replies; 7+ messages in thread
From: Artem Bityutskiy @ 2009-11-10 14:54 UTC (permalink / raw)
  To: Johannes Stezenbach
  Cc: David Woodhouse, David Brownell, linux-mtd, linux-kernel

On Tue, 2009-11-03 at 11:00 +0100, Johannes Stezenbach wrote:
> On Tue, Nov 03, 2009 at 08:36:05AM +0200, Artem Bityutskiy wrote:
> > 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.
> > 
> > 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.

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

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mtd: m25p80: make command buffer DMA-safe
@ 2009-11-10 14:54       ` Artem Bityutskiy
  0 siblings, 0 replies; 7+ messages in thread
From: Artem Bityutskiy @ 2009-11-10 14:54 UTC (permalink / raw)
  To: Johannes Stezenbach
  Cc: linux-mtd, David Brownell, David Woodhouse, linux-kernel

On Tue, 2009-11-03 at 11:00 +0100, Johannes Stezenbach wrote:
> On Tue, Nov 03, 2009 at 08:36:05AM +0200, Artem Bityutskiy wrote:
> > 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.
> > 
> > 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.

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

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-11-10 14:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-28 13:21 [PATCH] mtd: m25p80: make command buffer DMA-safe Johannes Stezenbach
2009-11-03  6:36 ` Artem Bityutskiy
2009-11-03  6:36   ` Artem Bityutskiy
2009-11-03 10:00   ` Johannes Stezenbach
2009-11-03 10:00     ` Johannes Stezenbach
2009-11-10 14:54     ` Artem Bityutskiy
2009-11-10 14:54       ` Artem Bityutskiy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.