Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1027068ybx; Thu, 31 Oct 2019 04:43:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkEZk0RvPmVM661khjV2ki2Y6Doz6rHRRR1DWyjUaUkmTUiBIERsC96bp7A1MpJ9lKgEfS X-Received: by 2002:a17:906:557:: with SMTP id k23mr3316653eja.165.1572522204557; Thu, 31 Oct 2019 04:43:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572522204; cv=none; d=google.com; s=arc-20160816; b=IahwLm9CXcVd/JFm9a4PuDwln/wQZlFnP/D9VyKehp0+/9UADiPtFKclDVZ8JxUbZ6 eQooCpQ/RPF1LNkU6HK4LVXUXJLX2CXjelW/sXXZJzm0uYRV9BoS5F1AzTfkRXlrjBK9 2kNwfsvAWtvUtQX4xgdSe1gUWMHNbr0Skuv2DK4PZJ0VVG5IZ7APauX9wc55GjLkYIBc VgjBfXdh6PglvjOTRHDDN8t83jzyj2kmbD9ELX6cshdIIArSp2EHYGcopKl5PoSoXlnc RNY7cf4n8KfxXR86bZgly0SLEpmbOVDTaAQDCuoIaxCCSJl7nmRFfLMnRsSEaWg8wsrv Xs7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=qQZseT6H+3sR8F8doBptYyv+/+xaKdGAn4ZzbBqSC+s=; b=ux/np3cZrldd2Q62CRPyv1XRrBTXqmiB1yQpqkMWkbscatdPTNa3N6CvN87BOf1tKj ZG7CXowgCQy0qlTsdGVcvgVOUoRJGZ4LS7AEAZ416Ypz/k01Krl90BQXT5ROGxXHDaFN WHfj9wxyLXGMLkSudypZq9s1ym08T2AHtIKDI+TqG0JueuvRxM2fD7Lb2XFYxprRWGlH +OXT73ff4bh3v6Z2wAygq11muD9ujTXbayVlFM1iwZy1boCz3aK5Aeeut/VbDDItLN7J WJJAmNGReHBAmAPOzuW/1y5nWbxfeRwvfuZEFeqUpbN6HycMPkPrPHP+pkBqnpecEsdu 0lyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c24si4152461edb.328.2019.10.31.04.43.01; Thu, 31 Oct 2019 04:43:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726594AbfJaLjm (ORCPT + 99 others); Thu, 31 Oct 2019 07:39:42 -0400 Received: from regular1.263xmail.com ([211.150.70.206]:41196 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbfJaLjm (ORCPT ); Thu, 31 Oct 2019 07:39:42 -0400 Received: from localhost (unknown [192.168.167.235]) by regular1.263xmail.com (Postfix) with ESMTP id CD7F8275; Thu, 31 Oct 2019 19:39:00 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-SKE-CHECKED: 1 X-ABS-CHECKED: 1 Received: from localhost.localdomain (unknown [14.18.236.69]) by smtp.263.net (postfix) whith ESMTP id P24753T140070325851904S1572521937221647_; Thu, 31 Oct 2019 19:39:01 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <679ed05f8bdd73a17973893edc03c15f> X-RL-SENDER: yili@winhong.com X-SENDER: yili@winhong.com X-LOGIN-NAME: yili@winhong.com X-FST-TO: linux-fsdevel@vger.kernel.org X-SENDER-IP: 14.18.236.69 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 From: Yi Li To: linux-fsdevel@vger.kernel.org Cc: yili@winhong.com, Yi Li , Alexander Viro , linux-kernel@vger.kernel.org Subject: [PATCH] seq_file: fix condition while loop Date: Thu, 31 Oct 2019 19:38:21 +0800 Message-Id: <1572521901-5070-1-git-send-email-yili@winhong.com> X-Mailer: git-send-email 2.7.5 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yi Li Use the break condition of loop body. PTR_ERR has some meanings when p is illegal,and return 0 when p is null. set the err = 0 on the next iteration if err > 0. Signed-off-by: Yi Li --- fs/seq_file.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index 1600034..3796d4f 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -107,9 +107,10 @@ static int traverse(struct seq_file *m, loff_t offset) } p = m->op->start(m, &m->index); while (p) { - error = PTR_ERR(p); - if (IS_ERR(p)) + if (IS_ERR(p)) { + error = PTR_ERR(p); break; + } error = m->op->show(m, p); if (error < 0) break; @@ -222,10 +223,11 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) /* we need at least one record in buffer */ m->from = 0; p = m->op->start(m, &m->index); - while (1) { - err = PTR_ERR(p); - if (!p || IS_ERR(p)) + while (p) { + if (IS_ERR(p)) { + err = PTR_ERR(p); break; + } err = m->op->show(m, p); if (err < 0) break; @@ -233,6 +235,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) m->count = 0; if (unlikely(!m->count)) { p = m->op->next(m, p, &m->index); + err = 0; continue; } if (m->count < m->size) -- 2.7.5