Skip to contentSkip to conversation

tpm: return -ENODEV if np is not set

PATCH In review Colin King 2 participants 2 messages Nov 15, 2016 TPM device driver

lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 tpm: return -ENODEV if np is not set

From: Colin Ian King <[email protected]>

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

---
 drivers/char/tpm/tpm_of.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm_of.c +1 -1
index 3af829f..1426590 100644
@@ -31,7 +31,7 @@ int 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);
Signature · 1 line
2.10.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Colin King

From: Colin Ian King <[email protected]>

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.

Quoted 6 lines

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

/Jarkko

Quoted 20 lines
---
 drivers/char/tpm/tpm_of.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm_of.c +1 -1
index 3af829f..1426590 100644
@@ -31,7 +31,7 @@ int 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);
Signature · 1 line
2.10.2

------------------------------------------------------------------------------