Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752374AbdLGXUl (ORCPT ); Thu, 7 Dec 2017 18:20:41 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:35419 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752303AbdLGXUi (ORCPT ); Thu, 7 Dec 2017 18:20:38 -0500 Date: Thu, 7 Dec 2017 15:20:37 -0800 From: Matthew Wilcox To: Vasyl Gomonovych Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fs/seq_file: Fix warning of passing zero to 'PTR_ERR' Message-ID: <20171207232037.GE26792@bombadil.infradead.org> References: <1512687788-27172-1-git-send-email-gomonovych@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1512687788-27172-1-git-send-email-gomonovych@gmail.com> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1335 Lines: 42 On Fri, Dec 08, 2017 at 12:03:07AM +0100, Vasyl Gomonovych wrote: > p could be NULL and passing into PTR_ERR What makes you think this is correct? To quote the documentation: The next function to implement is called, amazingly, next(); its job is to move the iterator forward to the next position in the sequence. The example module can simply increment the position by one; more useful modules will do what is needed to step through some data structure. The next() function returns a new iterator, or NULL if the sequence is complete. Here's the example version: So if it returns NULL, we want to set err to 0 and break. Which is, um, exactly what the code does. Did you test this at all? > Signed-off-by: Vasyl Gomonovych > --- > fs/seq_file.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/seq_file.c b/fs/seq_file.c > index 4be761c..8b700b9 100644 > --- a/fs/seq_file.c > +++ b/fs/seq_file.c > @@ -262,8 +262,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) > size_t offs = m->count; > loff_t next = pos; > p = m->op->next(m, p, &next); > - if (!p || IS_ERR(p)) { > - err = PTR_ERR(p); > + if (IS_ERR(p)) { > + err = (!p ? -EFAULT : PTR_ERR(p)); > break; > } > err = m->op->show(m, p); > -- > 1.9.1 >