David Hendricks has uploaded this change for review. ( https://review.coreboot.org/26500
Change subject: linux_mtd: Bail out early if sysfs node doesn't exist ......................................................................
linux_mtd: Bail out early if sysfs node doesn't exist
This checks that the MTD sysfs node we will use actually exists prior to calling setup code. Although the setup code will eventually catch such an error, we need to think about the use case before printing possibly irrelevant/confusing error message to the terminal.
This patch makes it so that we only print an error message if the user specifies a non-existent MTD device. Otherwise, the failure is considered benign and we only print a debug message prior to bailing out.
Change-Id: I8dc965eecc68cd305a989016869c688fe1a3921f Signed-off-by: David Hendricks dhendricks@fb.com --- M linux_mtd.c 1 file changed, 18 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/00/26500/1
diff --git a/linux_mtd.c b/linux_mtd.c index e65f093..ae8bef2 100644 --- a/linux_mtd.c +++ b/linux_mtd.c @@ -376,6 +376,24 @@ } }
+ /* + * If user specified the MTD device number then error out if it doesn't + * appear to exist. Otherwise assume the error is benign and print a + * debug message. Bail out in either case. + */ + char sysfs_path[32]; + if (snprintf(sysfs_path, sizeof(sysfs_path), "%s/mtd%d", LINUX_MTD_SYSFS_ROOT, dev_num) < 0) + goto linux_mtd_init_exit; + + struct stat s; + if (stat(sysfs_path, &s) < 0) { + if (param) + msg_perr("%s does not exist\n", sysfs_path); + else + msg_pdbg("%s does not exist\n", sysfs_path); + goto linux_mtd_init_exit; + } + if (linux_mtd_setup(dev_num)) goto linux_mtd_init_exit;