From: Colin Ian King Date: Tue, 15 Nov 2016 13:27:22 +0000 (+0000) Subject: tpm: return -ENODEV if np is not set X-Git-Tag: v4.10-rc1~116^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=79eec5b940cffff14c7bd1b9eb856ccb36274cc2;p=thirdparty%2Fkernel%2Flinux.git tpm: return -ENODEV if np is not set device_node np contains a garbage value from the stack and it is only set if chip->dev.parent->of_node is not null. Thus the check for a null np won't spot a garbage value of np from the stack if chip->dev.parent->of_node is null and if np contains an garbage non-null value. I believe the correct fix is to return -ENODEV if and only if chip->dev.parent->of_node is null. Found with static analysis by CoverityScan, CID 1377755 Signed-off-by: Colin Ian King Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen --- diff --git a/drivers/char/tpm/tpm_of.c b/drivers/char/tpm/tpm_of.c index 643cc8ccb35bd..36df9df4c472b 100644 --- a/drivers/char/tpm/tpm_of.c +++ b/drivers/char/tpm/tpm_of.c @@ -31,7 +31,7 @@ int tpm_read_log_of(struct tpm_chip *chip) log = &chip->log; if (chip->dev.parent->of_node) np = chip->dev.parent->of_node; - if (!np) + else return -ENODEV; sizep = of_get_property(np, "linux,sml-size", NULL);