From patchwork Mon Jul 2 00:49:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "xinhua.Cao" X-Patchwork-Id: 10500275 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C5846035E for ; Mon, 2 Jul 2018 00:50:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCFD128727 for ; Mon, 2 Jul 2018 00:50:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBEFE28789; Mon, 2 Jul 2018 00:50:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4B68228727 for ; Mon, 2 Jul 2018 00:50:36 +0000 (UTC) Received: from localhost ([::1]:56134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZn33-00038z-E7 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 01 Jul 2018 20:50:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZn2I-0002kf-DX for qemu-devel@nongnu.org; Sun, 01 Jul 2018 20:49:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fZn2F-00081W-AI for qemu-devel@nongnu.org; Sun, 01 Jul 2018 20:49:46 -0400 Received: from [45.249.212.35] (port=45075 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fZn2E-0007yG-Tn for qemu-devel@nongnu.org; Sun, 01 Jul 2018 20:49:43 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 7E44952246C83; Mon, 2 Jul 2018 08:49:33 +0800 (CST) Received: from localhost (10.177.25.200) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.382.0; Mon, 2 Jul 2018 08:49:26 +0800 From: xinhua.Cao To: , , , , Date: Mon, 2 Jul 2018 08:49:10 +0800 Message-ID: <20180702004910.13216-1-caoxinhua@huawei.com> X-Mailer: git-send-email 2.8.3 MIME-Version: 1.0 X-Originating-IP: [10.177.25.200] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 45.249.212.35 Subject: [Qemu-devel] [PATCH] qemu-char: reset errno before qemu char write or read action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "xinhua.Cao" , weidong.huang@huawei.com, weifuqiang@huawei.com, qemu-devel@nongnu.org, king.wang@huawei.com, liuyongan@huawei.com, arei.gonglei@huawei.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In the tcp_chr_write function, we checked errno, but errno was not reset before a read or write operation. Therefore, this check of errno's actions is often incorrect after EAGAIN has occurred. We reset errno before reading and writing to ensure the correctness of errno's judgment Signed-off-by: xinhua.Cao Reviewed-by: Philippe Mathieu-Daudé --- chardev/char-fe.c | 1 + chardev/char.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index b1f228e..d96ca6f 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -69,6 +69,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) while (offset < len) { retry: + errno = 0; res = CHARDEV_GET_CLASS(s)->chr_sync_read(s, buf + offset, len - offset); if (res == -1 && errno == EAGAIN) { diff --git a/chardev/char.c b/chardev/char.c index 76d866e..3387442 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -85,6 +85,7 @@ static void qemu_chr_write_log(Chardev *s, const uint8_t *buf, size_t len) while (done < len) { retry: + errno = 0; ret = write(s->logfd, buf + done, len - done); if (ret == -1 && errno == EAGAIN) { g_usleep(100); @@ -109,6 +110,7 @@ static int qemu_chr_write_buffer(Chardev *s, qemu_mutex_lock(&s->chr_write_lock); while (*offset < len) { retry: + errno = 0; res = cc->chr_write(s, buf + *offset, len - *offset); if (res < 0 && errno == EAGAIN && write_all) { g_usleep(100);