From patchwork Tue May 5 10:21:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qais Yousef X-Patchwork-Id: 6336791 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A97F7BEEE1 for ; Tue, 5 May 2015 10:26:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C06E320377 for ; Tue, 5 May 2015 10:26:37 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 8C0CA2034F for ; Tue, 5 May 2015 10:26:36 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 9843D265300; Tue, 5 May 2015 12:26:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id C5C5B2650CC; Tue, 5 May 2015 12:24:27 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 20478261A3B; Tue, 5 May 2015 12:24:22 +0200 (CEST) Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by alsa0.perex.cz (Postfix) with ESMTP id 7775E2652C3 for ; Tue, 5 May 2015 12:22:34 +0200 (CEST) Received: from KLMAIL01.kl.imgtec.org (unknown [192.168.5.35]) by Websense Email Security Gateway with ESMTPS id 1F42B127C51E6; Tue, 5 May 2015 11:22:31 +0100 (IST) Received: from LEMAIL01.le.imgtec.org (192.168.152.62) by KLMAIL01.kl.imgtec.org (192.168.5.35) with Microsoft SMTP Server (TLS) id 14.3.195.1; Tue, 5 May 2015 11:21:28 +0100 Received: from qyousef-linux.le.imgtec.org (192.168.154.94) by LEMAIL01.le.imgtec.org (192.168.152.62) with Microsoft SMTP Server (TLS) id 14.3.210.2; Tue, 5 May 2015 11:21:28 +0100 From: Qais Yousef To: Date: Tue, 5 May 2015 11:21:09 +0100 Message-ID: <1430821271-15624-6-git-send-email-qais.yousef@imgtec.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1430821271-15624-1-git-send-email-qais.yousef@imgtec.com> References: <1430821271-15624-1-git-send-email-qais.yousef@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [192.168.154.94] Cc: alsa-devel@alsa-project.org, Qais Yousef Subject: [alsa-devel] [TINYCOMPRESS][PATCH v3 5/7] compress.c: fix check for errors from poll(), read() and write() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP When these functions fail they return -1 and set errno. Fix error checks accordingly. Signed-off-by: Qais Yousef --- 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;