hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/mtd/sm_ftl.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright © 2009 - Maxim Levitsky
34 * SmartMedia/xD translation layer
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
85 */
96
107 #include <linux/kernel.h>
....@@ -221,14 +218,18 @@
221218 {
222219 uint8_t ecc[3];
223220
224
- __nand_calculate_ecc(buffer, SM_SMALL_PAGE, ecc);
225
- if (__nand_correct_data(buffer, ecc, oob->ecc1, SM_SMALL_PAGE) < 0)
221
+ __nand_calculate_ecc(buffer, SM_SMALL_PAGE, ecc,
222
+ IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC));
223
+ if (__nand_correct_data(buffer, ecc, oob->ecc1, SM_SMALL_PAGE,
224
+ IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)) < 0)
226225 return -EIO;
227226
228227 buffer += SM_SMALL_PAGE;
229228
230
- __nand_calculate_ecc(buffer, SM_SMALL_PAGE, ecc);
231
- if (__nand_correct_data(buffer, ecc, oob->ecc2, SM_SMALL_PAGE) < 0)
229
+ __nand_calculate_ecc(buffer, SM_SMALL_PAGE, ecc,
230
+ IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC));
231
+ if (__nand_correct_data(buffer, ecc, oob->ecc2, SM_SMALL_PAGE,
232
+ IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)) < 0)
232233 return -EIO;
233234 return 0;
234235 }
....@@ -246,7 +247,8 @@
246247
247248 /* FTL can contain -1 entries that are by default filled with bits */
248249 if (block == -1) {
249
- memset(buffer, 0xFF, SM_SECTOR_SIZE);
250
+ if (buffer)
251
+ memset(buffer, 0xFF, SM_SECTOR_SIZE);
250252 return 0;
251253 }
252254
....@@ -393,11 +395,13 @@
393395 }
394396
395397 if (ftl->smallpagenand) {
396
- __nand_calculate_ecc(buf + boffset,
397
- SM_SMALL_PAGE, oob.ecc1);
398
+ __nand_calculate_ecc(buf + boffset, SM_SMALL_PAGE,
399
+ oob.ecc1,
400
+ IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC));
398401
399402 __nand_calculate_ecc(buf + boffset + SM_SMALL_PAGE,
400
- SM_SMALL_PAGE, oob.ecc2);
403
+ SM_SMALL_PAGE, oob.ecc2,
404
+ IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC));
401405 }
402406 if (!sm_write_sector(ftl, zone, block, boffset,
403407 buf + boffset, &oob))
....@@ -771,8 +775,11 @@
771775 continue;
772776
773777 /* Read the oob of first sector */
774
- if (sm_read_sector(ftl, zone_num, block, 0, NULL, &oob))
778
+ if (sm_read_sector(ftl, zone_num, block, 0, NULL, &oob)) {
779
+ kfifo_free(&zone->free_sectors);
780
+ kfree(zone->lba_to_phys_table);
775781 return -EIO;
782
+ }
776783
777784 /* Test to see if block is erased. It is enough to test
778785 first sector, because erase happens in one shot */
....@@ -1091,9 +1098,9 @@
10911098 {
10921099 struct sm_ftl *ftl = dev->priv;
10931100
1094
- mutex_lock(&ftl->mutex);
10951101 del_timer_sync(&ftl->timer);
10961102 cancel_work_sync(&ftl->flush_work);
1103
+ mutex_lock(&ftl->mutex);
10971104 sm_cache_flush(ftl);
10981105 mutex_unlock(&ftl->mutex);
10991106 }