diff options
Diffstat (limited to 'fs/fcntl.c')
| -rw-r--r-- | fs/fcntl.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/fs/fcntl.c b/fs/fcntl.c index 04df8570a2d2..431bb6459273 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c | |||
| @@ -141,7 +141,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes) | |||
| 141 | return ret; | 141 | return ret; |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | FASYNC | O_DIRECT | O_NOATIME) | 144 | #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME) |
| 145 | 145 | ||
| 146 | static int setfl(int fd, struct file * filp, unsigned long arg) | 146 | static int setfl(int fd, struct file * filp, unsigned long arg) |
| 147 | { | 147 | { |
| @@ -177,23 +177,19 @@ static int setfl(int fd, struct file * filp, unsigned long arg) | |||
| 177 | return error; | 177 | return error; |
| 178 | 178 | ||
| 179 | /* | 179 | /* |
| 180 | * We still need a lock here for now to keep multiple FASYNC calls | 180 | * ->fasync() is responsible for setting the FASYNC bit. |
| 181 | * from racing with each other. | ||
| 182 | */ | 181 | */ |
| 183 | lock_kernel(); | 182 | if (((arg ^ filp->f_flags) & FASYNC) && filp->f_op && |
| 184 | if ((arg ^ filp->f_flags) & FASYNC) { | 183 | filp->f_op->fasync) { |
| 185 | if (filp->f_op && filp->f_op->fasync) { | 184 | error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0); |
| 186 | error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0); | 185 | if (error < 0) |
| 187 | if (error < 0) | 186 | goto out; |
| 188 | goto out; | ||
| 189 | } | ||
| 190 | } | 187 | } |
| 191 | |||
| 192 | spin_lock(&filp->f_lock); | 188 | spin_lock(&filp->f_lock); |
| 193 | filp->f_flags = (arg & SETFL_MASK) | (filp->f_flags & ~SETFL_MASK); | 189 | filp->f_flags = (arg & SETFL_MASK) | (filp->f_flags & ~SETFL_MASK); |
| 194 | spin_unlock(&filp->f_lock); | 190 | spin_unlock(&filp->f_lock); |
| 191 | |||
| 195 | out: | 192 | out: |
| 196 | unlock_kernel(); | ||
| 197 | return error; | 193 | return error; |
| 198 | } | 194 | } |
| 199 | 195 | ||
| @@ -518,7 +514,7 @@ static DEFINE_RWLOCK(fasync_lock); | |||
| 518 | static struct kmem_cache *fasync_cache __read_mostly; | 514 | static struct kmem_cache *fasync_cache __read_mostly; |
| 519 | 515 | ||
| 520 | /* | 516 | /* |
| 521 | * fasync_helper() is used by some character device drivers (mainly mice) | 517 | * fasync_helper() is used by almost all character device drivers |
| 522 | * to set up the fasync queue. It returns negative on error, 0 if it did | 518 | * to set up the fasync queue. It returns negative on error, 0 if it did |
| 523 | * no changes and positive if it added/deleted the entry. | 519 | * no changes and positive if it added/deleted the entry. |
| 524 | */ | 520 | */ |
| @@ -557,6 +553,13 @@ int fasync_helper(int fd, struct file * filp, int on, struct fasync_struct **fap | |||
| 557 | result = 1; | 553 | result = 1; |
| 558 | } | 554 | } |
| 559 | out: | 555 | out: |
| 556 | /* Fix up FASYNC bit while still holding fasync_lock */ | ||
| 557 | spin_lock(&filp->f_lock); | ||
| 558 | if (on) | ||
| 559 | filp->f_flags |= FASYNC; | ||
| 560 | else | ||
| 561 | filp->f_flags &= ~FASYNC; | ||
| 562 | spin_unlock(&filp->f_lock); | ||
| 560 | write_unlock_irq(&fasync_lock); | 563 | write_unlock_irq(&fasync_lock); |
| 561 | return result; | 564 | return result; |
| 562 | } | 565 | } |
