Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Greg Kroah-Hartman and committed by
Miquel Raynal
c2d73ba8 267c1d77

+41 -104
+7 -19
drivers/mtd/mtdcore.c
··· 382 382 static void mtd_debugfs_populate(struct mtd_info *mtd) 383 383 { 384 384 struct device *dev = &mtd->dev; 385 - struct dentry *root, *dent; 385 + struct dentry *root; 386 386 387 387 if (IS_ERR_OR_NULL(dfs_dir_mtd)) 388 388 return; 389 389 390 390 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 - 396 391 mtd->dbg.dfs_dir = root; 397 392 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); 404 396 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); 412 400 } 413 401 414 402 #ifndef CONFIG_MMU
+1 -7
drivers/mtd/mtdswap.c
··· 1257 1257 static int mtdswap_add_debugfs(struct mtdswap_dev *d) 1258 1258 { 1259 1259 struct dentry *root = d->mtd->dbg.dfs_dir; 1260 - struct dentry *dent; 1261 1260 1262 1261 if (!IS_ENABLED(CONFIG_DEBUG_FS)) 1263 1262 return 0; ··· 1264 1265 if (IS_ERR_OR_NULL(root)) 1265 1266 return -1; 1266 1267 1267 - dent = debugfs_create_file("mtdswap_stats", S_IRUSR, root, d, 1268 - &mtdswap_fops); 1269 - if (!dent) { 1270 - dev_err(d->dev, "debugfs_create_file failed\n"); 1271 - return -1; 1272 - } 1268 + debugfs_create_file("mtdswap_stats", S_IRUSR, root, d, &mtdswap_fops); 1273 1269 1274 1270 return 0; 1275 1271 }
+33 -78
drivers/mtd/ubi/debug.c
··· 509 509 */ 510 510 int ubi_debugfs_init_dev(struct ubi_device *ubi) 511 511 { 512 - int err, n; 513 512 unsigned long ubi_num = ubi->ubi_num; 514 - const char *fname; 515 - struct dentry *dent; 516 513 struct ubi_debug_info *d = &ubi->dbg; 514 + int n; 517 515 518 516 if (!IS_ENABLED(CONFIG_DEBUG_FS)) 519 517 return 0; ··· 520 522 ubi->ubi_num); 521 523 if (n == UBI_DFS_DIR_LEN) { 522 524 /* The array size is too small */ 523 - fname = UBI_DFS_DIR_NAME; 524 - dent = ERR_PTR(-EINVAL); 525 - goto out; 525 + return -EINVAL; 526 526 } 527 527 528 - fname = d->dfs_dir_name; 529 - dent = debugfs_create_dir(fname, dfs_rootdir); 530 - if (IS_ERR_OR_NULL(dent)) 531 - goto out; 532 - d->dfs_dir = dent; 528 + d->dfs_dir = debugfs_create_dir(d->dfs_dir_name, dfs_rootdir); 533 529 534 - fname = "chk_gen"; 535 - dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, 536 - &dfs_fops); 537 - if (IS_ERR_OR_NULL(dent)) 538 - goto out_remove; 539 - d->dfs_chk_gen = dent; 530 + d->dfs_chk_gen = debugfs_create_file("chk_gen", S_IWUSR, d->dfs_dir, 531 + (void *)ubi_num, &dfs_fops); 540 532 541 - fname = "chk_io"; 542 - dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, 543 - &dfs_fops); 544 - if (IS_ERR_OR_NULL(dent)) 545 - goto out_remove; 546 - d->dfs_chk_io = dent; 533 + d->dfs_chk_io = debugfs_create_file("chk_io", S_IWUSR, d->dfs_dir, 534 + (void *)ubi_num, &dfs_fops); 547 535 548 - fname = "chk_fastmap"; 549 - dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, 550 - &dfs_fops); 551 - if (IS_ERR_OR_NULL(dent)) 552 - goto out_remove; 553 - d->dfs_chk_fastmap = dent; 536 + d->dfs_chk_fastmap = debugfs_create_file("chk_fastmap", S_IWUSR, 537 + d->dfs_dir, (void *)ubi_num, 538 + &dfs_fops); 554 539 555 - fname = "tst_disable_bgt"; 556 - dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, 557 - &dfs_fops); 558 - if (IS_ERR_OR_NULL(dent)) 559 - goto out_remove; 560 - d->dfs_disable_bgt = dent; 540 + d->dfs_disable_bgt = debugfs_create_file("tst_disable_bgt", S_IWUSR, 541 + d->dfs_dir, (void *)ubi_num, 542 + &dfs_fops); 561 543 562 - fname = "tst_emulate_bitflips"; 563 - dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, 564 - &dfs_fops); 565 - if (IS_ERR_OR_NULL(dent)) 566 - goto out_remove; 567 - d->dfs_emulate_bitflips = dent; 544 + d->dfs_emulate_bitflips = debugfs_create_file("tst_emulate_bitflips", 545 + S_IWUSR, d->dfs_dir, 546 + (void *)ubi_num, 547 + &dfs_fops); 568 548 569 - fname = "tst_emulate_io_failures"; 570 - dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, 571 - &dfs_fops); 572 - if (IS_ERR_OR_NULL(dent)) 573 - goto out_remove; 574 - d->dfs_emulate_io_failures = dent; 549 + d->dfs_emulate_io_failures = debugfs_create_file("tst_emulate_io_failures", 550 + S_IWUSR, d->dfs_dir, 551 + (void *)ubi_num, 552 + &dfs_fops); 575 553 576 - fname = "tst_emulate_power_cut"; 577 - dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, 578 - &dfs_fops); 579 - if (IS_ERR_OR_NULL(dent)) 580 - goto out_remove; 581 - d->dfs_emulate_power_cut = dent; 554 + d->dfs_emulate_power_cut = debugfs_create_file("tst_emulate_power_cut", 555 + S_IWUSR, d->dfs_dir, 556 + (void *)ubi_num, 557 + &dfs_fops); 582 558 583 - fname = "tst_emulate_power_cut_min"; 584 - dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, 585 - &dfs_fops); 586 - if (IS_ERR_OR_NULL(dent)) 587 - goto out_remove; 588 - d->dfs_power_cut_min = dent; 559 + d->dfs_power_cut_min = debugfs_create_file("tst_emulate_power_cut_min", 560 + S_IWUSR, d->dfs_dir, 561 + (void *)ubi_num, &dfs_fops); 589 562 590 - fname = "tst_emulate_power_cut_max"; 591 - dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, 592 - &dfs_fops); 593 - if (IS_ERR_OR_NULL(dent)) 594 - goto out_remove; 595 - d->dfs_power_cut_max = dent; 563 + d->dfs_power_cut_max = debugfs_create_file("tst_emulate_power_cut_max", 564 + S_IWUSR, d->dfs_dir, 565 + (void *)ubi_num, &dfs_fops); 596 566 597 - fname = "detailed_erase_block_info"; 598 - dent = debugfs_create_file(fname, S_IRUSR, d->dfs_dir, (void *)ubi_num, 599 - &eraseblk_count_fops); 600 - if (IS_ERR_OR_NULL(dent)) 601 - goto out_remove; 567 + debugfs_create_file("detailed_erase_block_info", S_IRUSR, d->dfs_dir, 568 + (void *)ubi_num, &eraseblk_count_fops); 602 569 603 570 return 0; 604 - 605 - out_remove: 606 - debugfs_remove_recursive(d->dfs_dir); 607 - out: 608 - err = dent ? PTR_ERR(dent) : -ENODEV; 609 - ubi_err(ubi, "cannot create \"%s\" debugfs file or directory, error %d\n", 610 - fname, err); 611 - return err; 612 571 } 613 572 614 573 /**