From patchwork Mon Jun 1 21:32:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yann Droneaud X-Patchwork-Id: 6524791 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BDD749F1CC for ; Mon, 1 Jun 2015 21:33:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DCBF120460 for ; Mon, 1 Jun 2015 21:33:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 060C62045E for ; Mon, 1 Jun 2015 21:33:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753686AbbFAVdW (ORCPT ); Mon, 1 Jun 2015 17:33:22 -0400 Received: from smtp4-g21.free.fr ([212.27.42.4]:23686 "EHLO smtp4-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754052AbbFAVcf (ORCPT ); Mon, 1 Jun 2015 17:32:35 -0400 Received: from localhost.localdomain (unknown [IPv6:2a01:e35:2e9f:6ac0:684c:e451:65d7:ebf6]) by smtp4-g21.free.fr (Postfix) with ESMTPS id CE1F74C8029; Mon, 1 Jun 2015 23:28:29 +0200 (CEST) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.15.1/8.14.8) with ESMTP id t51LWSxQ032331; Mon, 1 Jun 2015 23:32:28 +0200 Received: (from ydroneaud@localhost) by localhost.localdomain (8.15.1/8.15.1/Submit) id t51LWScH032330; Mon, 1 Jun 2015 23:32:28 +0200 From: Yann Droneaud To: Al Viro , Andrew Morton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Yann Droneaud Subject: [PATCH v1 2/3] fs: allocate structure unconditionally in seq_open() Date: Mon, 1 Jun 2015 23:32:14 +0200 Message-Id: <14d8ee37ef4423dea354256598f22250fba3e7ab.1433193673.git.ydroneaud@opteya.com> X-Mailer: git-send-email 2.4.2 In-Reply-To: References: In-Reply-To: References: Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since patch described below, 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.1433193673.git.ydroneaud@opteya.com Signed-off-by: Yann Droneaud --- fs/seq_file.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index c14f6a43beb5..a909f12dad4d 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -51,15 +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 = kzalloc(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; #ifdef CONFIG_USER_NS