From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85E9E6078C67 for ; Wed, 4 Nov 2026 19:32:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cTuaWM9d Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4jKbDq21CYz308j; Thu, 05 Nov 2026 06:32:27 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=172.105.4.254 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1793820747; cv=none; b=bWQSyfa0DYYavVVICGKlTJgHk7MPl6/f2YioohoqDSua6AK8/gEeUjF3BySto3rK3SqnxBBI9eS1wUY0nJdxApBPps6gCLvm/6MpfPuvPCO6Z8vNjLp53t5RC0bdshNGg6uYrDLkzxZDPjXRaSRFRnA/bn54oQv82M/vE9VjtugQUrZRDDsJAiTl+iADZXv1FYbCaTf7+/qx0wcYeipmePJvhtX785WXefZElyY+0Qf5V+03DIFFDxsTNdTPiy7eYEGZiPtCgU6Hi3S60x/0lJdZzRsibSSlJux2RlHBRbBiYmXApTFGLHBXWnzYf6A+eN7LiWvrNH+N2wNU4bgfzg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1793820747; c=relaxed/relaxed; bh=t7CXhIggcklIY3xO5IiO5lA9eZblBCQpzIpV4iqWwIs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FeDiKiIf9nBiHohp4LvDPdyCjlFdH3mfvkdBPlAGjeNQ3Fcd36jINWRglspc6TcgaCEKYJcf3WP17wndfu9dEf2hcitbv2uA6le778gqvIH3VGPrCqzcj86q4+eOoVDXWiSYsIs22FGLPGg7VRq818E3eDq56Is4Mys0xs96OhIyUWZrs2kdADRoeb2KB5DSEXh/vx1m4GtOw12YKuFJJoWnuowVddP3U3WMk/Xe/z7mif0g8d+InA8HDAWFy3g+OU6vyvk3gd1m+/G2xgonOUsaHxBEIRU8aToE/1FTVqjRwN1GxIp1NbkusR4ftrPc0RR5ZyKV4Btd5YjTfu/ogA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cTuaWM9d; dkim-atps=neutral; spf=pass (client-ip=172.105.4.254; helo=tor.source.kernel.org; envelope-from=brauner@kernel.org; receiver=lists.ozlabs.org) smtp.mailfrom=kernel.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cTuaWM9d; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=172.105.4.254; helo=tor.source.kernel.org; envelope-from=brauner@kernel.org; receiver=lists.ozlabs.org) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4jKbDp3F2dz3048 for ; Thu, 05 Nov 2026 06:32:26 +1100 (AEDT) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 8C89E60D9F; Wed, 4 Nov 2026 19:32:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A89F31F00919; Wed, 4 Nov 2026 19:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793820744; bh=t7CXhIggcklIY3xO5IiO5lA9eZblBCQpzIpV4iqWwIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cTuaWM9d7bmS3BQXsgtTAPR9uVh6iO0s1VUb1qW5xthyjwQ7vxJulOEZ629mv/ktX 8pc572eXrayXIbCxFRUJIEYHlf9ycJZjdr5EilMv+/yNyQNPgE7IbTr67SmbjqGKon wQxWa1oDi8Z96DmUhmEkZsLKgf7TxOqe0u+yeHEa9M+VTfdbUwRpShdZhtLt7n6wLd xG8ZPgiEEG146zAmYMMPTfNZP+A5FSPLxTvy8HupirTDlyG6AokYQO4fF7KBnvln4/ BccNNTsARBWlIFPDpemmx+BLFNPVItSM8w4MnywAOEfXW90hS1vRbBdoScA6JM7MiN 65ED+/q2glmuQ== From: Christian Brauner To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Jann Horn , Josef Bacik , Chris Mason , Jeff Layton , NeilBrown , Eric Dumazet , Thomas Gleixner , Al Viro , Jonathan Corbet , Christoph Hellwig , Greg Kroah-Hartman , Joel Granados , Kees Cook , Jan Kara , Jan Kara , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-um@lists.infradead.org, linux-wireless@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org, ntfs3@lists.linux.dev, platform-driver-x86@vger.kernel.org, coreteam@netfilter.org, kexec@lists.infradead.org, linux-pci@vger.kernel.org, linux-sound@vger.kernel.org, netfilter-devel@vger.kernel.org, dri-devel@lists.freedesktop.org, ibm-acpi-devel@lists.sourceforge.net, jfs-discussion@lists.sourceforge.net, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-cifs@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-mm@kvack.org, linux-sh@vger.kernel.org, linux-usb@vger.kernel.org, samba-technical@lists.samba.org, sparclinux@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-doc@vger.kernel.org, linux-serial@vger.kernel.org, linux-atm-general@lists.sourceforge.net, Takashi Iwai , linux-input@vger.kernel.org, linux-raid@vger.kernel.org, linux-ext4@vger.kernel.org, linux-modules@vger.kernel.org, linux-debuggers@vger.kernel.org, "Christian Brauner (Amutable)" , Chuck Lever Subject: [PATCH RESEND v2 12/23] seq_file: add seq_preallocate() Date: Wed, 4 Nov 2026 20:32:10 +0100 Message-ID: <20261104-work-procfs-core-v2-12-76ace653a773@kernel.org> In-Reply-To: <20261104-work-procfs-core-v2-0-76ace653a773@kernel.org> References: <20261104-work-procfs-core-v2-0-76ace653a773@kernel.org> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , Precedence: list X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2744; i=brauner@kernel.org; h=from:subject:message-id; bh=cArC7PPeLGnNNo4k1qcZwNiSGSA+jlDCNRnIKXcvzj8=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWS9bq9fUy53Y+meKbNe5Zf78F+aKHlY58q16usqyqJv3 +V2rX5U0FHKwiDGxSArpsji0G4SLrecp2KzUaYGzBxWJpAhDFycAjAR+1yG/3HL357Tm/j6pbNY 7t1vOYdrHYtOvFVkdFthFzlPc30mlyDDP53w+qwZtmFzcn4YvJ2TMYtvgYrB74l+jyOkXn9YOXn VaS4A X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 single_open_size() allocates the buffer itself because it does the single_open() too. A file whose seq_file is opened by somebody else, like procfs does now, needs to do that after the fact. Add seq_preallocate() for that and use it in single_open_size(). No functional changes. Signed-off-by: Christian Brauner (Amutable) --- fs/seq_file.c | 36 ++++++++++++++++++++++++++++-------- include/linux/seq_file.h | 1 + 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index 456c78719fd0..a4644cdda7e6 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -590,21 +590,41 @@ int single_open(struct file *file, int (*show)(struct seq_file *, void *), } EXPORT_SYMBOL(single_open); -int single_open_size(struct file *file, int (*show)(struct seq_file *, void *), - void *data, size_t size) +/** + * seq_preallocate - start out with a buffer of @size + * @m: the seq_file, before it is first read + * @size: the size of the buffer + * + * For files whose records don't fit into a page, so that the first read + * doesn't have to work its way up to the right buffer size. + */ +int seq_preallocate(struct seq_file *m, size_t size) { char *buf = seq_buf_alloc(size); - int ret; + if (!buf) return -ENOMEM; + kvfree(m->buf); + m->buf = buf; + m->size = size; + return 0; +} +EXPORT_SYMBOL(seq_preallocate); + +int single_open_size(struct file *file, int (*show)(struct seq_file *, void *), + void *data, size_t size) +{ + int ret; + ret = single_open(file, show, data); - if (ret) { - kvfree(buf); + if (ret) return ret; + ret = seq_preallocate(file->private_data, size); + if (ret) { + single_release(file_inode(file), file); + file->private_data = NULL; } - ((struct seq_file *)file->private_data)->buf = buf; - ((struct seq_file *)file->private_data)->size = size; - return 0; + return ret; } EXPORT_SYMBOL(single_open_size); diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index b813b7e63d89..834daff48b7d 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -175,6 +175,7 @@ int seq_path_root(struct seq_file *m, const struct path *path, void *single_start(struct seq_file *, loff_t *); int single_open(struct file *, int (*)(struct seq_file *, void *), void *); int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t); +int seq_preallocate(struct seq_file *m, size_t size); int single_release(struct inode *, struct file *); void *__seq_open_private(struct file *, const struct seq_operations *, int); int seq_open_private(struct file *, const struct seq_operations *, int); -- 2.53.0