From: Andrew Morton Date: Wed, 1 Feb 2006 11:05:01 +0000 (-0800) Subject: [PATCH] tpm_bios: securityfs error checking fix X-Git-Tag: v2.6.16-rc2~142 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca4a031f6b43edb8745ebc0a1b7307c24719dae4;p=linux-2.6 [PATCH] tpm_bios: securityfs error checking fix These functions return ERR_PTR()s on error, not NULL. Spotted by Randy. Cc: Serge Hallyn Cc: Kylene Jo Hall Cc: "Randy.Dunlap" Acked-by: Greg KH Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c index aedf7a8e6d..9ffa5643e7 100644 --- a/drivers/char/tpm/tpm_bios.c +++ b/drivers/char/tpm/tpm_bios.c @@ -487,26 +487,35 @@ struct file_operations tpm_binary_bios_measurements_ops = { .release = tpm_bios_measurements_release, }; +static int is_bad(void *p) +{ + if (!p) + return 1; + if (IS_ERR(p) && (PTR_ERR(p) != -ENODEV)) + return 1; + return 0; +} + struct dentry **tpm_bios_log_setup(char *name) { struct dentry **ret = NULL, *tpm_dir, *bin_file, *ascii_file; tpm_dir = securityfs_create_dir(name, NULL); - if (!tpm_dir) + if (is_bad(tpm_dir)) goto out; bin_file = securityfs_create_file("binary_bios_measurements", S_IRUSR | S_IRGRP, tpm_dir, NULL, &tpm_binary_bios_measurements_ops); - if (!bin_file) + if (is_bad(bin_file)) goto out_tpm; ascii_file = securityfs_create_file("ascii_bios_measurements", S_IRUSR | S_IRGRP, tpm_dir, NULL, &tpm_ascii_bios_measurements_ops); - if (!ascii_file) + if (is_bad(ascii_file)) goto out_bin; ret = kmalloc(3 * sizeof(struct dentry *), GFP_KERNEL);