1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 15:12:36 +02:00

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 a
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>
Reviewed-on: https://review.coreboot.org/26500
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
This commit is contained in:
David Hendricks 2018-05-23 21:50:18 -07:00 committed by Nico Huber
parent a75a2edc05
commit b0247b3acb

View File

@ -376,6 +376,24 @@ int linux_mtd_init(void)
}
}
/*
* 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;