Re: Sleep during spinlock in TPM driver

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <akpm@...>
Cc: <dsk6@...>, <linux-kernel@...>
Date: Sunday, April 22, 2007 - 3:06 pm

Andrew Morton <akpm <at> linux-foundation.org> writes:

wrote:

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.

David - could you please try the below patch and see if it works? Thanks.

Signed-off-by: Parag Warudkar <parag.warudkar@gmail.com>

--- linux-2.6-us/drivers/char/tpm/tpm.c	2007-04-21 14:55:03.134975360 -0400
+++ linux-2.6-wk/drivers/char/tpm/tpm.c	2007-04-22 14:58:51.957999963 -0400
@@ -942,12 +942,12 @@
   {
   	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 @@

   	/* 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 @@

   	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;

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: Sleep during spinlock in TPM driver, Parag Warudkar, (Sun Apr 22, 3:06 pm)
Re: Sleep during spinlock in TPM driver, Jiri Kosina, (Mon Apr 23, 3:42 am)
Re: Sleep during spinlock in TPM driver, Parag Warudkar, (Mon Apr 23, 8:04 am)
Re: Sleep during spinlock in TPM driver, Jiri Slaby, (Mon Apr 23, 8:42 am)
Re: Sleep during spinlock in TPM driver, Parag Warudkar, (Mon Apr 23, 8:14 am)
Re: Sleep during spinlock in TPM driver, Andrew Morton, (Wed Apr 25, 9:33 pm)