diff options
-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 = { |