Skip to content

Commit c2d73ba

Browse files
gregkhmiquelraynal
authored andcommitted
mtd: no need to check return value of debugfs_create functions
When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this. Cc: David Woodhouse <dwmw2@infradead.org> Cc: Brian Norris <computersforpeace@gmail.com> Cc: Marek Vasut <marek.vasut@gmail.com> Cc: Miquel Raynal <miquel.raynal@bootlin.com> Cc: Richard Weinberger <richard@nod.at> Cc: Vignesh Raghavendra <vigneshr@ti.com> Cc: Artem Bityutskiy <dedekind1@gmail.com> Cc: linux-mtd@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 267c1d7 commit c2d73ba

3 files changed

Lines changed: 51 additions & 114 deletions

File tree

‎drivers/mtd/mtdcore.c‎

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -382,33 +382,21 @@ static struct dentry *dfs_dir_mtd;
382382
static void mtd_debugfs_populate(struct mtd_info *mtd)
383383
{
384384
struct device *dev = &mtd->dev;
385-
struct dentry *root, *dent;
385+
struct dentry *root;
386386

387387
if (IS_ERR_OR_NULL(dfs_dir_mtd))
388388
return;
389389

390390
root = debugfs_create_dir(dev_name(dev), dfs_dir_mtd);
391-
if (IS_ERR_OR_NULL(root)) {
392-
dev_dbg(dev, "won't show data in debugfs\n");
393-
return;
394-
}
395-
396391
mtd->dbg.dfs_dir = root;
397392

398-
if (mtd->dbg.partid) {
399-
dent = debugfs_create_file("partid", 0400, root, mtd,
400-
&mtd_partid_debug_fops);
401-
if (IS_ERR_OR_NULL(dent))
402-
dev_err(dev, "can't create debugfs entry for partid\n");
403-
}
393+
if (mtd->dbg.partid)
394+
debugfs_create_file("partid", 0400, root, mtd,
395+
&mtd_partid_debug_fops);
404396

405-
if (mtd->dbg.partname) {
406-
dent = debugfs_create_file("partname", 0400, root, mtd,
407-
&mtd_partname_debug_fops);
408-
if (IS_ERR_OR_NULL(dent))
409-
dev_err(dev,
410-
"can't create debugfs entry for partname\n");
411-
}
397+
if (mtd->dbg.partname)
398+
debugfs_create_file("partname", 0400, root, mtd,
399+
&mtd_partname_debug_fops);
412400
}
413401

414402
#ifndef CONFIG_MMU

‎drivers/mtd/mtdswap.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,20 +1257,14 @@ DEFINE_SHOW_ATTRIBUTE(mtdswap);
12571257
static int mtdswap_add_debugfs(struct mtdswap_dev *d)
12581258
{
12591259
struct dentry *root = d->mtd->dbg.dfs_dir;
1260-
struct dentry *dent;
12611260

12621261
if (!IS_ENABLED(CONFIG_DEBUG_FS))
12631262
return 0;
12641263

12651264
if (IS_ERR_OR_NULL(root))
12661265
return -1;
12671266

1268-
dent = debugfs_create_file("mtdswap_stats", S_IRUSR, root, d,
1269-
&mtdswap_fops);
1270-
if (!dent) {
1271-
dev_err(d->dev, "debugfs_create_file failed\n");
1272-
return -1;
1273-
}
1267+
debugfs_create_file("mtdswap_stats", S_IRUSR, root, d, &mtdswap_fops);
12741268

12751269
return 0;
12761270
}

‎drivers/mtd/ubi/debug.c‎

Lines changed: 43 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,9 @@ static const struct file_operations eraseblk_count_fops = {
509509
*/
510510
int ubi_debugfs_init_dev(struct ubi_device *ubi)
511511
{
512-
int err, n;
513512
unsigned long ubi_num = ubi->ubi_num;
514-
const char *fname;
515-
struct dentry *dent;
516513
struct ubi_debug_info *d = &ubi->dbg;
514+
int n;
517515

518516
if (!IS_ENABLED(CONFIG_DEBUG_FS))
519517
return 0;
@@ -522,95 +520,52 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
522520
ubi->ubi_num);
523521
if (n == UBI_DFS_DIR_LEN) {
524522
/* The array size is too small */
525-
fname = UBI_DFS_DIR_NAME;
526-
dent = ERR_PTR(-EINVAL);
527-
goto out;
523+
return -EINVAL;
528524
}
529525

530-
fname = d->dfs_dir_name;
531-
dent = debugfs_create_dir(fname, dfs_rootdir);
532-
if (IS_ERR_OR_NULL(dent))
533-
goto out;
534-
d->dfs_dir = dent;
535-
536-
fname = "chk_gen";
537-
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
538-
&dfs_fops);
539-
if (IS_ERR_OR_NULL(dent))
540-
goto out_remove;
541-
d->dfs_chk_gen = dent;
542-
543-
fname = "chk_io";
544-
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
545-
&dfs_fops);
546-
if (IS_ERR_OR_NULL(dent))
547-
goto out_remove;
548-
d->dfs_chk_io = dent;
549-
550-
fname = "chk_fastmap";
551-
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
552-
&dfs_fops);
553-
if (IS_ERR_OR_NULL(dent))
554-
goto out_remove;
555-
d->dfs_chk_fastmap = dent;
556-
557-
fname = "tst_disable_bgt";
558-
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
559-
&dfs_fops);
560-
if (IS_ERR_OR_NULL(dent))
561-
goto out_remove;
562-
d->dfs_disable_bgt = dent;
563-
564-
fname = "tst_emulate_bitflips";
565-
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
566-
&dfs_fops);
567-
if (IS_ERR_OR_NULL(dent))
568-
goto out_remove;
569-
d->dfs_emulate_bitflips = dent;
570-
571-
fname = "tst_emulate_io_failures";
572-
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
573-
&dfs_fops);
574-
if (IS_ERR_OR_NULL(dent))
575-
goto out_remove;
576-
d->dfs_emulate_io_failures = dent;
577-
578-
fname = "tst_emulate_power_cut";
579-
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
580-
&dfs_fops);
581-
if (IS_ERR_OR_NULL(dent))
582-
goto out_remove;
583-
d->dfs_emulate_power_cut = dent;
584-
585-
fname = "tst_emulate_power_cut_min";
586-
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
587-
&dfs_fops);
588-
if (IS_ERR_OR_NULL(dent))
589-
goto out_remove;
590-
d->dfs_power_cut_min = dent;
591-
592-
fname = "tst_emulate_power_cut_max";
593-
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
594-
&dfs_fops);
595-
if (IS_ERR_OR_NULL(dent))
596-
goto out_remove;
597-
d->dfs_power_cut_max = dent;
598-
599-
fname = "detailed_erase_block_info";
600-
dent = debugfs_create_file(fname, S_IRUSR, d->dfs_dir, (void *)ubi_num,
601-
&eraseblk_count_fops);
602-
if (IS_ERR_OR_NULL(dent))
603-
goto out_remove;
526+
d->dfs_dir = debugfs_create_dir(d->dfs_dir_name, dfs_rootdir);
604527

605-
return 0;
528+
d->dfs_chk_gen = debugfs_create_file("chk_gen", S_IWUSR, d->dfs_dir,
529+
(void *)ubi_num, &dfs_fops);
606530

607-
out_remove:
608-
debugfs_remove_recursive(d->dfs_dir);
609-
out:
610-
err = dent ? PTR_ERR(dent) : -ENODEV;
611-
ubi_err(ubi, "cannot create \"%s\" debugfs file or directory, error %d\n",
612-
fname, err);
613-
return err;
531+
d->dfs_chk_io = debugfs_create_file("chk_io", S_IWUSR, d->dfs_dir,
532+
(void *)ubi_num, &dfs_fops);
533+
534+
d->dfs_chk_fastmap = debugfs_create_file("chk_fastmap", S_IWUSR,
535+
d->dfs_dir, (void *)ubi_num,
536+
&dfs_fops);
537+
538+
d->dfs_disable_bgt = debugfs_create_file("tst_disable_bgt", S_IWUSR,
539+
d->dfs_dir, (void *)ubi_num,
540+
&dfs_fops);
541+
542+
d->dfs_emulate_bitflips = debugfs_create_file("tst_emulate_bitflips",
543+
S_IWUSR, d->dfs_dir,
544+
(void *)ubi_num,
545+
&dfs_fops);
546+
547+
d->dfs_emulate_io_failures = debugfs_create_file("tst_emulate_io_failures",
548+
S_IWUSR, d->dfs_dir,
549+
(void *)ubi_num,
550+
&dfs_fops);
551+
552+
d->dfs_emulate_power_cut = debugfs_create_file("tst_emulate_power_cut",
553+
S_IWUSR, d->dfs_dir,
554+
(void *)ubi_num,
555+
&dfs_fops);
556+
557+
d->dfs_power_cut_min = debugfs_create_file("tst_emulate_power_cut_min",
558+
S_IWUSR, d->dfs_dir,
559+
(void *)ubi_num, &dfs_fops);
560+
561+
d->dfs_power_cut_max = debugfs_create_file("tst_emulate_power_cut_max",
562+
S_IWUSR, d->dfs_dir,
563+
(void *)ubi_num, &dfs_fops);
564+
565+
debugfs_create_file("detailed_erase_block_info", S_IRUSR, d->dfs_dir,
566+
(void *)ubi_num, &eraseblk_count_fops);
567+
568+
return 0;
614569
}
615570

616571
/**

0 commit comments

Comments
 (0)