From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793632652; b=fjrf76wuIK2QcuM78mDCueD1+jN8Qq6sJdiv19ArCRLjpydnHu3Q3bPMO3NA0FA4arzV UyI8/auRQlqfbOqjN/w1cJORJkYtvl2x7LOkTrqUbMHRgzqGGeFMpDvbG0tmQ+EbtcpMo H3PmNhP/M+Lrbkfo5gLwhW3yBWKxzRkBU+3f7NA5XVX5N3Mu6HrgxvnQTXJGzq4vYABFt fBIdJZIVRjm++FapLjWIOAIprIapEmSv7nsaFl3RzXW9xWOvc+EqyUkxP30zvhhF6amGQ 0ktJaMqWNx6tmHvxWs1iVQy7FGCrlaF2hvMqSGSILeG2W/tjV6bp86+JPkD24oCKfuA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793632652; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=S8BhauG/lP2s9np5J0R1zzems7E8P5CDYFcbPs7MISk=; b=K0+b4Zzk1cKCHIeXab6CdabG6f7Gl+tfkzwLrCNMYCwuNuXjk0E4qaeSJXyW9kbDO6yU 6XjBNRrwCq8OOXk+g9ohTWd5/4IJaovo1fyLLMFk4uZi/mK+F/j686BG/4nL4zgk7Opuu +1CZ3sRk2E8aTq2wYS5lA0hf4ZmcTUJ6Uqi7UarpqnTiC9SC1AXDbBn33uMloQlvD2Vpm KdEiyaPzM4rv96sMsGp93FzoCpnc3lS3IWvEvucCEu/wu7TD0xjyjIOSyRXPdVInoO6Kb 0oyTOO5yEJG8xixgJN0zAmUk/GwnvHMwybTjGTwdvYPE/fYhde5TlNxODNSA+4Dj1DA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B6cTTm4Y; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (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 6E350606F207; Mon, 2 Nov 2026 15:17:32 +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=B6cTTm4Y Received: by smtp.kernel.org (Postfix) with ESMTPSA id 367381F00A16; Mon, 2 Nov 2026 15:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793632651; bh=S8BhauG/lP2s9np5J0R1zzems7E8P5CDYFcbPs7MISk=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=B6cTTm4Y/wdooL+ApfO/HX/ZDcHy871M+X9n7WkLV4Na54VVI8Ta+GbpUioF3ohSU HHQo9Jkcew+x0HR14YfLduB3vudFo6GZ0wfYcfe7ffo/MAUQIiTmuM8ZFUOm9Sg5hr 9kkUsh2Q8m4eaiyTGh20A2ag1ZbWNy43odsaE3VIqiomPZmHmYzMxoNcG2FL1hoMLH 78N6Ik+BUAAl1xtmFBWvurEQT0AERbrvBCCfciM03MgEELv6G4mkS4ovaRu4ohxvyl 4wGuLeQtigGuCLneFLcOpa6Ayv00b+mXvCWgBazmSkXDaCma8Dt3CVFcCwkH1dWK1q 5bg3vsSIrSD6g== From: Christian Brauner Date: Mon, 02 Nov 2026 16:07:28 +0100 Subject: [PATCH RFC 21/23] ALSA: info: let procfs copy in writes X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261102-work-procfs-drivers-v1-21-a994bd4d3b1a@kernel.org> References: <20261102-work-procfs-drivers-v1-0-a994bd4d3b1a@kernel.org> In-Reply-To: <20261102-work-procfs-drivers-v1-0-a994bd4d3b1a@kernel.org> 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 X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4905; i=brauner@kernel.org; h=from:subject:message-id; bh=LuuwL6UJ7KGtrckYm3Uj4kQJlkSBUwRuOX3mF2sG+Yw=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWS9WG6o6D7rw7X6A5dqbtx35bCpa3Q+EXL87IJ3SqrHA 5Yqn/zyo6OUhUGMi0FWTJHFod0kXG45T8Vmo0wNmDmsTCBDGLg4BWAiLfMZGVr3H8tc/DUgTOey t8qOf6wHdFd+DO0+5PpnP8fEQrsrMdMYGfY2374+1XfmNYM73p/uJBzp37b9zN94sbn1Hn7frnz n+s8BAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Implement ->proc_write_buf() for data and text entries so procfs copies in what is written before it pins the entry. Data entries take writes a page at a time with PROC_ENTRY_SHORT_WRITES. They used to get the whole write at once. ->write() of struct snd_info_entry_ops gets the kernel copy and opl4, its only user, writes it to the sample memory without bouncing it through a vmalloc() buffer of its own. Text entries take up to SND_INFO_TEXT_WRITE_MAX bytes at once like before. A single write that is larger fails with -EINVAL from procfs instead of -EIO now. Signed-off-by: Christian Brauner (Amutable) --- include/sound/info.h | 2 +- sound/core/info.c | 21 ++++++++++++--------- sound/drivers/opl4/opl4_proc.c | 11 +---------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/include/sound/info.h b/include/sound/info.h index adbc506860d6..32fc608d056c 100644 --- a/include/sound/info.h +++ b/include/sound/info.h @@ -42,7 +42,7 @@ struct snd_info_entry_ops { struct file *file, char __user *buf, size_t count, loff_t pos); ssize_t (*write)(struct snd_info_entry *entry, void *file_private_data, - struct file *file, const char __user *buf, + struct file *file, const char *buf, size_t count, loff_t pos); loff_t (*llseek)(struct snd_info_entry *entry, void *file_private_data, struct file *file, diff --git a/sound/core/info.c b/sound/core/info.c index 8f905f398a0d..09d4420202e5 100644 --- a/sound/core/info.c +++ b/sound/core/info.c @@ -160,7 +160,7 @@ static ssize_t snd_info_entry_read(struct file *file, char __user *buffer, return size; } -static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer, +static ssize_t snd_info_entry_write(struct file *file, char *buffer, size_t count, loff_t * offset) { struct snd_info_private_data *data = file->private_data; @@ -277,9 +277,11 @@ static int snd_info_entry_release(struct inode *inode, struct file *file) static const struct proc_ops snd_info_entry_operations = { + .proc_flags = PROC_ENTRY_SHORT_WRITES, .proc_lseek = snd_info_entry_llseek, .proc_read = snd_info_entry_read, - .proc_write = snd_info_entry_write, + .proc_write_buf = snd_info_entry_write, + .proc_write_size = PAGE_SIZE, .proc_poll = snd_info_entry_poll, .proc_ioctl = snd_info_entry_ioctl, .proc_mmap = snd_info_entry_mmap, @@ -287,11 +289,13 @@ static const struct proc_ops snd_info_entry_operations = .proc_release = snd_info_entry_release, }; +/* don't handle too large text inputs */ +#define SND_INFO_TEXT_WRITE_MAX (16 * 1024) + /* * file ops for text proc files */ -static ssize_t snd_info_text_entry_write(struct file *file, - const char __user *buffer, +static ssize_t snd_info_text_entry_write(struct file *file, char *buffer, size_t count, loff_t *offset) { struct seq_file *m = file->private_data; @@ -307,8 +311,7 @@ static ssize_t snd_info_text_entry_write(struct file *file, if (!valid_pos(pos, count)) return -EIO; next = pos + count; - /* don't handle too large text inputs */ - if (next > 16 * 1024) + if (next > SND_INFO_TEXT_WRITE_MAX) return -EIO; guard(mutex)(&entry->access); buf = data->wbuffer; @@ -325,8 +328,7 @@ static ssize_t snd_info_text_entry_write(struct file *file, buf->buffer = nbuf; buf->len = PAGE_ALIGN(next); } - if (copy_from_user(buf->buffer + pos, buffer, count)) - return -EFAULT; + memcpy(buf->buffer + pos, buffer, count); buf->size = next; *offset = next; return count; @@ -404,7 +406,8 @@ static const struct proc_ops snd_info_text_entry_ops = .proc_show = snd_info_seq_show, .proc_open = snd_info_text_entry_open, .proc_release = snd_info_text_entry_release, - .proc_write = snd_info_text_entry_write, + .proc_write_buf = snd_info_text_entry_write, + .proc_write_size = SND_INFO_TEXT_WRITE_MAX, }; static struct snd_info_entry *create_subdir(struct module *mod, diff --git a/sound/drivers/opl4/opl4_proc.c b/sound/drivers/opl4/opl4_proc.c index fd0ba4704d9f..bdcae02a4dc2 100644 --- a/sound/drivers/opl4/opl4_proc.c +++ b/sound/drivers/opl4/opl4_proc.c @@ -54,21 +54,12 @@ static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry, static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry, void *file_private_data, struct file *file, - const char __user *_buf, + const char *buf, size_t count, loff_t pos) { struct snd_opl4 *opl4 = entry->private_data; - char *buf; - buf = vmalloc(count); - if (!buf) - return -ENOMEM; - if (copy_from_user(buf, _buf, count)) { - vfree(buf); - return -EFAULT; - } snd_opl4_write_memory(opl4, buf, pos, count); - vfree(buf); return count; } -- 2.53.0