From f2a10cc7688ae7ff7e7ccda777d1fd120e450f4a Mon Sep 17 00:00:00 2001 From: Qais Yousef Date: Tue, 5 May 2015 11:21:09 +0100 Subject: [PATCH] compress.c: fix check for errors from poll(), read() and write() When these functions fail they return -1 and set errno. Fix error checks accordingly. Signed-off-by: Qais Yousef Signed-off-by: Vinod Koul --- src/lib/compress.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/lib/compress.c b/src/lib/compress.c index 15dfdb7..84738d2 100644 --- a/src/lib/compress.c +++ b/src/lib/compress.c @@ -383,7 +383,7 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size } /* A pause will cause -EBADFD or zero. * This is not an error, just stop writing */ - if ((ret == 0) || (ret == -EBADFD)) + if ((ret == 0) || (ret < 0 && errno == EBADFD)) break; if (ret < 0) return oops(compress, errno, "poll error"); @@ -397,11 +397,12 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size else to_write = size; written = write(compress->fd, cbuf, to_write); - /* If play was paused the write returns -EBADFD */ - if (written == -EBADFD) - break; - if (written < 0) + if (written < 0) { + /* If play was paused the write returns -EBADFD */ + if (errno == EBADFD) + break; return oops(compress, errno, "write failed!"); + } size -= written; cbuf += written; @@ -443,7 +444,7 @@ int compress_read(struct compress *compress, void *buf, unsigned int size) } /* A pause will cause -EBADFD or zero. * This is not an error, just stop reading */ - if ((ret == 0) || (ret == -EBADFD)) + if ((ret == 0) || (ret < 0 && errno == EBADFD)) break; if (ret < 0) return oops(compress, errno, "poll error"); @@ -457,11 +458,12 @@ int compress_read(struct compress *compress, void *buf, unsigned int size) else to_read = size; num_read = read(compress->fd, cbuf, to_read); - /* If play was paused the read returns -EBADFD */ - if (num_read == -EBADFD) - break; - if (num_read < 0) + if (num_read < 0) { + /* If play was paused the read returns -EBADFD */ + if (errno == EBADFD) + break; return oops(compress, errno, "read failed!"); + } size -= num_read; cbuf += num_read; -- 2.47.3