hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/mtd/nand/core.c
....@@ -174,6 +174,40 @@
174174 EXPORT_SYMBOL_GPL(nanddev_mtd_erase);
175175
176176 /**
177
+ * nanddev_mtd_max_bad_blocks() - Get the maximum number of bad eraseblock on
178
+ * a specific region of the NAND device
179
+ * @mtd: MTD device
180
+ * @offs: offset of the NAND region
181
+ * @len: length of the NAND region
182
+ *
183
+ * Default implementation for mtd->_max_bad_blocks(). Only works if
184
+ * nand->memorg.max_bad_eraseblocks_per_lun is > 0.
185
+ *
186
+ * Return: a positive number encoding the maximum number of eraseblocks on a
187
+ * portion of memory, a negative error code otherwise.
188
+ */
189
+int nanddev_mtd_max_bad_blocks(struct mtd_info *mtd, loff_t offs, size_t len)
190
+{
191
+ struct nand_device *nand = mtd_to_nanddev(mtd);
192
+ struct nand_pos pos, end;
193
+ unsigned int max_bb = 0;
194
+
195
+ if (!nand->memorg.max_bad_eraseblocks_per_lun)
196
+ return -ENOTSUPP;
197
+
198
+ nanddev_offs_to_pos(nand, offs, &pos);
199
+ nanddev_offs_to_pos(nand, offs + len, &end);
200
+
201
+ for (nanddev_offs_to_pos(nand, offs, &pos);
202
+ nanddev_pos_cmp(&pos, &end) < 0;
203
+ nanddev_pos_next_lun(nand, &pos))
204
+ max_bb += nand->memorg.max_bad_eraseblocks_per_lun;
205
+
206
+ return max_bb;
207
+}
208
+EXPORT_SYMBOL_GPL(nanddev_mtd_max_bad_blocks);
209
+
210
+/**
177211 * nanddev_init() - Initialize a NAND device
178212 * @nand: NAND device
179213 * @ops: NAND device operations