Skip to contentSkip to conversation

tpm: fix ordering bug in error path

PATCH New Kylene Jo Hall 1 participant 1 message Apr 19, 2006 TPM device driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tpm: fix ordering bug in error path

The clear_bit of chip->dev_num ended up after the kfree of chip in the error path of the tpm_register_hardware function. This patch fixes things to avoid a potential segmentation fault.

This bug was found by Coverity.

---
 drivers/char/tpm/tpm.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm.c +1 -1
@@ -1139,8 +1139,8 @@ struct tpm_chip *tpm_register_hardware(s
 			chip->vendor.miscdev.name,
 			chip->vendor.miscdev.minor);
 		put_device(dev);
-		kfree(chip);
 		clear_bit(chip->dev_num, dev_mask);
+		kfree(chip);
 		return NULL;
 	}