.. | .. |
---|
| 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 | |
---|
.. | .. |
---|
308 | 297 | static int mtdblock_flush(struct mtd_blktrans_dev *dev) |
---|
309 | 298 | { |
---|
310 | 299 | struct mtdblk_dev *mtdblk = container_of(dev, struct mtdblk_dev, mbd); |
---|
| 300 | + int ret; |
---|
311 | 301 | |
---|
312 | 302 | mutex_lock(&mtdblk->cache_mutex); |
---|
313 | | - write_cached_data(mtdblk); |
---|
| 303 | + ret = write_cached_data(mtdblk); |
---|
314 | 304 | mutex_unlock(&mtdblk->cache_mutex); |
---|
315 | 305 | mtd_sync(dev->mtd); |
---|
316 | | - return 0; |
---|
| 306 | + return ret; |
---|
317 | 307 | } |
---|
318 | 308 | |
---|
319 | 309 | static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) |
---|