tpm: fix sleep-in-spinlock
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 <e69d5020cbc9d855ec7c1cbb4d077dd67b741a5f@gmail.com>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

TeamVee-Kanas/android_kernel_samsung_kanas,KristFoundation/Programs,KristFoundation/Programs,TeamVee-Kanas/android_kernel_samsung_kanas,KristFoundation/Programs,KristFoundation/Programs,TeamVee-Kanas/android_kernel_samsung_kanas,KristFoundation/Programs,TeamVee-Kanas/android_kernel_samsung_kanas,TeamVee-Kanas/android_kernel_samsung_kanas,KristFoundation/Programs