.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Direct MTD block device access |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org> |
---|
5 | 6 | * Copyright © 2000-2003 Nicolas Pitre <nico@fluxnic.net> |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License as published by |
---|
9 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
10 | | - * (at your option) any later version. |
---|
11 | | - * |
---|
12 | | - * This program is distributed in the hope that it will be useful, |
---|
13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | | - * GNU General Public License for more details. |
---|
16 | | - * |
---|
17 | | - * You should have received a copy of the GNU General Public License |
---|
18 | | - * along with this program; if not, write to the Free Software |
---|
19 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
20 | | - * |
---|
21 | 7 | */ |
---|
22 | 8 | |
---|
23 | 9 | #include <linux/fs.h> |
---|
.. | .. |
---|
56 | 42 | */ |
---|
57 | 43 | |
---|
58 | 44 | static int erase_write (struct mtd_info *mtd, unsigned long pos, |
---|
59 | | - int len, const char *buf) |
---|
| 45 | + unsigned int len, const char *buf) |
---|
60 | 46 | { |
---|
61 | 47 | struct erase_info erase; |
---|
62 | 48 | size_t retlen; |
---|
.. | .. |
---|
103 | 89 | |
---|
104 | 90 | ret = erase_write (mtd, mtdblk->cache_offset, |
---|
105 | 91 | mtdblk->cache_size, mtdblk->cache_data); |
---|
106 | | - if (ret) |
---|
107 | | - return ret; |
---|
108 | 92 | |
---|
109 | 93 | /* |
---|
110 | 94 | * Here we could arguably set the cache state to STATE_CLEAN. |
---|
.. | .. |
---|
112 | 96 | * be notified if this content is altered on the flash by other |
---|
113 | 97 | * means. Let's declare it empty and leave buffering tasks to |
---|
114 | 98 | * the buffer cache instead. |
---|
| 99 | + * |
---|
| 100 | + * If this cache_offset points to a bad block, data cannot be |
---|
| 101 | + * written to the device. Clear cache_state to avoid writing to |
---|
| 102 | + * bad blocks repeatedly. |
---|
115 | 103 | */ |
---|
116 | | - mtdblk->cache_state = STATE_EMPTY; |
---|
117 | | - return 0; |
---|
| 104 | + if (ret == 0 || ret == -EIO) |
---|
| 105 | + mtdblk->cache_state = STATE_EMPTY; |
---|
| 106 | + return ret; |
---|
118 | 107 | } |
---|
119 | 108 | |
---|
120 | 109 | |
---|
.. | .. |
---|
164 | 153 | mtdblk->cache_state = STATE_EMPTY; |
---|
165 | 154 | ret = mtd_read(mtd, sect_start, sect_size, |
---|
166 | 155 | &retlen, mtdblk->cache_data); |
---|
167 | | - if (ret) |
---|
| 156 | + if (ret && !mtd_is_bitflip(ret)) |
---|
168 | 157 | return ret; |
---|
169 | 158 | if (retlen != sect_size) |
---|
170 | 159 | return -EIO; |
---|
.. | .. |
---|
199 | 188 | pr_debug("mtdblock: read on \"%s\" at 0x%lx, size 0x%x\n", |
---|
200 | 189 | mtd->name, pos, len); |
---|
201 | 190 | |
---|
202 | | - if (!sect_size) |
---|
203 | | - return mtd_read(mtd, pos, len, &retlen, buf); |
---|
| 191 | + if (!sect_size) { |
---|
| 192 | + ret = mtd_read(mtd, pos, len, &retlen, buf); |
---|
| 193 | + if (ret && !mtd_is_bitflip(ret)) |
---|
| 194 | + return ret; |
---|
| 195 | + return 0; |
---|
| 196 | + } |
---|
204 | 197 | |
---|
205 | 198 | while (len > 0) { |
---|
206 | 199 | unsigned long sect_start = (pos/sect_size)*sect_size; |
---|
.. | .. |
---|
220 | 213 | memcpy (buf, mtdblk->cache_data + offset, size); |
---|
221 | 214 | } else { |
---|
222 | 215 | ret = mtd_read(mtd, pos, size, &retlen, buf); |
---|
223 | | - if (ret) |
---|
| 216 | + if (ret && !mtd_is_bitflip(ret)) |
---|
224 | 217 | return ret; |
---|
225 | 218 | if (retlen != size) |
---|
226 | 219 | return -EIO; |
---|
.. | .. |
---|
308 | 301 | static int mtdblock_flush(struct mtd_blktrans_dev *dev) |
---|
309 | 302 | { |
---|
310 | 303 | struct mtdblk_dev *mtdblk = container_of(dev, struct mtdblk_dev, mbd); |
---|
| 304 | + int ret; |
---|
311 | 305 | |
---|
312 | 306 | mutex_lock(&mtdblk->cache_mutex); |
---|
313 | | - write_cached_data(mtdblk); |
---|
| 307 | + ret = write_cached_data(mtdblk); |
---|
314 | 308 | mutex_unlock(&mtdblk->cache_mutex); |
---|
315 | 309 | mtd_sync(dev->mtd); |
---|
316 | | - return 0; |
---|
| 310 | + return ret; |
---|
317 | 311 | } |
---|
318 | 312 | |
---|
319 | 313 | static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) |
---|