tpm: Only call pm_runtime_get_sync if device has a parent
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Mon, 7 Nov 2016 12:14:33 +0000 (07:14 -0500)
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Sun, 27 Nov 2016 23:31:31 +0000 (01:31 +0200)
Only call pm_runtime_get_sync if the device has a parent. This
change fixes a crash in the tpm_vtpm_proxy driver since that
driver does not have a parent device.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
drivers/char/tpm/tpm-interface.c

index ef0fcdb..a2688ac 100644 (file)
@@ -357,7 +357,8 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
        if (!(flags & TPM_TRANSMIT_UNLOCKED))
                mutex_lock(&chip->tpm_mutex);
 
-       pm_runtime_get_sync(chip->dev.parent);
+       if (chip->dev.parent)
+               pm_runtime_get_sync(chip->dev.parent);
 
        rc = chip->ops->send(chip, (u8 *) buf, count);
        if (rc < 0) {
@@ -400,7 +401,8 @@ out_recv:
                dev_err(&chip->dev,
                        "tpm_transmit: tpm_recv: error %zd\n", rc);
 out:
-       pm_runtime_put_sync(chip->dev.parent);
+       if (chip->dev.parent)
+               pm_runtime_put_sync(chip->dev.parent);
 
        if (!(flags & TPM_TRANSMIT_UNLOCKED))
                mutex_unlock(&chip->tpm_mutex);