diff options
author | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2011-12-29 08:16:28 -0500 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2012-01-09 13:25:56 -0500 |
commit | 30fa98480b782999248ce8290136aa58f22536cf (patch) | |
tree | 39136ed3fae074abc0178c0b78a2e242700b4cc0 /drivers/mtd | |
parent | 9cf075f8656524abc44ad3ff2ec3834fe76f186f (diff) |
mtd: remove extra retlen assignment
MTD functions always assign the 'retlen' argument to 0 at the very
beginning - the callers do not have to do this.
I used the following semantic patch to find these places:
@@
identifier retlen;
expression a, b, c, d, e;
constant C;
type T;
@@
(
- retlen = C;
|
T
-retlen = C
+ retlen
;
)
... when != retlen
when exists
(
mtd_read(a, b, c, &retlen, d)
|
mtd_write(a, b, c, &retlen, d)
|
mtd_panic_write(a, b, c, &retlen, d)
|
mtd_point(a, b, c, &retlen, d, e)
|
mtd_read_fact_prot_reg(a, b, c, &retlen, d)
|
mtd_write_user_prot_reg(a, b, c, &retlen, d)
|
mtd_read_user_prot_reg(a, b, c, &retlen, d)
|
mtd_writev(a, b, c, d, &retlen)
)
I ran it twice, because there were cases of double zero assigments
in mtd tests. Then I went through the patch to verify that spatch
did not find any false positives.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/mtdchar.c | 2 | ||||
-rw-r--r-- | drivers/mtd/tests/mtd_pagetest.c | 17 | ||||
-rw-r--r-- | drivers/mtd/tests/mtd_readtest.c | 2 | ||||
-rw-r--r-- | drivers/mtd/tests/mtd_speedtest.c | 12 | ||||
-rw-r--r-- | drivers/mtd/tests/mtd_stresstest.c | 4 | ||||
-rw-r--r-- | drivers/mtd/tests/mtd_subpagetest.c | 14 | ||||
-rw-r--r-- | drivers/mtd/tests/mtd_torturetest.c | 4 |
7 files changed, 22 insertions, 33 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 15a3f6224be4..83b0c82e9c94 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c | |||
@@ -189,7 +189,7 @@ static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t count, | |||
189 | { | 189 | { |
190 | struct mtd_file_info *mfi = file->private_data; | 190 | struct mtd_file_info *mfi = file->private_data; |
191 | struct mtd_info *mtd = mfi->mtd; | 191 | struct mtd_info *mtd = mfi->mtd; |
192 | size_t retlen=0; | 192 | size_t retlen; |
193 | size_t total_retlen=0; | 193 | size_t total_retlen=0; |
194 | int ret=0; | 194 | int ret=0; |
195 | int len; | 195 | int len; |
diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c index 8024eaf4c1ac..252ddb092fb2 100644 --- a/drivers/mtd/tests/mtd_pagetest.c +++ b/drivers/mtd/tests/mtd_pagetest.c | |||
@@ -95,7 +95,7 @@ static int erase_eraseblock(int ebnum) | |||
95 | static int write_eraseblock(int ebnum) | 95 | static int write_eraseblock(int ebnum) |
96 | { | 96 | { |
97 | int err = 0; | 97 | int err = 0; |
98 | size_t written = 0; | 98 | size_t written; |
99 | loff_t addr = ebnum * mtd->erasesize; | 99 | loff_t addr = ebnum * mtd->erasesize; |
100 | 100 | ||
101 | set_random_data(writebuf, mtd->erasesize); | 101 | set_random_data(writebuf, mtd->erasesize); |
@@ -111,7 +111,7 @@ static int write_eraseblock(int ebnum) | |||
111 | static int verify_eraseblock(int ebnum) | 111 | static int verify_eraseblock(int ebnum) |
112 | { | 112 | { |
113 | uint32_t j; | 113 | uint32_t j; |
114 | size_t read = 0; | 114 | size_t read; |
115 | int err = 0, i; | 115 | int err = 0, i; |
116 | loff_t addr0, addrn; | 116 | loff_t addr0, addrn; |
117 | loff_t addr = ebnum * mtd->erasesize; | 117 | loff_t addr = ebnum * mtd->erasesize; |
@@ -144,7 +144,6 @@ static int verify_eraseblock(int ebnum) | |||
144 | return err; | 144 | return err; |
145 | } | 145 | } |
146 | memset(twopages, 0, bufsize); | 146 | memset(twopages, 0, bufsize); |
147 | read = 0; | ||
148 | err = mtd_read(mtd, addr, bufsize, &read, twopages); | 147 | err = mtd_read(mtd, addr, bufsize, &read, twopages); |
149 | if (mtd_is_bitflip(err)) | 148 | if (mtd_is_bitflip(err)) |
150 | err = 0; | 149 | err = 0; |
@@ -180,7 +179,6 @@ static int verify_eraseblock(int ebnum) | |||
180 | return err; | 179 | return err; |
181 | } | 180 | } |
182 | memset(twopages, 0, bufsize); | 181 | memset(twopages, 0, bufsize); |
183 | read = 0; | ||
184 | err = mtd_read(mtd, addr, bufsize, &read, twopages); | 182 | err = mtd_read(mtd, addr, bufsize, &read, twopages); |
185 | if (mtd_is_bitflip(err)) | 183 | if (mtd_is_bitflip(err)) |
186 | err = 0; | 184 | err = 0; |
@@ -203,7 +201,7 @@ static int verify_eraseblock(int ebnum) | |||
203 | 201 | ||
204 | static int crosstest(void) | 202 | static int crosstest(void) |
205 | { | 203 | { |
206 | size_t read = 0; | 204 | size_t read; |
207 | int err = 0, i; | 205 | int err = 0, i; |
208 | loff_t addr, addr0, addrn; | 206 | loff_t addr, addr0, addrn; |
209 | unsigned char *pp1, *pp2, *pp3, *pp4; | 207 | unsigned char *pp1, *pp2, *pp3, *pp4; |
@@ -228,7 +226,6 @@ static int crosstest(void) | |||
228 | addrn -= mtd->erasesize; | 226 | addrn -= mtd->erasesize; |
229 | 227 | ||
230 | /* Read 2nd-to-last page to pp1 */ | 228 | /* Read 2nd-to-last page to pp1 */ |
231 | read = 0; | ||
232 | addr = addrn - pgsize - pgsize; | 229 | addr = addrn - pgsize - pgsize; |
233 | err = mtd_read(mtd, addr, pgsize, &read, pp1); | 230 | err = mtd_read(mtd, addr, pgsize, &read, pp1); |
234 | if (mtd_is_bitflip(err)) | 231 | if (mtd_is_bitflip(err)) |
@@ -241,7 +238,6 @@ static int crosstest(void) | |||
241 | } | 238 | } |
242 | 239 | ||
243 | /* Read 3rd-to-last page to pp1 */ | 240 | /* Read 3rd-to-last page to pp1 */ |
244 | read = 0; | ||
245 | addr = addrn - pgsize - pgsize - pgsize; | 241 | addr = addrn - pgsize - pgsize - pgsize; |
246 | err = mtd_read(mtd, addr, pgsize, &read, pp1); | 242 | err = mtd_read(mtd, addr, pgsize, &read, pp1); |
247 | if (mtd_is_bitflip(err)) | 243 | if (mtd_is_bitflip(err)) |
@@ -254,7 +250,6 @@ static int crosstest(void) | |||
254 | } | 250 | } |
255 | 251 | ||
256 | /* Read first page to pp2 */ | 252 | /* Read first page to pp2 */ |
257 | read = 0; | ||
258 | addr = addr0; | 253 | addr = addr0; |
259 | printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); | 254 | printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); |
260 | err = mtd_read(mtd, addr, pgsize, &read, pp2); | 255 | err = mtd_read(mtd, addr, pgsize, &read, pp2); |
@@ -268,7 +263,6 @@ static int crosstest(void) | |||
268 | } | 263 | } |
269 | 264 | ||
270 | /* Read last page to pp3 */ | 265 | /* Read last page to pp3 */ |
271 | read = 0; | ||
272 | addr = addrn - pgsize; | 266 | addr = addrn - pgsize; |
273 | printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); | 267 | printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); |
274 | err = mtd_read(mtd, addr, pgsize, &read, pp3); | 268 | err = mtd_read(mtd, addr, pgsize, &read, pp3); |
@@ -282,7 +276,6 @@ static int crosstest(void) | |||
282 | } | 276 | } |
283 | 277 | ||
284 | /* Read first page again to pp4 */ | 278 | /* Read first page again to pp4 */ |
285 | read = 0; | ||
286 | addr = addr0; | 279 | addr = addr0; |
287 | printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); | 280 | printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); |
288 | err = mtd_read(mtd, addr, pgsize, &read, pp4); | 281 | err = mtd_read(mtd, addr, pgsize, &read, pp4); |
@@ -309,7 +302,7 @@ static int crosstest(void) | |||
309 | 302 | ||
310 | static int erasecrosstest(void) | 303 | static int erasecrosstest(void) |
311 | { | 304 | { |
312 | size_t read = 0, written = 0; | 305 | size_t read, written; |
313 | int err = 0, i, ebnum, ebnum2; | 306 | int err = 0, i, ebnum, ebnum2; |
314 | loff_t addr0; | 307 | loff_t addr0; |
315 | char *readbuf = twopages; | 308 | char *readbuf = twopages; |
@@ -405,7 +398,7 @@ static int erasecrosstest(void) | |||
405 | 398 | ||
406 | static int erasetest(void) | 399 | static int erasetest(void) |
407 | { | 400 | { |
408 | size_t read = 0, written = 0; | 401 | size_t read, written; |
409 | int err = 0, i, ebnum, ok = 1; | 402 | int err = 0, i, ebnum, ok = 1; |
410 | loff_t addr0; | 403 | loff_t addr0; |
411 | 404 | ||
diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c index ad5fd0df86ee..4228eb4e54c7 100644 --- a/drivers/mtd/tests/mtd_readtest.c +++ b/drivers/mtd/tests/mtd_readtest.c | |||
@@ -44,7 +44,7 @@ static int pgcnt; | |||
44 | 44 | ||
45 | static int read_eraseblock_by_page(int ebnum) | 45 | static int read_eraseblock_by_page(int ebnum) |
46 | { | 46 | { |
47 | size_t read = 0; | 47 | size_t read; |
48 | int i, ret, err = 0; | 48 | int i, ret, err = 0; |
49 | loff_t addr = ebnum * mtd->erasesize; | 49 | loff_t addr = ebnum * mtd->erasesize; |
50 | void *buf = iobuf; | 50 | void *buf = iobuf; |
diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c index ecb287847505..4d2ed5c0807d 100644 --- a/drivers/mtd/tests/mtd_speedtest.c +++ b/drivers/mtd/tests/mtd_speedtest.c | |||
@@ -139,7 +139,7 @@ static int erase_whole_device(void) | |||
139 | 139 | ||
140 | static int write_eraseblock(int ebnum) | 140 | static int write_eraseblock(int ebnum) |
141 | { | 141 | { |
142 | size_t written = 0; | 142 | size_t written; |
143 | int err = 0; | 143 | int err = 0; |
144 | loff_t addr = ebnum * mtd->erasesize; | 144 | loff_t addr = ebnum * mtd->erasesize; |
145 | 145 | ||
@@ -155,7 +155,7 @@ static int write_eraseblock(int ebnum) | |||
155 | 155 | ||
156 | static int write_eraseblock_by_page(int ebnum) | 156 | static int write_eraseblock_by_page(int ebnum) |
157 | { | 157 | { |
158 | size_t written = 0; | 158 | size_t written; |
159 | int i, err = 0; | 159 | int i, err = 0; |
160 | loff_t addr = ebnum * mtd->erasesize; | 160 | loff_t addr = ebnum * mtd->erasesize; |
161 | void *buf = iobuf; | 161 | void *buf = iobuf; |
@@ -178,7 +178,7 @@ static int write_eraseblock_by_page(int ebnum) | |||
178 | 178 | ||
179 | static int write_eraseblock_by_2pages(int ebnum) | 179 | static int write_eraseblock_by_2pages(int ebnum) |
180 | { | 180 | { |
181 | size_t written = 0, sz = pgsize * 2; | 181 | size_t written, sz = pgsize * 2; |
182 | int i, n = pgcnt / 2, err = 0; | 182 | int i, n = pgcnt / 2, err = 0; |
183 | loff_t addr = ebnum * mtd->erasesize; | 183 | loff_t addr = ebnum * mtd->erasesize; |
184 | void *buf = iobuf; | 184 | void *buf = iobuf; |
@@ -210,7 +210,7 @@ static int write_eraseblock_by_2pages(int ebnum) | |||
210 | 210 | ||
211 | static int read_eraseblock(int ebnum) | 211 | static int read_eraseblock(int ebnum) |
212 | { | 212 | { |
213 | size_t read = 0; | 213 | size_t read; |
214 | int err = 0; | 214 | int err = 0; |
215 | loff_t addr = ebnum * mtd->erasesize; | 215 | loff_t addr = ebnum * mtd->erasesize; |
216 | 216 | ||
@@ -229,7 +229,7 @@ static int read_eraseblock(int ebnum) | |||
229 | 229 | ||
230 | static int read_eraseblock_by_page(int ebnum) | 230 | static int read_eraseblock_by_page(int ebnum) |
231 | { | 231 | { |
232 | size_t read = 0; | 232 | size_t read; |
233 | int i, err = 0; | 233 | int i, err = 0; |
234 | loff_t addr = ebnum * mtd->erasesize; | 234 | loff_t addr = ebnum * mtd->erasesize; |
235 | void *buf = iobuf; | 235 | void *buf = iobuf; |
@@ -255,7 +255,7 @@ static int read_eraseblock_by_page(int ebnum) | |||
255 | 255 | ||
256 | static int read_eraseblock_by_2pages(int ebnum) | 256 | static int read_eraseblock_by_2pages(int ebnum) |
257 | { | 257 | { |
258 | size_t read = 0, sz = pgsize * 2; | 258 | size_t read, sz = pgsize * 2; |
259 | int i, n = pgcnt / 2, err = 0; | 259 | int i, n = pgcnt / 2, err = 0; |
260 | loff_t addr = ebnum * mtd->erasesize; | 260 | loff_t addr = ebnum * mtd->erasesize; |
261 | void *buf = iobuf; | 261 | void *buf = iobuf; |
diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c index 4789c0ee3e9a..399aa2bf220d 100644 --- a/drivers/mtd/tests/mtd_stresstest.c +++ b/drivers/mtd/tests/mtd_stresstest.c | |||
@@ -140,7 +140,7 @@ static int is_block_bad(int ebnum) | |||
140 | 140 | ||
141 | static int do_read(void) | 141 | static int do_read(void) |
142 | { | 142 | { |
143 | size_t read = 0; | 143 | size_t read; |
144 | int eb = rand_eb(); | 144 | int eb = rand_eb(); |
145 | int offs = rand_offs(); | 145 | int offs = rand_offs(); |
146 | int len = rand_len(offs), err; | 146 | int len = rand_len(offs), err; |
@@ -169,7 +169,7 @@ static int do_read(void) | |||
169 | static int do_write(void) | 169 | static int do_write(void) |
170 | { | 170 | { |
171 | int eb = rand_eb(), offs, err, len; | 171 | int eb = rand_eb(), offs, err, len; |
172 | size_t written = 0; | 172 | size_t written; |
173 | loff_t addr; | 173 | loff_t addr; |
174 | 174 | ||
175 | offs = offsets[eb]; | 175 | offs = offsets[eb]; |
diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c index 4b873d49fe6a..9667bf535282 100644 --- a/drivers/mtd/tests/mtd_subpagetest.c +++ b/drivers/mtd/tests/mtd_subpagetest.c | |||
@@ -115,7 +115,7 @@ static int erase_whole_device(void) | |||
115 | 115 | ||
116 | static int write_eraseblock(int ebnum) | 116 | static int write_eraseblock(int ebnum) |
117 | { | 117 | { |
118 | size_t written = 0; | 118 | size_t written; |
119 | int err = 0; | 119 | int err = 0; |
120 | loff_t addr = ebnum * mtd->erasesize; | 120 | loff_t addr = ebnum * mtd->erasesize; |
121 | 121 | ||
@@ -150,7 +150,7 @@ static int write_eraseblock(int ebnum) | |||
150 | 150 | ||
151 | static int write_eraseblock2(int ebnum) | 151 | static int write_eraseblock2(int ebnum) |
152 | { | 152 | { |
153 | size_t written = 0; | 153 | size_t written; |
154 | int err = 0, k; | 154 | int err = 0, k; |
155 | loff_t addr = ebnum * mtd->erasesize; | 155 | loff_t addr = ebnum * mtd->erasesize; |
156 | 156 | ||
@@ -189,13 +189,12 @@ static void print_subpage(unsigned char *p) | |||
189 | 189 | ||
190 | static int verify_eraseblock(int ebnum) | 190 | static int verify_eraseblock(int ebnum) |
191 | { | 191 | { |
192 | size_t read = 0; | 192 | size_t read; |
193 | int err = 0; | 193 | int err = 0; |
194 | loff_t addr = ebnum * mtd->erasesize; | 194 | loff_t addr = ebnum * mtd->erasesize; |
195 | 195 | ||
196 | set_random_data(writebuf, subpgsize); | 196 | set_random_data(writebuf, subpgsize); |
197 | clear_data(readbuf, subpgsize); | 197 | clear_data(readbuf, subpgsize); |
198 | read = 0; | ||
199 | err = mtd_read(mtd, addr, subpgsize, &read, readbuf); | 198 | err = mtd_read(mtd, addr, subpgsize, &read, readbuf); |
200 | if (unlikely(err || read != subpgsize)) { | 199 | if (unlikely(err || read != subpgsize)) { |
201 | if (mtd_is_bitflip(err) && read == subpgsize) { | 200 | if (mtd_is_bitflip(err) && read == subpgsize) { |
@@ -223,7 +222,6 @@ static int verify_eraseblock(int ebnum) | |||
223 | 222 | ||
224 | set_random_data(writebuf, subpgsize); | 223 | set_random_data(writebuf, subpgsize); |
225 | clear_data(readbuf, subpgsize); | 224 | clear_data(readbuf, subpgsize); |
226 | read = 0; | ||
227 | err = mtd_read(mtd, addr, subpgsize, &read, readbuf); | 225 | err = mtd_read(mtd, addr, subpgsize, &read, readbuf); |
228 | if (unlikely(err || read != subpgsize)) { | 226 | if (unlikely(err || read != subpgsize)) { |
229 | if (mtd_is_bitflip(err) && read == subpgsize) { | 227 | if (mtd_is_bitflip(err) && read == subpgsize) { |
@@ -252,7 +250,7 @@ static int verify_eraseblock(int ebnum) | |||
252 | 250 | ||
253 | static int verify_eraseblock2(int ebnum) | 251 | static int verify_eraseblock2(int ebnum) |
254 | { | 252 | { |
255 | size_t read = 0; | 253 | size_t read; |
256 | int err = 0, k; | 254 | int err = 0, k; |
257 | loff_t addr = ebnum * mtd->erasesize; | 255 | loff_t addr = ebnum * mtd->erasesize; |
258 | 256 | ||
@@ -261,7 +259,6 @@ static int verify_eraseblock2(int ebnum) | |||
261 | break; | 259 | break; |
262 | set_random_data(writebuf, subpgsize * k); | 260 | set_random_data(writebuf, subpgsize * k); |
263 | clear_data(readbuf, subpgsize * k); | 261 | clear_data(readbuf, subpgsize * k); |
264 | read = 0; | ||
265 | err = mtd_read(mtd, addr, subpgsize * k, &read, readbuf); | 262 | err = mtd_read(mtd, addr, subpgsize * k, &read, readbuf); |
266 | if (unlikely(err || read != subpgsize * k)) { | 263 | if (unlikely(err || read != subpgsize * k)) { |
267 | if (mtd_is_bitflip(err) && read == subpgsize * k) { | 264 | if (mtd_is_bitflip(err) && read == subpgsize * k) { |
@@ -288,14 +285,13 @@ static int verify_eraseblock2(int ebnum) | |||
288 | static int verify_eraseblock_ff(int ebnum) | 285 | static int verify_eraseblock_ff(int ebnum) |
289 | { | 286 | { |
290 | uint32_t j; | 287 | uint32_t j; |
291 | size_t read = 0; | 288 | size_t read; |
292 | int err = 0; | 289 | int err = 0; |
293 | loff_t addr = ebnum * mtd->erasesize; | 290 | loff_t addr = ebnum * mtd->erasesize; |
294 | 291 | ||
295 | memset(writebuf, 0xff, subpgsize); | 292 | memset(writebuf, 0xff, subpgsize); |
296 | for (j = 0; j < mtd->erasesize / subpgsize; ++j) { | 293 | for (j = 0; j < mtd->erasesize / subpgsize; ++j) { |
297 | clear_data(readbuf, subpgsize); | 294 | clear_data(readbuf, subpgsize); |
298 | read = 0; | ||
299 | err = mtd_read(mtd, addr, subpgsize, &read, readbuf); | 295 | err = mtd_read(mtd, addr, subpgsize, &read, readbuf); |
300 | if (unlikely(err || read != subpgsize)) { | 296 | if (unlikely(err || read != subpgsize)) { |
301 | if (mtd_is_bitflip(err) && read == subpgsize) { | 297 | if (mtd_is_bitflip(err) && read == subpgsize) { |
diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c index 30c4ed9855ec..557105f2ead3 100644 --- a/drivers/mtd/tests/mtd_torturetest.c +++ b/drivers/mtd/tests/mtd_torturetest.c | |||
@@ -127,7 +127,7 @@ static inline int erase_eraseblock(int ebnum) | |||
127 | static inline int check_eraseblock(int ebnum, unsigned char *buf) | 127 | static inline int check_eraseblock(int ebnum, unsigned char *buf) |
128 | { | 128 | { |
129 | int err, retries = 0; | 129 | int err, retries = 0; |
130 | size_t read = 0; | 130 | size_t read; |
131 | loff_t addr = ebnum * mtd->erasesize; | 131 | loff_t addr = ebnum * mtd->erasesize; |
132 | size_t len = mtd->erasesize; | 132 | size_t len = mtd->erasesize; |
133 | 133 | ||
@@ -181,7 +181,7 @@ retry: | |||
181 | static inline int write_pattern(int ebnum, void *buf) | 181 | static inline int write_pattern(int ebnum, void *buf) |
182 | { | 182 | { |
183 | int err; | 183 | int err; |
184 | size_t written = 0; | 184 | size_t written; |
185 | loff_t addr = ebnum * mtd->erasesize; | 185 | loff_t addr = ebnum * mtd->erasesize; |
186 | size_t len = mtd->erasesize; | 186 | size_t len = mtd->erasesize; |
187 | 187 | ||