From: Kees Cook <kees@kernel.org>
To: Luis Chamberlain <mcgrof@kernel.org>
Cc: "Kees Cook" <kees@kernel.org>,
"Pengpeng Hou" <pengpeng@iscas.ac.cn>,
"Petr Pavlu" <petr.pavlu@suse.com>,
"Richard Weinberger" <richard@nod.at>,
"Anton Ivanov" <anton.ivanov@cambridgegreys.com>,
"Johannes Berg" <johannes@sipsolutions.net>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Len Brown" <lenb@kernel.org>,
"Corey Minyard" <corey@minyard.net>,
"Gabriel Somlo" <somlo@cmu.edu>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Tvrtko Ursulin" <tursulin@ursulin.net>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Bart Van Assche" <bvanassche@acm.org>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Leon Romanovsky" <leon@kernel.org>,
"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>,
"Hans de Goede" <hansg@kernel.org>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Hannes Reinecke" <hare@suse.de>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
"Daniel Lezcano" <daniel.lezcano@kernel.org>,
"Zhang Rui" <rui.zhang@intel.com>,
"Lukasz Luba" <lukasz.luba@arm.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Alan Stern" <stern@rowland.harvard.edu>,
"Jason Wang" <jasowang@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Jason Baron" <jbaron@akamai.com>,
"Jim Cromie" <jim.cromie@gmail.com>,
"Tiwei Bie" <tiwei.btw@antgroup.com>,
"Benjamin Berg" <benjamin.berg@intel.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"David E. Box" <david.e.box@linux.intel.com>,
"Maciej W. Rozycki" <macro@orcam.me.uk>,
"Srinivas Pandruvada" <srinivas.pandruvada@linux.intel.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Sean Christopherson" <seanjc@google.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Borislav Petkov" <bp@alien8.de>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
"Vinod Koul" <vkoul@kernel.org>, "Frank Li" <Frank.Li@kernel.org>,
"Daniel Gomez" <da.gomez@kernel.org>,
"Sami Tolvanen" <samitolvanen@google.com>,
"Aaron Tomlin" <atomlin@atomlin.com>,
"Alexander Potapenko" <glider@google.com>,
"Marco Elver" <elver@google.com>,
"Dmitry Vyukov" <dvyukov@google.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"John Johansen" <john.johansen@canonical.com>,
"Paul Moore" <paul@paul-moore.com>,
"James Morris" <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Georgia Garcia" <georgia.garcia@canonical.com>,
kvm@vger.kernel.org, dmaengine@vger.kernel.org,
linux-modules@vger.kernel.org, kasan-dev@googlegroups.com,
linux-mm@kvack.org, apparmor@lists.ubuntu.com,
linux-security-module@vger.kernel.org,
linux-um@lists.infradead.org, linux-acpi@vger.kernel.org,
openipmi-developer@lists.sourceforge.net, qemu-devel@nongnu.org,
intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-rdma@vger.kernel.org, linux-media@vger.kernel.org,
linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-pm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-serial@vger.kernel.org, linux-usb@vger.kernel.org,
usb-storage@lists.one-eyed-alien.net,
virtualization@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org, netdev@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: [PATCH 11/11] moduleparam: Drop legacy kernel_param_ops .get_str field and dispatch logic
Date: Thu, 21 May 2026 06:33:24 -0700 [thread overview]
Message-ID: <20260521133326.2465264-11-kees@kernel.org> (raw)
In-Reply-To: <20260521133315.work.845-kees@kernel.org>
All struct kernel_param_ops .get callbacks have been migrated to using
struct seq_buf. Drop the migration scaffolding.
Signed-off-by: Kees Cook <kees@kernel.org>
---
include/linux/moduleparam.h | 37 ++--------------------
kernel/params.c | 62 ++++++++++---------------------------
2 files changed, 20 insertions(+), 79 deletions(-)
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 38acb5aef56b..e6af6f051c93 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -66,15 +66,8 @@ struct kernel_param_ops {
/*
* Format the parameter's value into @s. Return 0 on success
* (length derived from seq_buf_used()) or -errno on error.
- * Exactly one of .get and .get_str should be set; the dispatcher
- * WARNs and prefers .get if both are.
*/
int (*get)(struct seq_buf *s, const struct kernel_param *kp);
- /*
- * Returns length written or -errno. Buffer is 4k (ie. be short!).
- * Deprecated: callbacks should implement .get instead.
- */
- int (*get_str)(char *buffer, const struct kernel_param *kp);
/* Optional function to free kp->arg when module unloaded. */
void (*free)(void *arg);
};
@@ -84,33 +77,11 @@ struct kernel_param_ops {
* any required visibility qualifiers (typically "static"):
*
* static DEFINE_KERNEL_PARAM_OPS(my_ops, my_set, my_get);
- *
- * @_get may be either of:
- * int (*)(struct seq_buf *, const struct kernel_param *) (seq_buf)
- * int (*)(char *, const struct kernel_param *) (legacy)
- *
- * The macro uses _Generic to route the function pointer to the
- * matching field (.get or .get_str) at compile time, leaving the
- * other field NULL. Each helper matches the wrong prototype signature
- * and returns NULL, falling through to the default branch otherwise;
- * if @_get has neither expected signature the assignment to the
- * fields gets a normal compile-time type-mismatch error.
*/
-#define _KERNEL_PARAM_OPS_GET(_get) \
- _Generic((_get), \
- int (*)(char *, const struct kernel_param *): NULL, \
- default: (_get))
-
-#define _KERNEL_PARAM_OPS_GET_STR(_get) \
- _Generic((_get), \
- int (*)(struct seq_buf *, const struct kernel_param *): NULL, \
- default: (_get))
-
#define DEFINE_KERNEL_PARAM_OPS(_name, _set, _get) \
const struct kernel_param_ops _name = { \
.set = (_set), \
- .get = _KERNEL_PARAM_OPS_GET(_get), \
- .get_str = _KERNEL_PARAM_OPS_GET_STR(_get), \
+ .get = (_get), \
}
/* As DEFINE_KERNEL_PARAM_OPS, with KERNEL_PARAM_OPS_FL_NOARG set. */
@@ -118,16 +89,14 @@ struct kernel_param_ops {
const struct kernel_param_ops _name = { \
.flags = KERNEL_PARAM_OPS_FL_NOARG, \
.set = (_set), \
- .get = _KERNEL_PARAM_OPS_GET(_get), \
- .get_str = _KERNEL_PARAM_OPS_GET_STR(_get), \
+ .get = (_get), \
}
/* As DEFINE_KERNEL_PARAM_OPS, with an additional .free callback. */
#define DEFINE_KERNEL_PARAM_OPS_FREE(_name, _set, _get, _free) \
const struct kernel_param_ops _name = { \
.set = (_set), \
- .get = _KERNEL_PARAM_OPS_GET(_get), \
- .get_str = _KERNEL_PARAM_OPS_GET_STR(_get), \
+ .get = (_get), \
.free = (_free), \
}
diff --git a/kernel/params.c b/kernel/params.c
index 25f0c8d5d19f..6b410189297b 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -461,8 +461,7 @@ static int param_array_get(struct seq_buf *s, const struct kernel_param *kp)
{
const struct kparam_array *arr = kp->arr;
struct kernel_param p = *kp;
- char *elem_buf = NULL;
- int i, ret = 0;
+ int i, ret;
for (i = 0; i < (arr->num ? *arr->num : arr->max); i++) {
size_t before = s->len;
@@ -470,23 +469,9 @@ static int param_array_get(struct seq_buf *s, const struct kernel_param *kp)
p.arg = arr->elem + arr->elemsize * i;
check_kparam_locked(p.mod);
- if (arr->ops->get) {
- ret = arr->ops->get(s, &p);
- if (ret < 0)
- goto out;
- } else {
- if (!elem_buf) {
- elem_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
- if (!elem_buf) {
- ret = -ENOMEM;
- goto out;
- }
- }
- ret = arr->ops->get_str(elem_buf, &p);
- if (ret < 0)
- goto out;
- seq_buf_putmem(s, elem_buf, ret);
- }
+ ret = arr->ops->get(s, &p);
+ if (ret < 0)
+ return ret;
/* Nothing got written (e.g. overflow) — stop. */
if (s->len == before)
@@ -496,10 +481,7 @@ static int param_array_get(struct seq_buf *s, const struct kernel_param *kp)
if (i && s->buffer[before - 1] == '\n')
s->buffer[before - 1] = ',';
}
- ret = 0;
-out:
- kfree(elem_buf);
- return ret;
+ return 0;
}
static void param_array_free(void *arg)
@@ -570,32 +552,22 @@ static ssize_t param_attr_show(const struct module_attribute *mattr,
int count;
const struct param_attribute *attribute = to_param_attr(mattr);
const struct kernel_param_ops *ops = attribute->param->ops;
+ struct seq_buf s;
- if (!ops->get && !ops->get_str)
+ if (!ops->get)
return -EPERM;
- WARN_ON_ONCE(ops->get && ops->get_str);
-
kernel_param_lock(mk->mod);
- if (ops->get) {
- struct seq_buf s;
-
- seq_buf_init(&s, buf, PAGE_SIZE);
- count = ops->get(&s, attribute->param);
- if (count >= 0) {
- WARN_ON_ONCE(count > 0);
- count = seq_buf_used(&s);
- /* Make sure string is terminated. */
- seq_buf_str(&s);
- /*
- * If overflowed, reduce count by 1 for trailing
- * NUL byte.
- */
- if (seq_buf_has_overflowed(&s))
- count--;
- }
- } else {
- count = ops->get_str(buf, attribute->param);
+ seq_buf_init(&s, buf, PAGE_SIZE);
+ count = ops->get(&s, attribute->param);
+ if (count >= 0) {
+ WARN_ON_ONCE(count > 0);
+ count = seq_buf_used(&s);
+ /* Make sure string is terminated. */
+ seq_buf_str(&s);
+ /* If overflowed, reduce count by 1 for trailing NUL byte. */
+ if (seq_buf_has_overflowed(&s))
+ count--;
}
kernel_param_unlock(mk->mod);
return count;
--
2.34.1
next prev parent reply other threads:[~2026-05-21 13:33 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-21 13:33 [PATCH 00/11] Convert moduleparams to seq_buf Kees Cook
2026-05-21 13:33 ` [PATCH 01/11] params: bound array element output to the caller's page buffer Kees Cook
2026-05-21 16:46 ` David Laight
2026-06-01 20:23 ` Matthew Wilcox
2026-06-02 11:26 ` Andy Shevchenko
2026-06-02 12:33 ` Jason Gunthorpe
2026-06-02 13:04 ` David Laight
2026-05-21 13:33 ` [PATCH 02/11] panic: Replace panic_print_get() with generic helper Kees Cook
2026-05-21 13:33 ` [PATCH 03/11] moduleparam: Add DEFINE_KERNEL_PARAM_OPS macro family Kees Cook
2026-05-25 13:27 ` Petr Pavlu
2026-05-21 13:33 ` [PATCH 04/11] treewide: Convert struct kernel_param_ops initializers to DEFINE_KERNEL_PARAM_OPS Kees Cook
2026-05-21 13:59 ` Sean Christopherson
2026-05-22 17:01 ` Rafael J. Wysocki
2026-05-23 0:38 ` SeongJae Park
2026-05-25 13:35 ` Petr Pavlu
2026-05-21 13:33 ` [PATCH 05/11] moduleparam: Rename .get field to .get_str Kees Cook
2026-05-30 0:45 ` sashiko-bot
2026-05-21 13:33 ` [PATCH 06/11] moduleparam: Add seq_buf-based .get callback alongside .get_str Kees Cook
2026-05-25 16:19 ` Petr Pavlu
2026-05-30 0:45 ` sashiko-bot
2026-05-21 13:33 ` [PATCH 07/11] moduleparam: Route DEFINE_KERNEL_PARAM_OPS get pointer via _Generic Kees Cook
2026-05-25 16:24 ` Petr Pavlu
2026-05-21 13:33 ` [PATCH 08/11] params: Convert generic kernel_param_ops .get helpers to seq_buf Kees Cook
2026-05-25 17:10 ` Petr Pavlu
2026-05-30 0:45 ` sashiko-bot
2026-05-21 13:33 ` [PATCH 09/11] treewide: Convert custom kernel_param_ops .get callbacks to seq_buf via cocci Kees Cook
2026-05-21 13:45 ` Sean Christopherson
2026-05-22 17:03 ` Rafael J. Wysocki
2026-05-23 0:45 ` SeongJae Park
2026-05-21 13:33 ` [PATCH 10/11] treewide: Manually convert custom kernel_param_ops .get callbacks Kees Cook
2026-05-21 17:44 ` Jani Nikula
2026-05-22 17:05 ` Rafael J. Wysocki
2026-05-21 13:33 ` Kees Cook [this message]
2026-05-30 0:46 ` [PATCH 11/11] moduleparam: Drop legacy kernel_param_ops .get_str field and dispatch logic sashiko-bot
2026-05-22 16:33 ` ✗ Fi.CI.BUILD: failure for Convert moduleparams to seq_buf Patchwork
2026-05-26 6:53 ` [PATCH 00/11] " Petr Pavlu
2026-06-01 19:59 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260521133326.2465264-11-kees@kernel.org \
--to=kees@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=anton.ivanov@cambridgegreys.com \
--cc=apparmor@lists.ubuntu.com \
--cc=atomlin@atomlin.com \
--cc=benjamin.berg@intel.com \
--cc=bhelgaas@google.com \
--cc=bp@alien8.de \
--cc=bvanassche@acm.org \
--cc=corey@minyard.net \
--cc=da.gomez@kernel.org \
--cc=daniel.lezcano@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=david.e.box@linux.intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=eperezma@redhat.com \
--cc=georgia.garcia@canonical.com \
--cc=glider@google.com \
--cc=gor@linux.ibm.com \
--cc=gregkh@linuxfoundation.org \
--cc=hansg@kernel.org \
--cc=hare@suse.de \
--cc=hca@linux.ibm.com \
--cc=hpa@zytor.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=jasowang@redhat.com \
--cc=jbaron@akamai.com \
--cc=jgg@ziepe.ca \
--cc=jim.cromie@gmail.com \
--cc=jirislaby@kernel.org \
--cc=jmorris@namei.org \
--cc=johannes@sipsolutions.net \
--cc=john.johansen@canonical.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kasan-dev@googlegroups.com \
--cc=kvm@vger.kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=lenb@kernel.org \
--cc=leon@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-modules@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=linux-usb@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=lukasz.luba@arm.com \
--cc=macro@orcam.me.uk \
--cc=martin.petersen@oracle.com \
--cc=mcgrof@kernel.org \
--cc=mchehab@kernel.org \
--cc=mingo@redhat.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=openipmi-developer@lists.sourceforge.net \
--cc=paul@paul-moore.com \
--cc=pbonzini@redhat.com \
--cc=pengpeng@iscas.ac.cn \
--cc=peterz@infradead.org \
--cc=petr.pavlu@suse.com \
--cc=qemu-devel@nongnu.org \
--cc=rafael@kernel.org \
--cc=richard@nod.at \
--cc=rodrigo.vivi@intel.com \
--cc=rui.zhang@intel.com \
--cc=samitolvanen@google.com \
--cc=seanjc@google.com \
--cc=serge@hallyn.com \
--cc=simona@ffwll.ch \
--cc=somlo@cmu.edu \
--cc=srinivas.pandruvada@linux.intel.com \
--cc=stern@rowland.harvard.edu \
--cc=tglx@kernel.org \
--cc=tiwei.btw@antgroup.com \
--cc=tursulin@ursulin.net \
--cc=usb-storage@lists.one-eyed-alien.net \
--cc=virtualization@lists.linux.dev \
--cc=vkoul@kernel.org \
--cc=x86@kernel.org \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.