diff options
author | Ian Munsie <imunsie@au1.ibm.com> | 2014-10-08 20:17:46 -0400 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2014-10-08 20:29:57 -0400 |
commit | d53ba6b3bba33432cc37b7101a86f8f3392c46e7 (patch) | |
tree | a82fe60070c230303bc1daa7ce55384ab46904d0 | |
parent | a9282d01cf357379ce29103cec5e7651a53c634d (diff) |
cxl: Fix afu_read() not doing finish_wait() on signal or non-blocking
If afu_read() returned due to a signal or the AFU file descriptor being
opened non-blocking it would not call finish_wait() before returning,
which could lead to a crash later when something else wakes up the wait
queue.
This patch restructures the wait logic to ensure that the cleanup is
done correctly.
Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r-- | drivers/misc/cxl/file.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c index 847b7e646a7e..378b099e7c0b 100644 --- a/drivers/misc/cxl/file.c +++ b/drivers/misc/cxl/file.c | |||
@@ -273,6 +273,7 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count, | |||
273 | struct cxl_context *ctx = file->private_data; | 273 | struct cxl_context *ctx = file->private_data; |
274 | struct cxl_event event; | 274 | struct cxl_event event; |
275 | unsigned long flags; | 275 | unsigned long flags; |
276 | int rc; | ||
276 | DEFINE_WAIT(wait); | 277 | DEFINE_WAIT(wait); |
277 | 278 | ||
278 | if (count < CXL_READ_MIN_SIZE) | 279 | if (count < CXL_READ_MIN_SIZE) |
@@ -285,13 +286,17 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count, | |||
285 | if (ctx_event_pending(ctx)) | 286 | if (ctx_event_pending(ctx)) |
286 | break; | 287 | break; |
287 | 288 | ||
288 | spin_unlock_irqrestore(&ctx->lock, flags); | 289 | if (file->f_flags & O_NONBLOCK) { |
289 | if (file->f_flags & O_NONBLOCK) | 290 | rc = -EAGAIN; |
290 | return -EAGAIN; | 291 | goto out; |
292 | } | ||
291 | 293 | ||
292 | if (signal_pending(current)) | 294 | if (signal_pending(current)) { |
293 | return -ERESTARTSYS; | 295 | rc = -ERESTARTSYS; |
296 | goto out; | ||
297 | } | ||
294 | 298 | ||
299 | spin_unlock_irqrestore(&ctx->lock, flags); | ||
295 | pr_devel("afu_read going to sleep...\n"); | 300 | pr_devel("afu_read going to sleep...\n"); |
296 | schedule(); | 301 | schedule(); |
297 | pr_devel("afu_read woken up\n"); | 302 | pr_devel("afu_read woken up\n"); |
@@ -336,6 +341,11 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count, | |||
336 | if (copy_to_user(buf, &event, event.header.size)) | 341 | if (copy_to_user(buf, &event, event.header.size)) |
337 | return -EFAULT; | 342 | return -EFAULT; |
338 | return event.header.size; | 343 | return event.header.size; |
344 | |||
345 | out: | ||
346 | finish_wait(&ctx->wq, &wait); | ||
347 | spin_unlock_irqrestore(&ctx->lock, flags); | ||
348 | return rc; | ||
339 | } | 349 | } |
340 | 350 | ||
341 | static const struct file_operations afu_fops = { | 351 | static const struct file_operations afu_fops = { |