Skip to content

Commit

Permalink
Remove needless access() in efivarfs_probe()
Browse files Browse the repository at this point in the history
The access() is always seemingly-validated by a statfs():
there's no need for this, but this incurs an additional syscall

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
  • Loading branch information
nabijaczleweli authored and vathpela committed Jan 29, 2024
1 parent 3904527 commit af8bc6d
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/efivarfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,26 @@ efivarfs_probe(void)
{
const char *path = get_efivarfs_path();

if (!access(path, F_OK)) {
int rc = 0;
struct statfs buf;

memset(&buf, '\0', sizeof (buf));
rc = statfs(path, &buf);
if (rc == 0) {
char *tmp;
__typeof__(buf.f_type) magic = EFIVARFS_MAGIC;
if (!memcmp(&buf.f_type, &magic, sizeof (magic)))
return 1;
else
efi_error("bad fs type for %s", path);

tmp = getenv("EFIVARFS_PATH");
if (tmp && !strcmp(tmp, path)) {
efi_error_clear();
return 1;
}
} else {
efi_error("statfs(%s) failed", path);
int rc = 0;
struct statfs buf;

memset(&buf, '\0', sizeof (buf));
rc = statfs(path, &buf);
if (rc == 0) {
char *tmp;
__typeof__(buf.f_type) magic = EFIVARFS_MAGIC;
if (!memcmp(&buf.f_type, &magic, sizeof (magic)))
return 1;
else
efi_error("bad fs type for %s", path);

tmp = getenv("EFIVARFS_PATH");
if (tmp && !strcmp(tmp, path)) {
efi_error_clear();
return 1;
}
} else {
efi_error("access(%s, F_OK) failed", path);
efi_error("statfs(%s) failed", path);
}

return 0;
Expand Down

0 comments on commit af8bc6d

Please sign in to comment.