All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qais Yousef <qais.yousef@imgtec.com>
To: vinod.koul@intel.com
Cc: alsa-devel@alsa-project.org, Qais Yousef <qais.yousef@imgtec.com>
Subject: [TINYCOMPRESS][PATCH 5/6] compress.c: fix check for errors from poll(), read() and write()
Date: Mon, 23 Mar 2015 13:09:04 +0000	[thread overview]
Message-ID: <1427116145-519-6-git-send-email-qais.yousef@imgtec.com> (raw)
In-Reply-To: <1427116145-519-1-git-send-email-qais.yousef@imgtec.com>

When these functions fail they return -1 and set errno. Fix error checks
accordingly.
---
 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 15dfdb74137e..84738d24ff45 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.1.0

  parent reply	other threads:[~2015-03-23 13:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-23 13:08 [TINYCOMPRESS][PATCH 0/6] Convert build system to autotools Qais Yousef
2015-03-23 13:09 ` [TINYCOMPRESS][PATCH 2/6] add .gitignore file Qais Yousef
2015-03-23 13:09 ` [TINYCOMPRESS][PATCH 3/6] makefile.linux: delete as no longer necessary/used Qais Yousef
2015-03-23 13:09 ` [TINYCOMPRESS][PATCH 4/6] Android.mk: Update to use the new location of source files Qais Yousef
2015-03-23 13:09 ` Qais Yousef [this message]
2015-03-23 13:09 ` [TINYCOMPRESS][PATCH 6/6] src/lib/utils.c: remove this empty file Qais Yousef
2015-03-23 15:19 ` [TINYCOMPRESS][PATCH 0/6] Convert build system to autotools Qais Yousef
2015-03-23 16:40 ` Vinod Koul
2015-03-24  9:57   ` Qais Yousef

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1427116145-519-6-git-send-email-qais.yousef@imgtec.com \
    --to=qais.yousef@imgtec.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.