hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/drivers/mtd/mtdblock.c
....@@ -1,23 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Direct MTD block device access
34 *
45 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
56 * 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
- *
217 */
228
239 #include <linux/fs.h>
....@@ -56,7 +42,7 @@
5642 */
5743
5844 static int erase_write (struct mtd_info *mtd, unsigned long pos,
59
- int len, const char *buf)
45
+ unsigned int len, const char *buf)
6046 {
6147 struct erase_info erase;
6248 size_t retlen;
....@@ -103,8 +89,6 @@
10389
10490 ret = erase_write (mtd, mtdblk->cache_offset,
10591 mtdblk->cache_size, mtdblk->cache_data);
106
- if (ret)
107
- return ret;
10892
10993 /*
11094 * Here we could arguably set the cache state to STATE_CLEAN.
....@@ -112,9 +96,14 @@
11296 * be notified if this content is altered on the flash by other
11397 * means. Let's declare it empty and leave buffering tasks to
11498 * 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.
115103 */
116
- mtdblk->cache_state = STATE_EMPTY;
117
- return 0;
104
+ if (ret == 0 || ret == -EIO)
105
+ mtdblk->cache_state = STATE_EMPTY;
106
+ return ret;
118107 }
119108
120109
....@@ -308,12 +297,13 @@
308297 static int mtdblock_flush(struct mtd_blktrans_dev *dev)
309298 {
310299 struct mtdblk_dev *mtdblk = container_of(dev, struct mtdblk_dev, mbd);
300
+ int ret;
311301
312302 mutex_lock(&mtdblk->cache_mutex);
313
- write_cached_data(mtdblk);
303
+ ret = write_cached_data(mtdblk);
314304 mutex_unlock(&mtdblk->cache_mutex);
315305 mtd_sync(dev->mtd);
316
- return 0;
306
+ return ret;
317307 }
318308
319309 static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)