From patchwork Tue Aug 23 09:19:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Majchrzak X-Patchwork-Id: 9295341 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 26EF3607D0 for ; Tue, 23 Aug 2016 09:34:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1696B28B5B for ; Tue, 23 Aug 2016 09:34:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 094C128B92; Tue, 23 Aug 2016 09:34:15 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8370828B5B for ; Tue, 23 Aug 2016 09:34:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754998AbcHWJdn (ORCPT ); Tue, 23 Aug 2016 05:33:43 -0400 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 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 23 Aug 2016 02:20:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,565,1464678000"; d="scan'208";a="752378985" Received: from gklab-102-100.igk.intel.com (HELO proton.igk.intel.com) ([10.102.102.100]) by FMSMGA003.fm.intel.com with ESMTP; 23 Aug 2016 02:20:24 -0700 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> X-Mailer: git-send-email 1.8.3.1 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Dan Williams --- 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)