Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=8e39c933b1b7df501dbb68879fb1640e277b8a5c
Commit:     8e39c933b1b7df501dbb68879fb1640e277b8a5c
Parent:     53ab97a1c1536015d4d6d900363ea96fece5ed97
Author:     Parag Warudkar <[EMAIL PROTECTED]>
AuthorDate: Tue May 8 00:31:09 2007 -0700
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Tue May 8 11:15:13 2007 -0700

    tpm: fix sleep-in-spinlock
    
    flush_scheduled_work() can sleep, and we're calling it under spinlock.
    
    AFAICS, moving flush_scheduled_work before spin_lock() should not cause any
    problems.
    
    Reason being - The only thing that can race against tpm_release is tpm_open
    (tpm_release is called when last reference to the file is closed and only
    thing that can happen after that is tpm_open??) and tpm_open acquires
    driver_lock and more over it bails out with EBUSY if chip->num_opens is
    greater than 0.
    
    I also moved chip->num_pending-- to after deleting timer and setting data
    pending as it looks more correct for the paranoid although it probably 
doesn't
    matter as it is guarded by driver_lock.  None the less this change should 
not
    cause problems.
    
    While I was at it I noticed a missing NULL check in tpm_register_hardware
    which is fixed with this patch as well.
    
    Signed-off-by: Parag Warudkar <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 drivers/char/tpm/tpm.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index e5a254a..ef991cd 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -942,12 +942,12 @@ int tpm_release(struct inode *inode, struct file *file)
 {
        struct tpm_chip *chip = file->private_data;
 
+       flush_scheduled_work();
        spin_lock(&driver_lock);
        file->private_data = NULL;
-       chip->num_opens--;
        del_singleshot_timer_sync(&chip->user_read_timer);
-       flush_scheduled_work();
        atomic_set(&chip->data_pending, 0);
+       chip->num_opens--;
        put_device(chip->dev);
        kfree(chip->data_buffer);
        spin_unlock(&driver_lock);
@@ -1097,8 +1097,13 @@ struct tpm_chip *tpm_register_hardware(struct device 
*dev, const struct tpm_vend
 
        /* Driver specific per-device data */
        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
-       if (chip == NULL)
+       devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
+
+       if (chip == NULL || devname == NULL) {
+               kfree(chip);
+               kfree(devname);
                return NULL;
+       }
 
        init_MUTEX(&chip->buffer_mutex);
        init_MUTEX(&chip->tpm_mutex);
@@ -1124,7 +1129,6 @@ struct tpm_chip *tpm_register_hardware(struct device 
*dev, const struct tpm_vend
 
        set_bit(chip->dev_num, dev_mask);
 
-       devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
        scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
        chip->vendor.miscdev.name = devname;
 
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to