From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com ([134.134.136.24]:46596 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751066AbcHWJck (ORCPT ); Tue, 23 Aug 2016 05:32:40 -0400 From: Tomasz Majchrzak To: linux-fsdevel@vger.kernel.org Cc: aleksey.obitotskiy@intel.com, pawel.baldysiak@intel.com, artur.paszkiewicz@intel.com, maksymilian.kunt@intel.com Subject: [PATCH] seq_file: don't set read position for invalid iterator Date: Tue, 23 Aug 2016 11:19:37 +0200 Message-Id: <1471943977-17822-1-git-send-email-tomasz.majchrzak@intel.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: If kernfs file is empty on a first read, successive read operations using the same file descriptor will return no data, even when data is available. Default kernfs 'seq_next' implementation advances iterator position even when next object is not there. Kernfs 'seq_start' for following requests will not return iterator as position is already on the second object. Don't set read position if valid iterator has not been returned. Signed-off-by: Tomasz Majchrzak --- fs/seq_file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index 19f532e..893db43 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -242,7 +242,8 @@ 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, &pos); - m->index = pos; + if (p && !IS_ERR(p)) + m->index = pos; continue; } if (m->count < m->size) -- 1.8.3.1