Skip to content

Commit

Permalink
linux_mtd: Bail out early if sysfs node doesn't exist
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dhendrix authored and i-c-o-n committed Jun 24, 2018
1 parent a75a2ed commit b0247b3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions linux_mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b0247b3

Please sign in to comment.