]> git.alsa-project.org Git - tinycompress.git/commitdiff
compress: Must check for POLLERR before POLLOUT/POLLIN
authorRichard Fitzgerald <rf@opensource.wolfsonmicro.com>
Thu, 29 Aug 2013 08:32:02 +0000 (09:32 +0100)
committerVinod Koul <vinod.koul@intel.com>
Wed, 25 Sep 2013 10:14:50 +0000 (15:44 +0530)
In the case of error the ALSA compressed driver sets revents as
(POLLOUT | POLLWRNORM | POLLERR) or (POLLIN | POLLWRNORM | POLLERR).
So we can't assume that POLLOUT or POLLIN indicate success, we must
check for POLLERR first.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
compress.c

index 0e71c28443b68ce983f6a42e3a50fae07b807ba1..5cd0966a51a5eba56049cda64d04b8fdb4054c97 100644 (file)
@@ -378,6 +378,9 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
                                return total;
 
                        ret = poll(&fds, 1, compress->max_poll_wait_ms);
+                       if (fds.revents & POLLERR) {
+                               return oops(compress, EIO, "poll returned error!");
+                       }
                        /* A pause will cause -EBADFD or zero.
                         * This is not an error, just stop writing */
                        if ((ret == 0) || (ret == -EBADFD))
@@ -387,9 +390,6 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
                        if (fds.revents & POLLOUT) {
                                continue;
                        }
-                       if (fds.revents & POLLERR) {
-                               return oops(compress, EIO, "poll returned error!");
-                       }
                }
                /* write avail bytes */
                if (size > avail.avail)
@@ -438,6 +438,9 @@ int compress_read(struct compress *compress, void *buf, unsigned int size)
                                return total;
 
                        ret = poll(&fds, 1, compress->max_poll_wait_ms);
+                       if (fds.revents & POLLERR) {
+                               return oops(compress, EIO, "poll returned error!");
+                       }
                        /* A pause will cause -EBADFD or zero.
                         * This is not an error, just stop reading */
                        if ((ret == 0) || (ret == -EBADFD))
@@ -447,9 +450,6 @@ int compress_read(struct compress *compress, void *buf, unsigned int size)
                        if (fds.revents & POLLIN) {
                                continue;
                        }
-                       if (fds.revents & POLLERR) {
-                               return oops(compress, EIO, "poll returned error!");
-                       }
                }
                /* read avail bytes */
                if (size > avail.avail)
@@ -616,15 +616,15 @@ int compress_wait(struct compress *compress, int timeout_ms)
        fds.events = POLLOUT | POLLIN;
 
        ret = poll(&fds, 1, timeout_ms);
+       if (fds.revents & POLLERR) {
+               return oops(compress, EIO, "poll returned error!");
+       }
        /* A pause will cause -EBADFD or zero. */
        if ((ret < 0) && (ret != -EBADFD))
                return oops(compress, errno, "poll error");
        if (fds.revents & (POLLOUT | POLLIN)) {
                return 0;
        }
-       if (fds.revents & POLLERR) {
-               return oops(compress, EIO, "poll returned error!");
-       }
        return ret;
 }