From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752708AbcGAJ3T (ORCPT ); Fri, 1 Jul 2016 05:29:19 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35115 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752205AbcGAJ3R (ORCPT ); Fri, 1 Jul 2016 05:29:17 -0400 From: Tal Shorer To: jlbec@evilplan.org, hch@lst.de, linux-kernel@vger.kernel.org Cc: Tal Shorer Subject: [PATCH] fs: configfs: don't set buffer_needs_fill to zero if show() returns error Date: Fri, 1 Jul 2016 12:28:57 +0300 Message-Id: <1467365337-6712-1-git-send-email-tal.shorer@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20160630093232.GA9287@lst.de> References: <20160630093232.GA9287@lst.de> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A confgifs attribute's show() callback is called once the first time the user attempts to read from it. If it returns an error, that error is returned to the user. However, the open file's buffer_needs_fill is still set to zero and consecutive read() calls will find an empty buffer that doesn't need filling and return 0 to the user. This could give the user the wrong impression that the attribute was read successfully. Fix this by not setting buffer_needs_fill if show() returns an error, making consecutive read() calls call show() again and either get an error again or get data. Signed-off-by: Tal Shorer --- fs/configfs/file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/configfs/file.c b/fs/configfs/file.c index 33b7ee3..68645c9 100644 --- a/fs/configfs/file.c +++ b/fs/configfs/file.c @@ -80,11 +80,11 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * buf count = attr->show(item, buffer->page); - buffer->needs_read_fill = 0; BUG_ON(count > (ssize_t)SIMPLE_ATTR_SIZE); - if (count >= 0) + if (count >= 0) { + buffer->needs_read_fill = 0; buffer->count = count; - else + } else ret = count; return ret; } -- 2.7.4