Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp330079ybp; Tue, 8 Oct 2019 19:04:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbFm/tX5ZDpwRwCHl9Gkwqegotprc9OUPLYTlvHnavv35Ys3iChrC2w8w209w+3Aks8DOG X-Received: by 2002:a05:6402:1519:: with SMTP id f25mr898451edw.65.1570586677291; Tue, 08 Oct 2019 19:04:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570586677; cv=none; d=google.com; s=arc-20160816; b=VhGbNegGyGRTvNEB8yVhAkIFgQnCzI5dk0XTHne5siKRmabmrtrIgqcJ7vc2yUNw80 mN1exp0TJl4h4g7QIsqYn+yXIPoSL0HQgcHTJ3GXr23XfPEghlUx4yrwPztaIlh9Socp QiyRnI0sV40wi+mbQ/DkSAkVNznC8sgr16Tfz7FrL5EHPdKffHAJMreuXh1NVXqZSXtG +dST6JdnygJ4Rhk8pimHiskEP3/KYmlePIdO9gG/gSkhlNbru48yrjWnL8eTrESjIiuR 4Enm9MtdgPgRb4DBkpNOuy6d1duDp6e6bxk9katI1aaH1xTyCZH1Eargpks85GkVRadr AYsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=QOI1TgdMFCHq6j8VKDRzxgU6VEiFm3md6nRsqj0Y+k4=; b=P9cNMtgb9EKCzh+IBQzXepTeUMCVbBfviGoHof/nrYufRigIM0OFydprlfqhAo1icO 3qg8UQkbSnBQvb/RJwJ1yMHME0Kt2t7gYV9X3255lsiPsHCsigHjzicQscMfW1p0H7Ax Ltfhku9IXUdrHTN9yKBgagx2ofeVXH0rzPi/IhLIhjX8f3IZs1GPDeHxLh2G3IP/OhmU 4dZ39nXu8nMSRe8XNyVQ11lMf0ChkBRniebtILwdsm0CTJyuq/aeEP5O5wBeWannDX8I gBLrTQ7WWiZr/TS+YxyO090vbU5PHkkjDMuJZP+7+E//LhwqYOp54ahijU0pzj8/qPH0 Bz7A== 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 jo19si353585ejb.271.2019.10.08.19.04.13; Tue, 08 Oct 2019 19:04:37 -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 S1729034AbfJICCG (ORCPT + 99 others); Tue, 8 Oct 2019 22:02:06 -0400 Received: from shells.gnugeneration.com ([66.240.222.126]:37466 "EHLO shells.gnugeneration.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726109AbfJICCF (ORCPT ); Tue, 8 Oct 2019 22:02:05 -0400 Received: by shells.gnugeneration.com (Postfix, from userid 1000) id 809B51A40559; Tue, 8 Oct 2019 19:02:05 -0700 (PDT) Date: Tue, 8 Oct 2019 19:02:05 -0700 From: Vito Caputo To: viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] seq_file: move seq_read() flushing into a function Message-ID: <20191009020205.2ezkdwzisnhtoau4@shells.gnugeneration.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Consolidate some duplicated bookkeeping from seq_read() into a function. Signed-off-by: Vito Caputo --- fs/seq_file.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index 1600034a929b..e5d2bccf5ac4 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -141,6 +141,25 @@ static int traverse(struct seq_file *m, loff_t offset) return !m->buf ? -ENOMEM : -EAGAIN; } +static int flush(struct seq_file *m, char __user **buf, size_t *size, size_t *copied) +{ + int err = 0; + size_t n; + + if (!m->count) + return err; + n = min(m->count, *size); + err = copy_to_user(*buf, m->buf + m->from, n); + if (err) + return err; + m->count -= n; + m->from += n; + *size -= n; + *buf += n; + *copied += n; + return err; +} + /** * seq_read - ->read() method for sequential files. * @file: the file to read from @@ -154,7 +173,6 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) { struct seq_file *m = file->private_data; size_t copied = 0; - size_t n; void *p; int err = 0; @@ -207,15 +225,9 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) } /* if not empty - flush it first */ if (m->count) { - n = min(m->count, size); - err = copy_to_user(buf, m->buf + m->from, n); + err = flush(m, &buf, &size, &copied); if (err) goto Efault; - m->count -= n; - m->from += n; - size -= n; - buf += n; - copied += n; if (!size) goto Done; } @@ -273,13 +285,9 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) } } m->op->stop(m, p); - n = min(m->count, size); - err = copy_to_user(buf, m->buf, n); + err = flush(m, &buf, &size, &copied); if (err) goto Efault; - copied += n; - m->count -= n; - m->from = n; Done: if (!copied) copied = err; -- 2.11.0