Skip to content

Commit 0c6bc37

Browse files
committed
Merge tag 'ubifs-for-linus-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs
Pull UBI and UBIFS updates from Richard Weinberger: "UBI: - Use in-tree fault injection framework and add new injection types - Fix for a memory leak in the block driver UBIFS: - kernel-doc fixes - Various minor fixes" * tag 'ubifs-for-linus-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs: ubi: block: fix memleak in ubiblock_create() ubifs: fix kernel-doc warnings mtd: Add several functions to the fail_function list ubi: Reserve sufficient buffer length for the input mask ubi: Add six fault injection type for testing ubi: Split io_failures into write_failure and erase_failure ubi: Use the fault injection framework to enhance the fault injection capability ubifs: ubifs_symlink: Fix memleak of inode->i_link in error path ubifs: Check @c->dirty_[n|p]n_cnt and @c->nroot state under @c->lp_mutex ubifs: describe function parameters ubifs: auth.c: fix kernel-doc function prototype warning ubifs: use crypto_shash_tfm_digest() in ubifs_hmac_wkm()
2 parents eebe758 + adbf4c4 commit 0c6bc37

File tree

12 files changed

+539
-88
lines changed

12 files changed

+539
-88
lines changed

drivers/mtd/mtdcore.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/debugfs.h>
3131
#include <linux/nvmem-provider.h>
3232
#include <linux/root_dev.h>
33+
#include <linux/error-injection.h>
3334

3435
#include <linux/mtd/mtd.h>
3536
#include <linux/mtd/partitions.h>
@@ -1412,6 +1413,7 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
14121413
return ret;
14131414
}
14141415
EXPORT_SYMBOL_GPL(mtd_erase);
1416+
ALLOW_ERROR_INJECTION(mtd_erase, ERRNO);
14151417

14161418
/*
14171419
* This stuff for eXecute-In-Place. phys is optional and may be set to NULL.
@@ -1511,6 +1513,7 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
15111513
return ret;
15121514
}
15131515
EXPORT_SYMBOL_GPL(mtd_read);
1516+
ALLOW_ERROR_INJECTION(mtd_read, ERRNO);
15141517

15151518
int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
15161519
const u_char *buf)
@@ -1527,6 +1530,7 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
15271530
return ret;
15281531
}
15291532
EXPORT_SYMBOL_GPL(mtd_write);
1533+
ALLOW_ERROR_INJECTION(mtd_write, ERRNO);
15301534

15311535
/*
15321536
* In blackbox flight recorder like scenarios we want to make successful writes
@@ -2347,6 +2351,7 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
23472351
return 0;
23482352
}
23492353
EXPORT_SYMBOL_GPL(mtd_block_markbad);
2354+
ALLOW_ERROR_INJECTION(mtd_block_markbad, ERRNO);
23502355

23512356
/*
23522357
* default_mtd_writev - the default writev method

drivers/mtd/ubi/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,13 @@ config MTD_UBI_BLOCK
104104

105105
If in doubt, say "N".
106106

107+
config MTD_UBI_FAULT_INJECTION
108+
bool "Fault injection capability of UBI device"
109+
default n
110+
depends on FAULT_INJECTION_DEBUG_FS
111+
help
112+
This option enables fault-injection support for UBI devices for
113+
testing purposes.
114+
115+
If in doubt, say "N".
107116
endif # MTD_UBI

drivers/mtd/ubi/block.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ int ubiblock_create(struct ubi_volume_info *vi)
434434
list_del(&dev->list);
435435
idr_remove(&ubiblock_minor_idr, gd->first_minor);
436436
out_cleanup_disk:
437-
put_disk(dev->gd);
437+
put_disk(gd);
438438
out_free_tags:
439439
blk_mq_free_tag_set(&dev->tag_set);
440440
out_free_dev:

drivers/mtd/ubi/debug.c

Lines changed: 100 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,37 @@
1010
#include <linux/uaccess.h>
1111
#include <linux/module.h>
1212
#include <linux/seq_file.h>
13+
#include <linux/fault-inject.h>
14+
15+
#ifdef CONFIG_MTD_UBI_FAULT_INJECTION
16+
static DECLARE_FAULT_ATTR(fault_eccerr_attr);
17+
static DECLARE_FAULT_ATTR(fault_bitflips_attr);
18+
static DECLARE_FAULT_ATTR(fault_read_failure_attr);
19+
static DECLARE_FAULT_ATTR(fault_write_failure_attr);
20+
static DECLARE_FAULT_ATTR(fault_erase_failure_attr);
21+
static DECLARE_FAULT_ATTR(fault_power_cut_attr);
22+
static DECLARE_FAULT_ATTR(fault_io_ff_attr);
23+
static DECLARE_FAULT_ATTR(fault_io_ff_bitflips_attr);
24+
static DECLARE_FAULT_ATTR(fault_bad_hdr_attr);
25+
static DECLARE_FAULT_ATTR(fault_bad_hdr_ebadmsg_attr);
26+
27+
#define FAIL_ACTION(name, fault_attr) \
28+
bool should_fail_##name(void) \
29+
{ \
30+
return should_fail(&fault_attr, 1); \
31+
}
1332

33+
FAIL_ACTION(eccerr, fault_eccerr_attr)
34+
FAIL_ACTION(bitflips, fault_bitflips_attr)
35+
FAIL_ACTION(read_failure, fault_read_failure_attr)
36+
FAIL_ACTION(write_failure, fault_write_failure_attr)
37+
FAIL_ACTION(erase_failure, fault_erase_failure_attr)
38+
FAIL_ACTION(power_cut, fault_power_cut_attr)
39+
FAIL_ACTION(io_ff, fault_io_ff_attr)
40+
FAIL_ACTION(io_ff_bitflips, fault_io_ff_bitflips_attr)
41+
FAIL_ACTION(bad_hdr, fault_bad_hdr_attr)
42+
FAIL_ACTION(bad_hdr_ebadmsg, fault_bad_hdr_ebadmsg_attr)
43+
#endif
1444

1545
/**
1646
* ubi_dump_flash - dump a region of flash.
@@ -212,6 +242,52 @@ void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req)
212242
*/
213243
static struct dentry *dfs_rootdir;
214244

245+
#ifdef CONFIG_MTD_UBI_FAULT_INJECTION
246+
static void dfs_create_fault_entry(struct dentry *parent)
247+
{
248+
struct dentry *dir;
249+
250+
dir = debugfs_create_dir("fault_inject", parent);
251+
if (IS_ERR_OR_NULL(dir)) {
252+
int err = dir ? PTR_ERR(dir) : -ENODEV;
253+
254+
pr_warn("UBI error: cannot create \"fault_inject\" debugfs directory, error %d\n",
255+
err);
256+
return;
257+
}
258+
259+
fault_create_debugfs_attr("emulate_eccerr", dir,
260+
&fault_eccerr_attr);
261+
262+
fault_create_debugfs_attr("emulate_read_failure", dir,
263+
&fault_read_failure_attr);
264+
265+
fault_create_debugfs_attr("emulate_bitflips", dir,
266+
&fault_bitflips_attr);
267+
268+
fault_create_debugfs_attr("emulate_write_failure", dir,
269+
&fault_write_failure_attr);
270+
271+
fault_create_debugfs_attr("emulate_erase_failure", dir,
272+
&fault_erase_failure_attr);
273+
274+
fault_create_debugfs_attr("emulate_power_cut", dir,
275+
&fault_power_cut_attr);
276+
277+
fault_create_debugfs_attr("emulate_io_ff", dir,
278+
&fault_io_ff_attr);
279+
280+
fault_create_debugfs_attr("emulate_io_ff_bitflips", dir,
281+
&fault_io_ff_bitflips_attr);
282+
283+
fault_create_debugfs_attr("emulate_bad_hdr", dir,
284+
&fault_bad_hdr_attr);
285+
286+
fault_create_debugfs_attr("emulate_bad_hdr_ebadmsg", dir,
287+
&fault_bad_hdr_ebadmsg_attr);
288+
}
289+
#endif
290+
215291
/**
216292
* ubi_debugfs_init - create UBI debugfs directory.
217293
*
@@ -232,6 +308,10 @@ int ubi_debugfs_init(void)
232308
return err;
233309
}
234310

311+
#ifdef CONFIG_MTD_UBI_FAULT_INJECTION
312+
dfs_create_fault_entry(dfs_rootdir);
313+
#endif
314+
235315
return 0;
236316
}
237317

@@ -252,7 +332,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
252332
struct dentry *dent = file->f_path.dentry;
253333
struct ubi_device *ubi;
254334
struct ubi_debug_info *d;
255-
char buf[8];
335+
char buf[16];
256336
int val;
257337

258338
ubi = ubi_get_device(ubi_num);
@@ -272,7 +352,12 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
272352
val = d->emulate_bitflips;
273353
else if (dent == d->dfs_emulate_io_failures)
274354
val = d->emulate_io_failures;
275-
else if (dent == d->dfs_emulate_power_cut) {
355+
else if (dent == d->dfs_emulate_failures) {
356+
snprintf(buf, sizeof(buf), "0x%04x\n", d->emulate_failures);
357+
count = simple_read_from_buffer(user_buf, count, ppos,
358+
buf, strlen(buf));
359+
goto out;
360+
} else if (dent == d->dfs_emulate_power_cut) {
276361
snprintf(buf, sizeof(buf), "%u\n", d->emulate_power_cut);
277362
count = simple_read_from_buffer(user_buf, count, ppos,
278363
buf, strlen(buf));
@@ -287,8 +372,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
287372
count = simple_read_from_buffer(user_buf, count, ppos,
288373
buf, strlen(buf));
289374
goto out;
290-
}
291-
else {
375+
} else {
292376
count = -EINVAL;
293377
goto out;
294378
}
@@ -316,7 +400,7 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
316400
struct ubi_device *ubi;
317401
struct ubi_debug_info *d;
318402
size_t buf_size;
319-
char buf[8] = {0};
403+
char buf[16] = {0};
320404
int val;
321405

322406
ubi = ubi_get_device(ubi_num);
@@ -330,7 +414,11 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
330414
goto out;
331415
}
332416

333-
if (dent == d->dfs_power_cut_min) {
417+
if (dent == d->dfs_emulate_failures) {
418+
if (kstrtouint(buf, 0, &d->emulate_failures) != 0)
419+
count = -EINVAL;
420+
goto out;
421+
} else if (dent == d->dfs_power_cut_min) {
334422
if (kstrtouint(buf, 0, &d->power_cut_min) != 0)
335423
count = -EINVAL;
336424
goto out;
@@ -559,6 +647,12 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
559647
debugfs_create_file("detailed_erase_block_info", S_IRUSR, d->dfs_dir,
560648
(void *)ubi_num, &eraseblk_count_fops);
561649

650+
#ifdef CONFIG_MTD_UBI_FAULT_INJECTION
651+
d->dfs_emulate_failures = debugfs_create_file("emulate_failures",
652+
mode, d->dfs_dir,
653+
(void *)ubi_num,
654+
&dfs_fops);
655+
#endif
562656
return 0;
563657
}
564658

@@ -600,7 +694,5 @@ int ubi_dbg_power_cut(struct ubi_device *ubi, int caller)
600694
if (ubi->dbg.power_cut_counter)
601695
return 0;
602696

603-
ubi_msg(ubi, "XXXXXXXXXXXXXXX emulating a power cut XXXXXXXXXXXXXXXX");
604-
ubi_ro_mode(ubi);
605697
return 1;
606698
}

0 commit comments

Comments
 (0)