public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] nftl: fix offset alignments
       [not found] <605152405.3397101250633087167.JavaMail.root@zimbra3-e1.priv.proxad.net>
@ 2009-08-18 22:06 ` dimitri.gorokhovik
  2009-08-19 23:34   ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: dimitri.gorokhovik @ 2009-08-18 22:06 UTC (permalink / raw)
  To: David Woodhouse, David Woodhouse, Tim Gardner,
	Scott James Remnant, Julia Lawall, David Brownell
  Cc: linux-mtd, linux-kernel

Arithmetic conversion in the mask computation makes the upper word 
of the second argument passed down to mtd->read_oob(), be always 0
(assuming 'offs' being a 64-bit signed long long type, and 
'mtd->writesize' being a 32-bit unsigned int type). 

This patch applies over the other one adding masking in nftl_write,
"nftl: write support is broken".

Signed-off-by: <dimitri.gorokhovik@free.fr>
---
 
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index 665d3eb..d2fd066 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -135,16 +135,17 @@ static void nftl_remove_dev(struct mtd_blktrans_dev *dev)
 int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
 		  size_t *retlen, uint8_t *buf)
 {
+	typeof(offs) mask = mtd->writesize - 1;
 	struct mtd_oob_ops ops;
 	int res;
 
 	ops.mode = MTD_OOB_PLACE;
-	ops.ooboffs = offs & (mtd->writesize - 1);
+	ops.ooboffs = offs & mask;
 	ops.ooblen = len;
 	ops.oobbuf = buf;
 	ops.datbuf = NULL;
 
-	res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
+	res = mtd->read_oob(mtd, offs & ~mask, &ops);
 	*retlen = ops.oobretlen;
 	return res;
 }
@@ -155,16 +156,17 @@ int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
 int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
 		   size_t *retlen, uint8_t *buf)
 {
+	typeof(offs) mask = mtd->writesize - 1;
 	struct mtd_oob_ops ops;
 	int res;
 
 	ops.mode = MTD_OOB_PLACE;
-	ops.ooboffs = offs & (mtd->writesize - 1);
+	ops.ooboffs = offs & mask;
 	ops.ooblen = len;
 	ops.oobbuf = buf;
 	ops.datbuf = NULL;
 
-	res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
+	res = mtd->write_oob(mtd, offs & ~mask, &ops);
 	*retlen = ops.oobretlen;
 	return res;
 }
@@ -177,17 +179,18 @@ int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
 static int nftl_write(struct mtd_info *mtd, loff_t offs, size_t len,
 		      size_t *retlen, uint8_t *buf, uint8_t *oob)
 {
+	typeof(offs) mask = mtd->writesize - 1;
 	struct mtd_oob_ops ops;
 	int res;
 
 	ops.mode = MTD_OOB_PLACE;
-	ops.ooboffs = offs & (mtd->writesize - 1);
+	ops.ooboffs = offs & mask;
 	ops.ooblen = mtd->oobsize;
 	ops.oobbuf = oob;
 	ops.datbuf = buf;
 	ops.len = len;
 
-	res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
+	res = mtd->write_oob(mtd, offs & ~mask, &ops);
 	*retlen = ops.retlen;
 	return res;
 }

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

* Re: [PATCH] nftl: fix offset alignments
  2009-08-18 22:06 ` [PATCH] nftl: fix offset alignments dimitri.gorokhovik
@ 2009-08-19 23:34   ` Andrew Morton
  2009-08-20 21:13     ` dimitri.gorokhovik
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2009-08-19 23:34 UTC (permalink / raw)
  To: dimitri.gorokhovik
  Cc: Scott James Remnant, David Brownell, David Woodhouse,
	linux-kernel, Julia Lawall, linux-mtd, Tim Gardner,
	David Woodhouse

On Wed, 19 Aug 2009 00:06:28 +0200 (CEST) dimitri.gorokhovik@free.fr wrote:

> Arithmetic conversion in the mask computation makes the upper word 
> of the second argument passed down to mtd->read_oob(), be always 0
> (assuming 'offs' being a 64-bit signed long long type, and 
> 'mtd->writesize' being a 32-bit unsigned int type). 
> 
> This patch applies over the other one adding masking in nftl_write,
> "nftl: write support is broken".
> 
> Signed-off-by: <dimitri.gorokhovik@free.fr>
> ---
>  
> diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
> index 665d3eb..d2fd066 100644
> --- a/drivers/mtd/nftlcore.c
> +++ b/drivers/mtd/nftlcore.c
> @@ -135,16 +135,17 @@ static void nftl_remove_dev(struct mtd_blktrans_dev *dev)
>  int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
>  		  size_t *retlen, uint8_t *buf)
>  {
> +	typeof(offs) mask = mtd->writesize - 1;

I see no reason to use typeof here.  Plain old

	loff_t mask = mtd->writesize - 1;

would be more conventional.

>  	struct mtd_oob_ops ops;
>  	int res;
>  
>  	ops.mode = MTD_OOB_PLACE;
> -	ops.ooboffs = offs & (mtd->writesize - 1);
> +	ops.ooboffs = offs & mask;
>  	ops.ooblen = len;
>  	ops.oobbuf = buf;
>  	ops.datbuf = NULL;
>  
> -	res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
> +	res = mtd->read_oob(mtd, offs & ~mask, &ops);

yup.

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

* Re: [PATCH] nftl: fix offset alignments
  2009-08-19 23:34   ` Andrew Morton
@ 2009-08-20 21:13     ` dimitri.gorokhovik
  0 siblings, 0 replies; 3+ messages in thread
From: dimitri.gorokhovik @ 2009-08-20 21:13 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Scott James Remnant, David Brownell, David Woodhouse,
	linux-kernel, Julia Lawall, linux-mtd, Tim Gardner,
	David Woodhouse

"Andrew Morton" <akpm@linux-foundation.org> a écrit :
> On Wed, 19 Aug 2009 00:06:28 +0200 (CEST) dimitri.gorokhovik@free.fr
> wrote:
> ...
> > +	typeof(offs) mask = mtd->writesize - 1;
> 
> I see no reason to use typeof here.  Plain old
> 
> 	loff_t mask = mtd->writesize - 1;
> 
> would be more conventional.

I use typeoff in this way to guard masking code against absent-minded
modifications. 

Attached is a corrected version as suggested. 

Maybe Julia can come up with a clever rule for detecting unusual masking 
operations automatically :-) ? 

---
From: Dimitri Gorokhovik <dimitri.gorokhovik@free.fr>
Subject: nftl: fix offset alignments

Arithmetic conversion in the mask computation makes the upper word
of the second argument passed down to mtd->read_oob(), be always 0
(assuming 'offs' being a 64-bit signed long long type, and
'mtd->writesize' being a 32-bit unsigned int type).

This patch applies over the other one adding masking in nftl_write,
"nftl: write support is broken".

Signed-off-by: Dimitri Gorokhovik <dimitri.gorokhovik@free.fr>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Tim Gardner <tim.gardner@canonical.com>
Cc: Scott James Remnant <scott@canonical.com>
---
 drivers/mtd/nftlcore.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index 665d3eb..1002e18 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -135,16 +135,17 @@ static void nftl_remove_dev(struct mtd_blktrans_dev *dev)
 int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
 		  size_t *retlen, uint8_t *buf)
 {
+	loff_t mask = mtd->writesize - 1;
 	struct mtd_oob_ops ops;
 	int res;
 
 	ops.mode = MTD_OOB_PLACE;
-	ops.ooboffs = offs & (mtd->writesize - 1);
+	ops.ooboffs = offs & mask;
 	ops.ooblen = len;
 	ops.oobbuf = buf;
 	ops.datbuf = NULL;
 
-	res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
+	res = mtd->read_oob(mtd, offs & ~mask, &ops);
 	*retlen = ops.oobretlen;
 	return res;
 }
@@ -155,16 +156,17 @@ int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
 int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
 		   size_t *retlen, uint8_t *buf)
 {
+	loff_t mask = mtd->writesize - 1;
 	struct mtd_oob_ops ops;
 	int res;
 
 	ops.mode = MTD_OOB_PLACE;
-	ops.ooboffs = offs & (mtd->writesize - 1);
+	ops.ooboffs = offs & mask;
 	ops.ooblen = len;
 	ops.oobbuf = buf;
 	ops.datbuf = NULL;
 
-	res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
+	res = mtd->write_oob(mtd, offs & ~mask, &ops);
 	*retlen = ops.oobretlen;
 	return res;
 }
@@ -177,17 +179,18 @@ int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
 static int nftl_write(struct mtd_info *mtd, loff_t offs, size_t len,
 		      size_t *retlen, uint8_t *buf, uint8_t *oob)
 {
+	loff_t mask = mtd->writesize - 1;
 	struct mtd_oob_ops ops;
 	int res;
 
 	ops.mode = MTD_OOB_PLACE;
-	ops.ooboffs = offs & (mtd->writesize - 1);
+	ops.ooboffs = offs & mask;
 	ops.ooblen = mtd->oobsize;
 	ops.oobbuf = oob;
 	ops.datbuf = buf;
 	ops.len = len;
 
-	res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
+	res = mtd->write_oob(mtd, offs & ~mask, &ops);
 	*retlen = ops.retlen;
 	return res;
 }
-- 
1.6.3.3

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

end of thread, other threads:[~2009-08-20 21:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <605152405.3397101250633087167.JavaMail.root@zimbra3-e1.priv.proxad.net>
2009-08-18 22:06 ` [PATCH] nftl: fix offset alignments dimitri.gorokhovik
2009-08-19 23:34   ` Andrew Morton
2009-08-20 21:13     ` dimitri.gorokhovik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox