From patchwork Tue Mar 24 10:32:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qais Yousef X-Patchwork-Id: 6077971 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3F2299F350 for ; Tue, 24 Mar 2015 10:35:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 52CD520212 for ; Tue, 24 Mar 2015 10:35:56 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 3C80B2011B for ; Tue, 24 Mar 2015 10:35:55 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 6CCA126537B; Tue, 24 Mar 2015 11:35:54 +0100 (CET) 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,NO_DNS_FOR_FROM, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 5D35A265177; Tue, 24 Mar 2015 11:33:00 +0100 (CET) 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 96100260462; Tue, 24 Mar 2015 11:32:53 +0100 (CET) Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by alsa0.perex.cz (Postfix) with ESMTP id 0E42326045C for ; Tue, 24 Mar 2015 11:32:44 +0100 (CET) Received: from KLMAIL01.kl.imgtec.org (unknown [192.168.5.35]) by Websense Email Security Gateway with ESMTPS id F188BE1B53E24; Tue, 24 Mar 2015 10:32:40 +0000 (GMT) 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, 24 Mar 2015 10:32:43 +0000 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, 24 Mar 2015 10:32:42 +0000 From: Qais Yousef To: Date: Tue, 24 Mar 2015 10:32:32 +0000 Message-ID: <1427193154-6753-6-git-send-email-qais.yousef@imgtec.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1427193154-6753-1-git-send-email-qais.yousef@imgtec.com> References: <1427193154-6753-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][v2 PATCH 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. --- 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;