Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752052AbbEDWUB (ORCPT ); Mon, 4 May 2015 18:20:01 -0400 Received: from smtp3-g21.free.fr ([212.27.42.3]:4354 "EHLO smtp3-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751753AbbEDWTg (ORCPT ); Mon, 4 May 2015 18:19:36 -0400 From: Yann Droneaud To: Al Viro Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Yann Droneaud Subject: [PATCH 2/3] fs: allocate structure unconditionally in seq_open() Date: Tue, 5 May 2015 00:19:14 +0200 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2012 Lines: 64 Since following commit, from v2.6.15-rc1, seq_open() could use a struct seq_file already allocated by the caller if the pointer to the structure is stored in file->private_data before calling the function. Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05 Author: Al Viro Date: Mon Nov 7 17:15:34 2005 -0500 [PATCH] allow callers of seq_open do allocation themselves Allow caller of seq_open() to kmalloc() seq_file + whatever else they want and set ->private_data to it. seq_open() will then abstain from doing allocation itself. As there's no more use for such feature, as it could be easily replaced by calls to seq_open_private(), see commit 39699037a5c9 ("[FS] seq_file: Introduce the seq_open_private()") and seq_release_private(), see v2.6.0-test3, support for this uncommon feature can be removed from seq_open(). Link: http://lkml.kernel.org/r/cover.1430777196.git.ydroneaud@opteya.com Signed-off-by: Yann Droneaud --- fs/seq_file.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index 555f82155be8..cb9c3dbd1a1e 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -51,14 +51,16 @@ static void *seq_buf_alloc(unsigned long size) */ int seq_open(struct file *file, const struct seq_operations *op) { - struct seq_file *p = file->private_data; + struct seq_file *p; + + WARN_ON(file->private_data); + + p = kmalloc(sizeof(*p), GFP_KERNEL); + if (!p) + return -ENOMEM; + + file->private_data = p; - if (!p) { - p = kmalloc(sizeof(*p), GFP_KERNEL); - if (!p) - return -ENOMEM; - file->private_data = p; - } memset(p, 0, sizeof(*p)); mutex_init(&p->lock); p->op = op; -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/