diff options
-rw-r--r-- | arch/powerpc/platforms/cell/spufs/file.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c index adb5abb9af5d..f139cd8b594d 100644 --- a/arch/powerpc/platforms/cell/spufs/file.c +++ b/arch/powerpc/platforms/cell/spufs/file.c | |||
@@ -2503,30 +2503,38 @@ static ssize_t spufs_switch_log_read(struct file *file, char __user *buf, | |||
2503 | char tbuf[128]; | 2503 | char tbuf[128]; |
2504 | int width; | 2504 | int width; |
2505 | 2505 | ||
2506 | if (file->f_flags & O_NONBLOCK) { | 2506 | if (spufs_switch_log_used(ctx) == 0) { |
2507 | if (spufs_switch_log_used(ctx) == 0) { | 2507 | if (cnt > 0) { |
2508 | /* If there's data ready to go, we can | ||
2509 | * just return straight away */ | ||
2510 | break; | ||
2511 | |||
2512 | } else if (file->f_flags & O_NONBLOCK) { | ||
2508 | error = -EAGAIN; | 2513 | error = -EAGAIN; |
2509 | break; | 2514 | break; |
2515 | |||
2516 | } else { | ||
2517 | /* spufs_wait will drop the mutex and | ||
2518 | * re-acquire, but since we're in read(), the | ||
2519 | * file cannot be _released (and so | ||
2520 | * ctx->switch_log is stable). | ||
2521 | */ | ||
2522 | error = spufs_wait(ctx->switch_log->wait, | ||
2523 | spufs_switch_log_used(ctx) > 0); | ||
2524 | |||
2525 | /* On error, spufs_wait returns without the | ||
2526 | * state mutex held */ | ||
2527 | if (error) | ||
2528 | return error; | ||
2529 | |||
2530 | /* We may have had entries read from underneath | ||
2531 | * us while we dropped the mutex in spufs_wait, | ||
2532 | * so re-check */ | ||
2533 | if (spufs_switch_log_used(ctx) == 0) | ||
2534 | continue; | ||
2510 | } | 2535 | } |
2511 | } else { | ||
2512 | /* spufs_wait will drop the mutex and re-acquire, | ||
2513 | * but since we're in read(), the file cannot be | ||
2514 | * _released (and so ctx->switch_log is stable). | ||
2515 | */ | ||
2516 | error = spufs_wait(ctx->switch_log->wait, | ||
2517 | spufs_switch_log_used(ctx) > 0); | ||
2518 | |||
2519 | /* On error, spufs_wait returns without the | ||
2520 | * state mutex held */ | ||
2521 | if (error) | ||
2522 | return error; | ||
2523 | } | 2536 | } |
2524 | 2537 | ||
2525 | /* We may have had entries read from underneath us while we | ||
2526 | * dropped the mutex in spufs_wait, so re-check */ | ||
2527 | if (ctx->switch_log->head == ctx->switch_log->tail) | ||
2528 | continue; | ||
2529 | |||
2530 | width = switch_log_sprint(ctx, tbuf, sizeof(tbuf)); | 2538 | width = switch_log_sprint(ctx, tbuf, sizeof(tbuf)); |
2531 | if (width < len) | 2539 | if (width < len) |
2532 | ctx->switch_log->tail = | 2540 | ctx->switch_log->tail = |