aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nftlcore.c
diff options
context:
space:
mode:
authorDimitri Gorokhovik <dimitri.gorokhovik@free.fr>2009-09-03 09:04:22 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2009-09-03 09:59:16 -0400
commit16f05c2b68520f94e365f9d347a7076f4ff00ad5 (patch)
treeca06a5950392f6619c92fdb3431729a40096744e /drivers/mtd/nftlcore.c
parent4149ed1aa944ab864024982a2e568d17eccff504 (diff)
mtd: 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: Tim Gardner <tim.gardner@canonical.com> Cc: Scott James Remnant <scott@canonical.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/nftlcore.c')
-rw-r--r--drivers/mtd/nftlcore.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index 665d3eba2f47..1002e1882996 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)
135int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len, 135int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
136 size_t *retlen, uint8_t *buf) 136 size_t *retlen, uint8_t *buf)
137{ 137{
138 loff_t mask = mtd->writesize - 1;
138 struct mtd_oob_ops ops; 139 struct mtd_oob_ops ops;
139 int res; 140 int res;
140 141
141 ops.mode = MTD_OOB_PLACE; 142 ops.mode = MTD_OOB_PLACE;
142 ops.ooboffs = offs & (mtd->writesize - 1); 143 ops.ooboffs = offs & mask;
143 ops.ooblen = len; 144 ops.ooblen = len;
144 ops.oobbuf = buf; 145 ops.oobbuf = buf;
145 ops.datbuf = NULL; 146 ops.datbuf = NULL;
146 147
147 res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops); 148 res = mtd->read_oob(mtd, offs & ~mask, &ops);
148 *retlen = ops.oobretlen; 149 *retlen = ops.oobretlen;
149 return res; 150 return res;
150} 151}
@@ -155,16 +156,17 @@ int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
155int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len, 156int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
156 size_t *retlen, uint8_t *buf) 157 size_t *retlen, uint8_t *buf)
157{ 158{
159 loff_t mask = mtd->writesize - 1;
158 struct mtd_oob_ops ops; 160 struct mtd_oob_ops ops;
159 int res; 161 int res;
160 162
161 ops.mode = MTD_OOB_PLACE; 163 ops.mode = MTD_OOB_PLACE;
162 ops.ooboffs = offs & (mtd->writesize - 1); 164 ops.ooboffs = offs & mask;
163 ops.ooblen = len; 165 ops.ooblen = len;
164 ops.oobbuf = buf; 166 ops.oobbuf = buf;
165 ops.datbuf = NULL; 167 ops.datbuf = NULL;
166 168
167 res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); 169 res = mtd->write_oob(mtd, offs & ~mask, &ops);
168 *retlen = ops.oobretlen; 170 *retlen = ops.oobretlen;
169 return res; 171 return res;
170} 172}
@@ -177,17 +179,18 @@ int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
177static int nftl_write(struct mtd_info *mtd, loff_t offs, size_t len, 179static int nftl_write(struct mtd_info *mtd, loff_t offs, size_t len,
178 size_t *retlen, uint8_t *buf, uint8_t *oob) 180 size_t *retlen, uint8_t *buf, uint8_t *oob)
179{ 181{
182 loff_t mask = mtd->writesize - 1;
180 struct mtd_oob_ops ops; 183 struct mtd_oob_ops ops;
181 int res; 184 int res;
182 185
183 ops.mode = MTD_OOB_PLACE; 186 ops.mode = MTD_OOB_PLACE;
184 ops.ooboffs = offs & (mtd->writesize - 1); 187 ops.ooboffs = offs & mask;
185 ops.ooblen = mtd->oobsize; 188 ops.ooblen = mtd->oobsize;
186 ops.oobbuf = oob; 189 ops.oobbuf = oob;
187 ops.datbuf = buf; 190 ops.datbuf = buf;
188 ops.len = len; 191 ops.len = len;
189 192
190 res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); 193 res = mtd->write_oob(mtd, offs & ~mask, &ops);
191 *retlen = ops.retlen; 194 *retlen = ops.retlen;
192 return res; 195 return res;
193} 196}