diff options
author | Jonathan Corbet <corbet@lwn.net> | 2009-02-06 17:25:24 -0500 |
---|---|---|
committer | Jonathan Corbet <corbet@lwn.net> | 2009-03-16 10:32:27 -0400 |
commit | db1dd4d376134eba0e08af523b61cc566a4ea1cd (patch) | |
tree | 8882c673abbaa5713511b7046493fa862b9140d1 /drivers/usb | |
parent | 684999149002dd046269666a390458e0acb38280 (diff) |
Use f_lock to protect f_flags
Traditionally, changes to struct file->f_flags have been done under BKL
protection, or with no protection at all. This patch causes all f_flags
changes after file open/creation time to be done under protection of
f_lock. This allows the removal of some BKL usage and fixes a number of
longstanding (if microscopic) races.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/gadget/file_storage.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index 1ab9dac7e12d..33bb76cef33c 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c | |||
@@ -1711,7 +1711,9 @@ static int do_write(struct fsg_dev *fsg) | |||
1711 | curlun->sense_data = SS_WRITE_PROTECTED; | 1711 | curlun->sense_data = SS_WRITE_PROTECTED; |
1712 | return -EINVAL; | 1712 | return -EINVAL; |
1713 | } | 1713 | } |
1714 | spin_lock(&curlun->filp->f_lock); | ||
1714 | curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait | 1715 | curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait |
1716 | spin_unlock(&curlun->filp->f_lock); | ||
1715 | 1717 | ||
1716 | /* Get the starting Logical Block Address and check that it's | 1718 | /* Get the starting Logical Block Address and check that it's |
1717 | * not too big */ | 1719 | * not too big */ |
@@ -1728,8 +1730,11 @@ static int do_write(struct fsg_dev *fsg) | |||
1728 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; | 1730 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; |
1729 | return -EINVAL; | 1731 | return -EINVAL; |
1730 | } | 1732 | } |
1731 | if (fsg->cmnd[1] & 0x08) // FUA | 1733 | if (fsg->cmnd[1] & 0x08) { // FUA |
1734 | spin_lock(&curlun->filp->f_lock); | ||
1732 | curlun->filp->f_flags |= O_SYNC; | 1735 | curlun->filp->f_flags |= O_SYNC; |
1736 | spin_unlock(&curlun->filp->f_lock); | ||
1737 | } | ||
1733 | } | 1738 | } |
1734 | if (lba >= curlun->num_sectors) { | 1739 | if (lba >= curlun->num_sectors) { |
1735 | curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | 1740 | curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; |