Convert moduleparams to seq_buf
Subsystems (104)
Kees Cook
maintainercover Convert moduleparams to seq_buf
Hi,
I tried to trim the CC list here, but it's still pretty huge...
We've had a long-standing issue with "write to a string pointer" callbacks that don't bounds check the destination (and for which the bounds is also not part of the callback prototype, even if it is "known" to be PAGE_SIZE, which sysfs_emit() depends on). Both moduleparams and sysfs use this pattern. As a first step, and to test the migration method, migrate moduleparams first.
There are 2 "mechanical" treewide patches that are handled by Coccinelle:
- treewide: Convert struct kernel_param_ops initializers to DEFINE_KERNEL_PARAM_OPS
- treewide: Convert custom kernel_param_ops .get callbacks to seq_buf via cocci
The last treewide patch is manual, and may need to be broken up into per-subsystem patches, though I'd prefer to avoid this, as it would extend the migration from 1 relase to at least 2 releases. (1 to release the migration infrastructure, then 1 release to collect all the subsystem changes, and possibly 1 more release to remove the migration infrastructure.)
Thoughts, questions?
-Kees
Kees Cook (10):
panic: Replace panic_print_get() with generic helper
moduleparam: Add DEFINE_KERNEL_PARAM_OPS macro family
treewide: Convert struct kernel_param_ops initializers to
DEFINE_KERNEL_PARAM_OPS
moduleparam: Rename .get field to .get_str
moduleparam: Add seq_buf-based .get callback alongside .get_str
moduleparam: Route DEFINE_KERNEL_PARAM_OPS get pointer via _Generic
params: Convert generic kernel_param_ops .get helpers to seq_buf
treewide: Convert custom kernel_param_ops .get callbacks to seq_buf
via cocci
treewide: Manually convert custom kernel_param_ops .get callbacks
moduleparam: Drop legacy kernel_param_ops .get_str field and dispatch
logic
Pengpeng Hou (1):
params: bound array element output to the caller's page buffer
include/linux/dynamic_debug.h | 8 +- include/linux/moduleparam.h | 65 +++++++--- security/apparmor/include/lib.h | 3 +- mm/kfence/core.c | 15 ++- arch/powerpc/kvm/book3s_hv.c | 5 +- arch/s390/kernel/perf_cpum_sf.c | 12 +- arch/um/drivers/vfio_kern.c | 9 +- arch/um/drivers/virtio_uml.c | 18 +-- arch/x86/kernel/msr.c | 11 +- arch/x86/kvm/mmu/mmu.c | 28 ++-- arch/x86/kvm/svm/avic.c | 14 +- arch/x86/kvm/vmx/vmx.c | 24 ++-- arch/x86/platform/uv/uv_nmi.c | 24 ++-- block/disk-events.c | 6 +- drivers/acpi/button.c | 19 ++- drivers/acpi/ec.c | 14 +- drivers/acpi/sysfs.c | 114 ++++++++-------- drivers/block/loop.c | 12 +- drivers/block/null_blk/main.c | 12 +- drivers/block/rnbd/rnbd-srv.c | 6 +- drivers/block/ublk_drv.c | 12 +- drivers/char/ipmi/ipmi_msghandler.c | 12 +- drivers/char/ipmi/ipmi_watchdog.c | 50 +++---- drivers/crypto/hisilicon/hpre/hpre_main.c | 16 +-- drivers/crypto/hisilicon/sec2/sec_main.c | 23 +--- drivers/crypto/hisilicon/zip/zip_crypto.c | 5 +- drivers/crypto/hisilicon/zip/zip_main.c | 21 +-- drivers/dma/dmatest.c | 34 ++--- drivers/edac/i10nm_base.c | 6 +- drivers/firmware/efi/efi-pstore.c | 6 +- drivers/firmware/qcom/qcom_scm.c | 18 +-- drivers/firmware/qemu_fw_cfg.c | 40 +++--- drivers/gpu/drm/drm_panic.c | 13 +- drivers/gpu/drm/i915/i915_mitigations.c | 31 ++--- drivers/gpu/drm/imagination/pvr_fw_trace.c | 6 +- drivers/hid/hid-cougar.c | 6 +- drivers/hid/hid-steam.c | 6 +- drivers/infiniband/hw/hfi1/driver.c | 12 +- drivers/infiniband/ulp/iser/iscsi_iser.c | 6 +- drivers/infiniband/ulp/isert/ib_isert.c | 6 +- drivers/infiniband/ulp/srp/ib_srp.c | 12 +- drivers/infiniband/ulp/srpt/ib_srpt.c | 5 +- drivers/input/misc/ati_remote2.c | 23 ++-- drivers/input/mouse/psmouse-base.c | 15 ++- drivers/md/md.c | 5 +- drivers/media/pci/tw686x/tw686x-core.c | 6 +- drivers/media/usb/uvc/uvc_driver.c | 14 +- drivers/misc/lis3lv02d/lis3lv02d.c | 5 +- drivers/net/wireless/ath/wil6210/main.c | 10 +- drivers/nvme/host/multipath.c | 17 +-- drivers/nvme/host/pci.c | 18 +-- drivers/nvme/target/rdma.c | 5 +- drivers/nvme/target/tcp.c | 5 +- drivers/pci/pcie/aspm.c | 17 ++- drivers/platform/x86/acerhdf.c | 5 +- drivers/power/supply/bq27xxx_battery.c | 6 +- drivers/power/supply/test_power.c | 122 +++++++++--------- drivers/scsi/fcoe/fcoe_transport.c | 22 ++-- drivers/scsi/sg.c | 6 +- drivers/target/target_core_user.c | 25 ++-- .../processor_thermal_soc_slider.c | 24 ++-- drivers/thermal/intel/intel_powerclamp.c | 34 ++--- drivers/tty/hvc/hvc_iucv.c | 24 ++-- drivers/tty/sysrq.c | 6 +- drivers/ufs/core/ufs-fault-injection.c | 12 +- drivers/ufs/core/ufs-mcq.c | 18 +-- drivers/ufs/core/ufs-txeq.c | 5 +- drivers/ufs/core/ufshcd.c | 12 +- drivers/usb/core/quirks.c | 6 +- drivers/usb/gadget/legacy/serial.c | 5 +- drivers/usb/storage/usb.c | 25 ++-- drivers/vhost/scsi.c | 12 +- drivers/virt/nitro_enclaves/ne_misc_dev.c | 6 +- drivers/virtio/virtio_mmio.c | 27 ++-- fs/ceph/super.c | 10 +- fs/fuse/dir.c | 5 +- fs/nfs/namespace.c | 12 +- fs/nfs/super.c | 6 +- fs/ocfs2/dlmfs/dlmfs.c | 5 +- fs/overlayfs/copy_up.c | 5 +- fs/ubifs/super.c | 6 +- kernel/locking/locktorture.c | 12 +- kernel/panic.c | 11 +- kernel/params.c | 122 +++++++++--------- kernel/power/hibernate.c | 6 +- kernel/rcu/tree.c | 24 ++-- kernel/sched/ext.c | 11 +- kernel/workqueue.c | 18 ++- lib/dynamic_debug.c | 16 ++- lib/test_dynamic_debug.c | 12 +- mm/damon/lru_sort.c | 33 +++-- mm/damon/reclaim.c | 33 +++-- mm/damon/stat.c | 16 +-- mm/memory_hotplug.c | 30 +++-- mm/page_reporting.c | 11 +- mm/shuffle.c | 6 +- mm/zswap.c | 14 +- net/batman-adv/bat_algo.c | 6 +- net/ceph/ceph_common.c | 10 +- net/ipv4/tcp_dctcp.c | 6 +- net/sunrpc/auth.c | 12 +- net/sunrpc/svc.c | 5 +- net/sunrpc/xprtsock.c | 18 +-- samples/damon/mtier.c | 6 +- samples/damon/prcl.c | 6 +- samples/damon/wsse.c | 6 +- security/apparmor/lib.c | 27 ++-- security/apparmor/lsm.c | 75 +++++------ sound/hda/controllers/intel.c | 5 +- sound/usb/card.c | 7 +- 110 files changed, 854 insertions(+), 1066 deletions(-)
Signature · 1 line
2.34.1
Kees Cook
maintainerPATCH 1/11 params: bound array element output to the caller's page buffer
From: Pengpeng Hou <[email protected]>
param_array_get() appends each element's string representation into the shared sysfs page buffer by passing buffer + off to the element getter.
That works for getters that only write a small bounded string, but param_get_charp() and similar helpers format against PAGE_SIZE from the pointer they receive. Once off is non-zero, an element getter can therefore write past the end of the original sysfs page buffer.
Collect each element into a temporary PAGE_SIZE buffer first and then copy only the remaining space into the caller's page buffer.
--- kernel/params.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
kernel/params.c +20 -6
@@ -475,22 +475,36 @@ static int param_array_set(const char *val, const struct kernel_param *kp)static int param_array_get (char *buffer,const struct kernel_param *kp) {int i, off, ret; +char *elem_buf;const struct kparam_array *arr = kp->arr;struct kernel_param p = *kp; + elem_buf =kmalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!elem_buf) +return -ENOMEM ; +for (i = off =0 ; i < (arr->num ? *arr->num : arr->max); i++) { -/* Replace \n with comma */ -if (i) - buffer[off -1 ] =',' ; p.arg = arr->elem + arr->elemsize * i;check_kparam_locked (p.mod); - ret = arr->ops->get (buffer + off, &p); + ret = arr->ops->get (elem_buf, &p);if (ret <0 ) -return ret; + goto out; + ret =min (ret, (int )(PAGE_SIZE -1 - off)); +if (!ret) +break ; +/* Replace the previous element's trailing newline with a comma. */ +if (i) + buffer[off -1 ] =',' ; +memcpy (buffer + off, elem_buf, ret); off += ret; +if (off ==PAGE_SIZE -1 ) +break ; } buffer[off] ='\0' ; -return off; + ret = off; +out: +kfree (elem_buf); +return ret; }static void param_array_free (void *arg)
Signature · 1 line
2.34.1
Re: [PATCH 01/11] params: bound array element output to the caller's page buffer
Quoted 5 lines · On Thu, 21 May 2026 06:33:14 -0700 Kees Cook <[email protected]> wrote:
From: Pengpeng Hou <[email protected]>
param_array_get()appends each element's string representation into the shared sysfs page buffer by passing buffer + off to the element getter.
Quoted 7 lines
That works for getters that only write a small bounded string, but
param_get_charp()and similar helpers format againstPAGE_SIZEfrom the pointer they receive. Once off is non-zero, an element getter can therefore write past the end of the original sysfs page buffer.Collect each element into a temporary
PAGE_SIZEbuffer first and then copy only the remaining space into the caller's page buffer.
Should this be using a 4k buffer on all architectures? Initially perhaps just using a different name for the constant until all the associated PAGE_SIZE limits have been removed.
-- David
Quoted 56 lines
Reviewed-by Petr Pavlu <[email protected]>Signed-off-by Pengpeng Hou <[email protected]>Signed-off-by Kees Cook <[email protected]>--- kernel/params.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)kernel/params.c +20
-6@@ -475,22 +475,36 @@ static int param_array_set(const char *val, const struct kernel_param *kp)static int param_array_get (char *buffer,const struct kernel_param *kp) {int i, off, ret; +char *elem_buf;const struct kparam_array *arr = kp->arr;struct kernel_param p = *kp; + elem_buf =kmalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!elem_buf) +return -ENOMEM ; +for (i = off =0 ; i < (arr->num ? *arr->num : arr->max); i++) { -/* Replace \n with comma */ -if (i) - buffer[off -1 ] =',' ; p.arg = arr->elem + arr->elemsize * i;check_kparam_locked (p.mod); - ret = arr->ops->get (buffer + off, &p); + ret = arr->ops->get (elem_buf, &p);if (ret <0 ) -return ret; + goto out; + ret =min (ret, (int )(PAGE_SIZE -1 - off)); +if (!ret) +break ; +/* Replace the previous element's trailing newline with a comma. */ +if (i) + buffer[off -1 ] =',' ; +memcpy (buffer + off, elem_buf, ret); off += ret; +if (off ==PAGE_SIZE -1 ) +break ; } buffer[off] ='\0' ; -return off; + ret = off; +out: +kfree (elem_buf); +return ret; }static void param_array_free (void *arg)
Re: [PATCH 01/11] params: bound array element output to the caller's page buffer
Quoted 8 lines · David Laight
Quoted 2 lines · On Thu, 21 May 2026 06:33:14 -0700 Kees Cook <[email protected]> wrote:
Collect each element into a temporary
PAGE_SIZEbuffer first and then copy only the remaining space into the caller's page buffer.Should this be using a 4k buffer on all architectures? Initially perhaps just using a different name for the constant until all the associated
PAGE_SIZElimits have been removed.
If we're acually going to think about this, even 4KiB is too big. An 80x25 terminal is 2000 bytes (assuming no utf8), so 4KiB is two entire screenfuls. Limiting to 2048 would seem reasonable to me.
Re: [PATCH 01/11] params: bound array element output to the caller's page buffer
In reply to Kees CookQuoted 11 lines · Kees Cook
param_array_get()appends each element's string representation into the shared sysfs page buffer by passing buffer + off to the element getter.That works for getters that only write a small bounded string, but
param_get_charp()and similar helpers format againstPAGE_SIZEfrom the pointer they receive. Once off is non-zero, an element getter can therefore write past the end of the original sysfs page buffer.Collect each element into a temporary
PAGE_SIZEbuffer first and then copy only the remaining space into the caller's page buffer.
...
kernel/params.c static int param_array_set(const char *val, const struct kernel_param *kp) · line 482
Quoted 1 line
kernel/params.c +1
-0+ elem_buf =kmalloc (PAGE_SIZE ,GFP_KERNEL );
get_free_page() (or how it is called)?
Quoted 5 lines
kernel/params.c +3
-1+if (!elem_buf) +return -ENOMEM ; +for (i = off =0 ; i < (arr->num ? *arr->num : arr->max); i++) { -/* Replace \n with comma */
kernel/params.c static int param_array_set(const char *val, const struct kernel_param *kp) · line 492
Quoted 10 lines
kernel/params.c +3
-4-if (i) - buffer[off -1 ] =',' ; p.arg = arr->elem + arr->elemsize * i;check_kparam_locked (p.mod); - ret = arr->ops->get (buffer + off, &p); + ret = arr->ops->get (elem_buf, &p);if (ret <0 ) -return ret; + goto out; + ret =min (ret, (int )(PAGE_SIZE -1 - off));
It's usually discouraged to use castings in min/max/clamp. Can we make ret long or do something different here?
kernel/params.c static int param_array_set(const char *val, const struct kernel_param *kp) · line 497
Quoted 6 lines
kernel/params.c +5
-0+if (!ret) +break ; +/* Replace the previous element's trailing newline with a comma. */ +if (i) + buffer[off -1 ] =',' ;
Can't we do this after with help of strreplace()?
Quoted 11 lines
kernel/params.c +7
-1+memcpy (buffer + off, elem_buf, ret); off += ret; +if (off ==PAGE_SIZE -1 ) +break ; } buffer[off] ='\0' ; -return off; + ret = off; +out: +kfree (elem_buf); +return ret;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 01/11] params: bound array element output to the caller's page buffer
Quoted 10 lines · Andy Shevchenko
Quoted 9 lines · Kees Cook
param_array_get()appends each element's string representation into the shared sysfs page buffer by passing buffer + off to the element getter.That works for getters that only write a small bounded string, but
param_get_charp()and similar helpers format againstPAGE_SIZEfrom the pointer they receive. Once off is non-zero, an element getter can therefore write past the end of the original sysfs page buffer.
Quoted 8 lines
Quoted 2 lines
Collect each element into a temporary
PAGE_SIZEbuffer first and then copy only the remaining space into the caller's page buffer....
kernel/params.c static int param_array_set(const char *val, const struct kernel_param *kp) · line 482
Quoted 1 line
kernel/params.c +1
-0+ elem_buf =kmalloc (PAGE_SIZE ,GFP_KERNEL );
get_free_page()(or how it is called)?
I thought modern mm guidance was to use kmalloc whenever possible and not use get_free_page() unless you intend to use the struct page bits?
Jason
Re: [PATCH 01/11] params: bound array element output to the caller's page buffer
In reply to Andy ShevchenkoQuoted 10 lines · On Tue, 2 Jun 2026 14:26:46 +0300 Andy Shevchenko…
Quoted 9 lines · Kees Cook
param_array_get()appends each element's string representation into the shared sysfs page buffer by passing buffer + off to the element getter.That works for getters that only write a small bounded string, but
param_get_charp()and similar helpers format againstPAGE_SIZEfrom the pointer they receive. Once off is non-zero, an element getter can therefore write past the end of the original sysfs page buffer.
Quoted 8 lines
Quoted 2 lines
Collect each element into a temporary
PAGE_SIZEbuffer first and then copy only the remaining space into the caller's page buffer....
kernel/params.c static int param_array_set(const char *val, const struct kernel_param *kp) · line 482
Quoted 1 line
kernel/params.c +1
-0+ elem_buf =kmalloc (PAGE_SIZE ,GFP_KERNEL );
get_free_page()(or how it is called)?
The kmalloc() should be faster and I think has to be aligned. There is another patch set to replace get_free_pages() with kmalloc().
Although all these 'show' functions should really head to using a safer interface.
Although, at the moment, it is really difficult to find the ones that are guaranteed to be passed a page aligned buffer.
-- David
Quoted 41 lines
Quoted 6 lines
kernel/params.c +3
-1+if (!elem_buf) +return -ENOMEM ; +for (i = off =0 ; i < (arr->num ? *arr->num : arr->max); i++) { -/* Replace \n with comma */ kernel/params.c static int param_array_set(const char *val, const struct kernel_param *kp) · line 492
Quoted 10 lines
kernel/params.c +3
-4-if (i) - buffer[off -1 ] =',' ; p.arg = arr->elem + arr->elemsize * i;check_kparam_locked (p.mod); - ret = arr->ops->get (buffer + off, &p); + ret = arr->ops->get (elem_buf, &p);if (ret <0 ) -return ret; + goto out; + ret =min (ret, (int )(PAGE_SIZE -1 - off));It's usually discouraged to use castings in min/max/clamp. Can we make ret long or do something different here?
kernel/params.c static int param_array_set(const char *val, const struct kernel_param *kp) · line 497
Quoted 6 lines
kernel/params.c +5
-0+if (!ret) +break ; +/* Replace the previous element's trailing newline with a comma. */ +if (i) + buffer[off -1 ] =',' ;Can't we do this after with help of
strreplace()?Quoted 11 lines
kernel/params.c +7
-1+memcpy (buffer + off, elem_buf, ret); off += ret; +if (off ==PAGE_SIZE -1 ) +break ; } buffer[off] ='\0' ; -return off; + ret = off; +out: +kfree (elem_buf); +return ret;
Re: [PATCH 01/11] params: bound array element output to the caller's page buffer
In reply to Kees CookQuoted 3 lines · Kees Cook
ret =
min(ret, (int)(PAGE_SIZE - 1 - off));
if (!ret)break;
One question about the truncation behavior here: when an element does not fully fit in the remaining buffer, this min() can cause only part of that element to be copied. For example, if the remaining space is 4 bytes and the next element produces "123456789\n", the resulting output could contain only "1234".
This leaves the reader with no way to distinguish a genuinely short value from one that was truncated due to the PAGE_SIZE limit, while the array otherwise still looks like a normal comma-separated list.
Is this partial-element truncation intentional for this patch, or is the expectation that it gets handled as part of the later seq_buf conversion? Would it be preferable to avoid copying an element unless it fits completely, and leave the larger-buffer case to be addressed later in the series?
Kees Cook
maintainerPATCH 2/11 panic: Replace panic_print_get() with generic helper
In reply to Kees CookSince panic_print_get() just calls the ulong helper directly, there is no need for it to exist as a wrapper.
--- kernel/panic.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
kernel/panic.c +1 -6
@@ -1214,14 +1214,9 @@ static int panic_print_set(const char *val, const struct kernel_param *kp)return param_set_ulong (val, kp); } -static int panic_print_get (char *val,const struct kernel_param *kp) -{ -return param_get_ulong (val, kp); -} -static const struct kernel_param_ops panic_print_ops = { .set = panic_print_set, - .get = panic_print_get, + .get = param_get_ulong, };__core_param_cb (panic_print, &panic_print_ops, &panic_print,0644 );
Signature · 1 line
2.34.1
Kees Cook
maintainerPATCH 3/11 moduleparam: Add DEFINE_KERNEL_PARAM_OPS macro family
In reply to Kees CookAdd macros that define a struct kernel_param_ops initializer through a macro so the underlying field layout can evolve without touching every call site. Three variants cover the three cases:
DEFINE_KERNEL_PARAM_OPS(name, set, get) // basic DEFINE_KERNEL_PARAM_OPS_NOARG(name, set, get) // set KERNEL_PARAM_OPS_FL_NOARG DEFINE_KERNEL_PARAM_OPS_FREE(name, set, get, free) // also set .free
Callers prefix their own visibility qualifiers, e.g.:
static DEFINE_KERNEL_PARAM_OPS(my_ops, my_set, my_get);
Also update module_param_call() and STANDARD_PARAM_DEF() to use DEFINE_KERNEL_PARAM_OPS internally so the generated ops table will go through the same macro as everything else.
Subsequent commits convert all open-coded struct kernel_param_ops definitions to use these macros, in preparation for migrating to a seq_buf .get API.
--- include/linux/moduleparam.h | 36 ++++++++++++++++++++++++++++++++++-- kernel/params.c | 6 ++---- 2 files changed, 36 insertions(+), 6 deletions(-)
include/linux/moduleparam.h +34 -2
@@ -68,6 +68,39 @@ struct kernel_param_ops {void (*free)(void *arg); }; +/* +* Define a const struct kernel_param_ops initializer. Callers prefix with +* any required visibility qualifiers (typically "static"): +* +* static DEFINE_KERNEL_PARAM_OPS(my_ops, my_set, my_get); +* +* Routing the @_set and @_get function pointers through the macro +* (rather than naming the struct fields at every call site) lets the +* field layout change in one place when callbacks are migrated to a +* new signature. +*/ +#define DEFINE_KERNEL_PARAM_OPS (_name, _set, _get) \ + const struct kernel_param_ops _name = { \ + .set = (_set), \ + .get = (_get), \ + } + +/* As DEFINE_KERNEL_PARAM_OPS, with KERNEL_PARAM_OPS_FL_NOARG set. */ +#define DEFINE_KERNEL_PARAM_OPS_NOARG (_name, _set, _get) \ + const struct kernel_param_ops _name = { \ + .flags = KERNEL_PARAM_OPS_FL_NOARG, \ + .set = (_set), \ + .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 = (_get), \ + .free = (_free), \ + } +/* * Flags available for kernel_param *
@@ -311,8 +344,7 @@ struct kparam_array* kernel_param_ops), use module_param_cb() instead. */ #define module_param_call (name, _set, _get, arg, perm) \ - static const struct kernel_param_ops __param_ops_##name = \ - { .flags = 0, .set = _set, .get = _get }; \ + static DEFINE_KERNEL_PARAM_OPS(__param_ops_##name, _set, _get); \ __module_param_call(MODULE_PARAM_PREFIX, \ name, &__param_ops_##name, arg, perm, -1, 0)
kernel/params.c +2 -4
@@ -222,10 +222,8 @@ char *parse_args(const char *doing,return scnprintf (buffer,PAGE_SIZE , format"\n" , \ *((type *)kp->arg)); \ } \ - const struct kernel_param_ops param_ops_##name = { \ - .set = param_set_##name, \ - .get = param_get_##name, \ - }; \ + DEFINE_KERNEL_PARAM_OPS(param_ops_##name, \ + param_set_##name, param_get_##name); \ EXPORT_SYMBOL(param_set_##name); \ EXPORT_SYMBOL(param_get_##name); \ EXPORT_SYMBOL(param_ops_##name)
Signature · 1 line
2.34.1
Petr Pavlu
maintainerRe: [PATCH 03/11] moduleparam: Add DEFINE_KERNEL_PARAM_OPS macro family
Quoted 35 lines · Kees Cook
Add macros that define a struct
kernel_param_opsinitializer through a macro so the underlying field layout can evolve without touching every call site. Three variants cover the three cases:
DEFINE_KERNEL_PARAM_OPS(name, set, get)// basicDEFINE_KERNEL_PARAM_OPS_NOARG(name, set, get)// setKERNEL_PARAM_OPS_FL_NOARGDEFINE_KERNEL_PARAM_OPS_FREE(name, set, get, free)// also set .freeCallers prefix their own visibility qualifiers, e.g.:
static DEFINE_KERNEL_PARAM_OPS(my_ops, my_set, my_get);Also update
module_param_call()andSTANDARD_PARAM_DEF()to useDEFINE_KERNEL_PARAM_OPSinternally so the generated ops table will go through the same macro as everything else.Subsequent commits convert all open-coded struct
kernel_param_opsdefinitions to use these macros, in preparation for migrating to aseq_buf.get API.Signed-off-by Kees Cook <[email protected]>--- include/linux/moduleparam.h | 36 ++++++++++++++++++++++++++++++++++-- kernel/params.c | 6 ++---- 2 files changed, 36 insertions(+), 6 deletions(-)include/linux/moduleparam.h +1
-0@@ -68,6 +68,39 @@ struct kernel_param_ops {void (*free)(void *arg); }; +/*
include/linux/moduleparam.h struct kernel_param_ops { · line 81
Quoted 10 lines
include/linux/moduleparam.h +10
-0+* Define a const struct kernel_param_ops initializer. Callers prefix with +* any required visibility qualifiers (typically "static"): +* +* static DEFINE_KERNEL_PARAM_OPS(my_ops, my_set, my_get); +* +* Routing the @_set and @_get function pointers through the macro +* (rather than naming the struct fields at every call site) lets the +* field layout change in one place when callbacks are migrated to a +* new signature. +*/
Nit: The newly introduced DEFINE_KERNEL_PARAM_OPS*() macros remain in place at the end of the series after the migration is complete and this comment is removed in patch 7. It would be helpful to describe in the commit message why these macros are generally preferable to defining kernel_param_ops instances directly.
I assume the motivation is that the structure is simple enough and using macros then makes defining kernel_param_ops instances a bit more concise. A minor disadvantage is that some analysis tools, such as ctags, may no longer see the generated definition, but that is also the case for DEFINE_MUTEX() and other similar macros.
Signature · 2 lines
Thanks, Petr
Kees Cook
maintainerPATCH 4/11 treewide: Convert struct kernel_param_ops initializers to DEFINE_KERNEL_PARAM_OPS
In reply to Kees CookUsing Coccinelle, rewrite every struct kernel_param_ops initializer that sets .get into a DEFINE_KERNEL_PARAM_OPS-family macro invocation, for example:
@@
declarer name DEFINE_KERNEL_PARAM_OPS;
identifier OPS;
expression SET, GET;
@@
- const struct kernel_param_ops OPS = {
- .set = SET,
- .get = GET,
- };
+ DEFINE_KERNEL_PARAM_OPS(OPS, SET, GET);
Using the macro for initialization means future changes can manipulate the struct layout and callback prototypes without having to change every initializer.
--- mm/kfence/core.c | 7 +- arch/powerpc/kvm/book3s_hv.c | 5 +- arch/s390/kernel/perf_cpum_sf.c | 6 +- arch/um/drivers/vfio_kern.c | 6 +- arch/um/drivers/virtio_uml.c | 6 +- arch/x86/kernel/msr.c | 6 +- arch/x86/kvm/mmu/mmu.c | 12 +-- arch/x86/kvm/svm/avic.c | 6 +- arch/x86/kvm/vmx/vmx.c | 6 +- arch/x86/platform/uv/uv_nmi.c | 12 +-- block/disk-events.c | 6 +- drivers/acpi/sysfs.c | 25 +++---- drivers/block/loop.c | 12 +-- drivers/block/null_blk/main.c | 12 +-- drivers/block/rnbd/rnbd-srv.c | 6 +- drivers/block/ublk_drv.c | 7 +- drivers/char/ipmi/ipmi_msghandler.c | 6 +- drivers/char/ipmi/ipmi_watchdog.c | 17 ++--- drivers/crypto/hisilicon/hpre/hpre_main.c | 16 +--- drivers/crypto/hisilicon/sec2/sec_main.c | 23 ++---- drivers/crypto/hisilicon/zip/zip_crypto.c | 5 +- drivers/crypto/hisilicon/zip/zip_main.c | 21 ++---- drivers/dma/dmatest.c | 20 ++--- drivers/edac/i10nm_base.c | 6 +- drivers/firmware/efi/efi-pstore.c | 6 +- drivers/firmware/qcom/qcom_scm.c | 6 +- drivers/firmware/qemu_fw_cfg.c | 6 +- drivers/gpu/drm/drm_panic.c | 6 +- drivers/gpu/drm/i915/i915_mitigations.c | 5 +- drivers/gpu/drm/imagination/pvr_fw_trace.c | 6 +- drivers/hid/hid-cougar.c | 6 +- drivers/hid/hid-steam.c | 6 +- drivers/infiniband/hw/hfi1/driver.c | 5 +- drivers/infiniband/ulp/iser/iscsi_iser.c | 6 +- drivers/infiniband/ulp/isert/ib_isert.c | 6 +- drivers/infiniband/ulp/srp/ib_srp.c | 5 +- drivers/input/misc/ati_remote2.c | 13 ++-- drivers/input/mouse/psmouse-base.c | 6 +- drivers/media/usb/uvc/uvc_driver.c | 6 +- drivers/misc/lis3lv02d/lis3lv02d.c | 5 +- drivers/net/wireless/ath/wil6210/main.c | 10 +-- drivers/nvme/host/multipath.c | 12 +-- drivers/nvme/host/pci.c | 18 ++--- drivers/nvme/target/rdma.c | 5 +- drivers/nvme/target/tcp.c | 5 +- drivers/platform/x86/acerhdf.c | 5 +- drivers/power/supply/bq27xxx_battery.c | 6 +- drivers/power/supply/test_power.c | 75 ++++++++----------- drivers/scsi/sg.c | 6 +- drivers/target/target_core_user.c | 13 ++-- .../processor_thermal_soc_slider.c | 12 +-- drivers/thermal/intel/intel_powerclamp.c | 20 +---- drivers/tty/hvc/hvc_iucv.c | 6 +- drivers/tty/sysrq.c | 6 +- drivers/ufs/core/ufs-fault-injection.c | 5 +- drivers/ufs/core/ufs-mcq.c | 18 ++--- drivers/ufs/core/ufs-txeq.c | 5 +- drivers/ufs/core/ufshcd.c | 12 +-- drivers/usb/core/quirks.c | 6 +- drivers/usb/gadget/legacy/serial.c | 5 +- drivers/usb/storage/usb.c | 5 +- drivers/vhost/scsi.c | 7 +- drivers/virt/nitro_enclaves/ne_misc_dev.c | 6 +- drivers/virtio/virtio_mmio.c | 6 +- fs/ceph/super.c | 10 +-- fs/fuse/dir.c | 5 +- fs/nfs/namespace.c | 6 +- fs/nfs/super.c | 6 +- fs/ubifs/super.c | 6 +- kernel/locking/locktorture.c | 6 +- kernel/panic.c | 6 +- kernel/params.c | 44 +++-------- kernel/power/hibernate.c | 6 +- kernel/rcu/tree.c | 18 ++--- kernel/sched/ext.c | 11 +-- kernel/workqueue.c | 12 +-- lib/dynamic_debug.c | 6 +- lib/test_dynamic_debug.c | 6 +- mm/damon/lru_sort.c | 19 ++--- mm/damon/reclaim.c | 19 ++--- mm/damon/stat.c | 6 +- mm/memory_hotplug.c | 12 +-- mm/page_reporting.c | 11 +-- mm/shuffle.c | 6 +- mm/zswap.c | 14 ++-- net/batman-adv/bat_algo.c | 6 +- net/ceph/ceph_common.c | 5 +- net/ipv4/tcp_dctcp.c | 6 +- net/sunrpc/auth.c | 6 +- net/sunrpc/xprtsock.c | 18 ++--- samples/damon/mtier.c | 6 +- samples/damon/prcl.c | 6 +- samples/damon/wsse.c | 6 +- security/apparmor/lsm.c | 34 +++------ sound/hda/controllers/intel.c | 5 +- sound/usb/card.c | 7 +- 96 files changed, 307 insertions(+), 660 deletions(-)
mm/kfence/core.c +3 -4
@@ -92,10 +92,9 @@ static int param_get_sample_interval(char *buffer, const struct kernel_param *kpreturn param_get_ulong (buffer, kp); } -static const struct kernel_param_ops sample_interval_param_ops = { - .set = param_set_sample_interval, - .get = param_get_sample_interval, -}; +static DEFINE_KERNEL_PARAM_OPS(sample_interval_param_ops, + param_set_sample_interval, + param_get_sample_interval);module_param_cb (sample_interval, &sample_interval_param_ops, &kfence_sample_interval,0600 );/* Pool usage% threshold when currently covered allocations are skipped. */
arch/powerpc/kvm/book3s_hv.c +1 -4
@@ -114,10 +114,7 @@ module_param(one_vm_per_core, bool, S_IRUGO | S_IWUSR);MODULE_PARM_DESC (one_vm_per_core,"Only run vCPUs from the same VM on a core (requires POWER8 or older)" );#ifdef CONFIG_KVM_XICS -static const struct kernel_param_ops module_param_ops = { - .set = param_set_int, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(module_param_ops, param_set_int, param_get_int);module_param_cb (kvm_irq_bypass, &module_param_ops, &kvm_irq_bypass,0644 );MODULE_PARM_DESC (kvm_irq_bypass,"Bypass passthrough interrupt optimization" );
arch/s390/kernel/perf_cpum_sf.c +2 -4
@@ -2029,10 +2029,8 @@ static int param_set_sfb_size(const char *val, const struct kernel_param *kp) }#define param_check_sfb_size (name, p) __param_check(name, p, void) -static const struct kernel_param_ops param_ops_sfb_size = { - .set = param_set_sfb_size, - .get = param_get_sfb_size, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_sfb_size, param_set_sfb_size, + param_get_sfb_size);enum {RS_INIT_FAILURE_BSDES =2 ,/* Bad basic sampling size */
arch/um/drivers/vfio_kern.c +2 -4
@@ -628,10 +628,8 @@ static int uml_vfio_cmdline_get(char *buffer, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops uml_vfio_cmdline_param_ops = { - .set = uml_vfio_cmdline_set, - .get = uml_vfio_cmdline_get, -}; +static DEFINE_KERNEL_PARAM_OPS(uml_vfio_cmdline_param_ops, uml_vfio_cmdline_set, + uml_vfio_cmdline_get);device_param_cb (device, ¨_vfio_cmdline_param_ops,NULL ,0400 ); __uml_help(uml_vfio_cmdline_param_ops,
arch/um/drivers/virtio_uml.c +2 -4
@@ -1398,10 +1398,8 @@ static int vu_cmdline_get(char *buffer, const struct kernel_param *kp)return strlen (buffer) +1 ; } -static const struct kernel_param_ops vu_cmdline_param_ops = { - .set = vu_cmdline_set, - .get = vu_cmdline_get, -}; +static DEFINE_KERNEL_PARAM_OPS(vu_cmdline_param_ops, vu_cmdline_set, + vu_cmdline_get);device_param_cb (device, &vu_cmdline_param_ops,NULL ,S_IRUSR ); __uml_help(vu_cmdline_param_ops,
arch/x86/kernel/msr.c +2 -4
@@ -322,10 +322,8 @@ static int get_allow_writes(char *buf, const struct kernel_param *kp)return sprintf (buf,"%s\n" , res); } -static const struct kernel_param_ops allow_writes_ops = { - .set = set_allow_writes, - .get = get_allow_writes -}; +static DEFINE_KERNEL_PARAM_OPS(allow_writes_ops, set_allow_writes, + get_allow_writes);module_param_cb (allow_writes, &allow_writes_ops,NULL ,0600 );
arch/x86/kvm/mmu/mmu.c +4 -8
@@ -74,15 +74,11 @@ static int get_nx_huge_pages(char *buffer, const struct kernel_param *kp);static int set_nx_huge_pages (const char *val,const struct kernel_param *kp);static int set_nx_huge_pages_recovery_param (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops nx_huge_pages_ops = { - .set = set_nx_huge_pages, - .get = get_nx_huge_pages, -}; +static DEFINE_KERNEL_PARAM_OPS(nx_huge_pages_ops, set_nx_huge_pages, + get_nx_huge_pages); -static const struct kernel_param_ops nx_huge_pages_recovery_param_ops = { - .set = set_nx_huge_pages_recovery_param, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(nx_huge_pages_recovery_param_ops, + set_nx_huge_pages_recovery_param, param_get_uint);module_param_cb (nx_huge_pages, &nx_huge_pages_ops, &nx_huge_pages,0644 );__MODULE_PARM_TYPE (nx_huge_pages,"bool" );
arch/x86/kvm/svm/avic.c +1 -5
@@ -87,11 +87,7 @@ static int avic_param_get(char *buffer, const struct kernel_param *kp)return param_get_bool (buffer, kp); } -static const struct kernel_param_ops avic_ops = { - .flags =KERNEL_PARAM_OPS_FL_NOARG , - .set = avic_param_set, - .get = avic_param_get, -}; +static DEFINE_KERNEL_PARAM_OPS_NOARG(avic_ops, avic_param_set, avic_param_get);/* * Enable / disable AVIC. In "auto" mode (default behavior), AVIC is enabled
arch/x86/kvm/vmx/vmx.c +2 -4
@@ -465,10 +465,8 @@ static int vmentry_l1d_flush_get(char *s, const struct kernel_param *kp) }#endif -static const struct kernel_param_ops vmentry_l1d_flush_ops = { - .set = vmentry_l1d_flush_set, - .get = vmentry_l1d_flush_get, -}; +static DEFINE_KERNEL_PARAM_OPS(vmentry_l1d_flush_ops, vmentry_l1d_flush_set, + vmentry_l1d_flush_get);module_param_cb (vmentry_l1d_flush, &vmentry_l1d_flush_ops,NULL ,0644 ); static __always_inline void vmx_disable_fb_clear(struct vcpu_vmx *vmx)
arch/x86/platform/uv/uv_nmi.c +4 -8
@@ -123,10 +123,8 @@ static int param_set_local64(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops param_ops_local64 = { - .get = param_get_local64, - .set = param_set_local64, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_local64, param_set_local64, + param_get_local64);#define param_check_local64 (name, p) __param_check(name, p, local64_t)static local64_t uv_nmi_count;
@@ -232,10 +230,8 @@ static int param_set_action(const char *val, const struct kernel_param *kp)return -EINVAL ; } -static const struct kernel_param_ops param_ops_action = { - .get = param_get_action, - .set = param_set_action, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_action, param_set_action, + param_get_action);#define param_check_action (name, p) __param_check(name, p, enum action_t)module_param_named (action, uv_nmi_action, action,0644 );
block/disk-events.c +2 -4
@@ -416,10 +416,8 @@ static int disk_events_set_dfl_poll_msecs(const char *val,return 0 ; } -static const struct kernel_param_ops disk_events_dfl_poll_msecs_param_ops = { - .set = disk_events_set_dfl_poll_msecs, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(disk_events_dfl_poll_msecs_param_ops, + disk_events_set_dfl_poll_msecs, param_get_ulong);#undef MODULE_PARAM_PREFIX#define MODULE_PARAM_PREFIX "block."
drivers/acpi/sysfs.c +9 -16
@@ -138,15 +138,11 @@ static int param_get_debug_level(char *buffer, const struct kernel_param *kp)return result; } -static const struct kernel_param_ops param_ops_debug_layer = { - .set = param_set_uint, - .get = param_get_debug_layer, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_debug_layer, param_set_uint, + param_get_debug_layer); -static const struct kernel_param_ops param_ops_debug_level = { - .set = param_set_uint, - .get = param_get_debug_level, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_debug_level, param_set_uint, + param_get_debug_level);module_param_cb (debug_layer, ¶m_ops_debug_layer, &acpi_dbg_layer,0644 );module_param_cb (debug_level, ¶m_ops_debug_level, &acpi_dbg_level,0644 );
@@ -201,15 +197,12 @@ static int param_get_trace_method_name(char *buffer, const struct kernel_param *return sysfs_emit (buffer,"%s\n" , acpi_gbl_trace_method_name); } -static const struct kernel_param_ops param_ops_trace_method = { - .set = param_set_trace_method_name, - .get = param_get_trace_method_name, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_trace_method, + param_set_trace_method_name, + param_get_trace_method_name); -static const struct kernel_param_ops param_ops_trace_attrib = { - .set = param_set_uint, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_trace_attrib, param_set_uint, + param_get_uint);module_param_cb (trace_method_name, ¶m_ops_trace_method, &trace_method_name,0644 );module_param_cb (trace_debug_layer, ¶m_ops_trace_attrib, &acpi_gbl_trace_dbg_layer,0644 );
drivers/block/loop.c +4 -8
@@ -1806,10 +1806,8 @@ static int max_loop_param_set_int(const char *val,return 0 ; } -static const struct kernel_param_ops max_loop_param_ops = { - .set = max_loop_param_set_int, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(max_loop_param_ops, max_loop_param_set_int, + param_get_int);module_param_cb (max_loop, &max_loop_param_ops, &max_loop,0444 );MODULE_PARM_DESC (max_loop,"Maximum number of loop devices" );
@@ -1836,10 +1834,8 @@ static int loop_set_hw_queue_depth(const char *s, const struct kernel_param *p)return 0 ; } -static const struct kernel_param_ops loop_hw_qdepth_param_ops = { - .set = loop_set_hw_queue_depth, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(loop_hw_qdepth_param_ops, + loop_set_hw_queue_depth, param_get_int);device_param_cb (hw_queue_depth, &loop_hw_qdepth_param_ops, &hw_queue_depth,0444 );MODULE_PARM_DESC (hw_queue_depth,"Queue depth for each hardware queue. Default: " __stringify(LOOP_DEFAULT_HW_Q_DEPTH ));
drivers/block/null_blk/main.c +4 -8
@@ -149,10 +149,8 @@ static int null_set_queue_mode(const char *str, const struct kernel_param *kp)return null_param_store_val (str, &g_queue_mode,NULL_Q_BIO ,NULL_Q_MQ ); } -static const struct kernel_param_ops null_queue_mode_param_ops = { - .set = null_set_queue_mode, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(null_queue_mode_param_ops, null_set_queue_mode, + param_get_int);device_param_cb (queue_mode, &null_queue_mode_param_ops, &g_queue_mode,0444 );MODULE_PARM_DESC (queue_mode,"Block interface to use (0=bio,1=rq,2=multiqueue)" );
@@ -193,10 +191,8 @@ static int null_set_irqmode(const char *str, const struct kernel_param *kp) NULL_IRQ_TIMER); } -static const struct kernel_param_ops null_irqmode_param_ops = { - .set = null_set_irqmode, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(null_irqmode_param_ops, null_set_irqmode, + param_get_int);device_param_cb (irqmode, &null_irqmode_param_ops, &g_irqmode,0444 );MODULE_PARM_DESC (irqmode,"IRQ completion handler. 0-none, 1-softirq, 2-timer" );
drivers/block/rnbd/rnbd-srv.c +2 -4
@@ -49,10 +49,8 @@ static struct kparam_string dev_search_path_kparam_str = { .string = dev_search_path }; -static const struct kernel_param_ops dev_search_path_ops = { - .set = dev_search_path_set, - .get = param_get_string, -}; +static DEFINE_KERNEL_PARAM_OPS(dev_search_path_ops, dev_search_path_set, + param_get_string);module_param_cb (dev_search_path, &dev_search_path_ops, &dev_search_path_kparam_str,0444 );
drivers/block/ublk_drv.c +3 -4
@@ -5874,10 +5874,9 @@ static int ublk_get_max_unprivileged_ublks(char *buf,return sysfs_emit (buf,"%u\n" , unprivileged_ublks_max); } -static const struct kernel_param_ops ublk_max_unprivileged_ublks_ops = { - .set = ublk_set_max_unprivileged_ublks, - .get = ublk_get_max_unprivileged_ublks, -}; +static DEFINE_KERNEL_PARAM_OPS(ublk_max_unprivileged_ublks_ops, + ublk_set_max_unprivileged_ublks, + ublk_get_max_unprivileged_ublks);module_param_cb (ublks_max, &ublk_max_unprivileged_ublks_ops, &unprivileged_ublks_max,0644 );
drivers/char/ipmi/ipmi_msghandler.c +2 -4
@@ -102,10 +102,8 @@ static int panic_op_read_handler(char *buffer, const struct kernel_param *kp)return sprintf (buffer,"%s\n" , event_str); } -static const struct kernel_param_ops panic_op_ops = { - .set = panic_op_write_handler, - .get = panic_op_read_handler -}; +static DEFINE_KERNEL_PARAM_OPS(panic_op_ops, panic_op_write_handler, + panic_op_read_handler);module_param_cb (panic_op, &panic_op_ops,NULL ,0600 );MODULE_PARM_DESC (panic_op,"Sets if the IPMI driver will attempt to store panic information in the event log in the event of a panic. Set to 'none' for no, 'event' for a single event, or 'string' for a generic event and the panic string in IPMI OEM events." );
drivers/char/ipmi/ipmi_watchdog.c +5 -12
@@ -193,10 +193,8 @@ static int set_param_timeout(const char *val, const struct kernel_param *kp)return rv; } -static const struct kernel_param_ops param_ops_timeout = { - .set = set_param_timeout, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_timeout, set_param_timeout, + param_get_int);#define param_check_timeout param_check_inttypedef int (*action_fn )(const char *intval,char *outval);
@@ -259,17 +257,12 @@ static int set_param_wdog_ifnum(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops param_ops_wdog_ifnum = { - .set = set_param_wdog_ifnum, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_wdog_ifnum, set_param_wdog_ifnum, + param_get_int);#define param_check_wdog_ifnum param_check_int -static const struct kernel_param_ops param_ops_str = { - .set = set_param_str, - .get = get_param_str, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_str, set_param_str, get_param_str);module_param (ifnum_to_use, wdog_ifnum,0644 ); MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog "
drivers/crypto/hisilicon/hpre/hpre_main.c +4 -12
@@ -420,10 +420,8 @@ static int hpre_cluster_regs_show(struct seq_file *s, void *unused)DEFINE_SHOW_ATTRIBUTE (hpre_cluster_regs); -static const struct kernel_param_ops hpre_uacce_mode_ops = { - .set = uacce_mode_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(hpre_uacce_mode_ops, uacce_mode_set, + param_get_int);/* * uacce_mode = 0 means hpre only register to crypto,
@@ -441,19 +439,13 @@ static int pf_q_num_set(const char *val, const struct kernel_param *kp)return hisi_qm_q_num_set (val, kp,PCI_DEVICE_ID_HUAWEI_HPRE_PF ); } -static const struct kernel_param_ops hpre_pf_q_num_ops = { - .set = pf_q_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(hpre_pf_q_num_ops, pf_q_num_set, param_get_int);static u32 pf_q_num =HPRE_PF_DEF_Q_NUM ;module_param_cb (pf_q_num, &hpre_pf_q_num_ops, &pf_q_num,0444 );MODULE_PARM_DESC (pf_q_num,"Number of queues in PF of CS(2-1024)" ); -static const struct kernel_param_ops vfs_num_ops = { - .set = vfs_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(vfs_num_ops, vfs_num_set, param_get_int);static u32 vfs_num;module_param_cb (vfs_num, &vfs_num_ops, &vfs_num,0444 );
drivers/crypto/hisilicon/sec2/sec_main.c +7 -16
@@ -362,10 +362,8 @@ static int sec_pf_q_num_set(const char *val, const struct kernel_param *kp)return hisi_qm_q_num_set (val, kp,PCI_DEVICE_ID_HUAWEI_SEC_PF ); } -static const struct kernel_param_ops sec_pf_q_num_ops = { - .set = sec_pf_q_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(sec_pf_q_num_ops, sec_pf_q_num_set, + param_get_int);static u32 pf_q_num =SEC_PF_DEF_Q_NUM ;module_param_cb (pf_q_num, &sec_pf_q_num_ops, &pf_q_num,0444 );
@@ -391,18 +389,13 @@ static int sec_ctx_q_num_set(const char *val, const struct kernel_param *kp)return param_set_int (val, kp); } -static const struct kernel_param_ops sec_ctx_q_num_ops = { - .set = sec_ctx_q_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(sec_ctx_q_num_ops, sec_ctx_q_num_set, + param_get_int);static u32 ctx_q_num =SEC_CTX_Q_NUM_DEF ;module_param_cb (ctx_q_num, &sec_ctx_q_num_ops, &ctx_q_num,0444 );MODULE_PARM_DESC (ctx_q_num,"Queue num in ctx (2 default, 2, 4, ..., 32)" ); -static const struct kernel_param_ops vfs_num_ops = { - .set = vfs_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(vfs_num_ops, vfs_num_set, param_get_int);static u32 vfs_num;module_param_cb (vfs_num, &vfs_num_ops, &vfs_num,0444 );
@@ -454,10 +447,8 @@ u64 sec_get_alg_bitmap(struct hisi_qm *qm, u32 high, u32 low)return ((u64 )cap_val_h <<SEC_ALG_BITMAP_SHIFT ) | (u64 )cap_val_l; } -static const struct kernel_param_ops sec_uacce_mode_ops = { - .set = uacce_mode_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(sec_uacce_mode_ops, uacce_mode_set, + param_get_int);/* * uacce_mode = 0 means sec only register to crypto,
drivers/crypto/hisilicon/zip/zip_crypto.c +1 -4
@@ -108,10 +108,7 @@ static int sgl_sge_nr_set(const char *val, const struct kernel_param *kp)return param_set_ushort (val, kp); } -static const struct kernel_param_ops sgl_sge_nr_ops = { - .set = sgl_sge_nr_set, - .get = param_get_ushort, -}; +static DEFINE_KERNEL_PARAM_OPS(sgl_sge_nr_ops, sgl_sge_nr_set, param_get_ushort);static u16 sgl_sge_nr =HZIP_SGL_SGE_NR ;module_param_cb (sgl_sge_nr, &sgl_sge_nr_ops, &sgl_sge_nr,0444 );
drivers/crypto/hisilicon/zip/zip_main.c +5 -16
@@ -394,10 +394,7 @@ static int perf_mode_set(const char *val, const struct kernel_param *kp)return param_set_int (val, kp); } -static const struct kernel_param_ops zip_com_perf_ops = { - .set = perf_mode_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(zip_com_perf_ops, perf_mode_set, param_get_int);/* * perf_mode = 0 means enable high compression rate mode,
@@ -408,10 +405,8 @@ static u32 perf_mode = HZIP_HIGH_COMP_RATE;module_param_cb (perf_mode, &zip_com_perf_ops, &perf_mode,0444 );MODULE_PARM_DESC (perf_mode,"ZIP high perf mode 0(default), 1(enable)" ); -static const struct kernel_param_ops zip_uacce_mode_ops = { - .set = uacce_mode_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(zip_uacce_mode_ops, uacce_mode_set, + param_get_int);/* * uacce_mode = 0 means zip only register to crypto,
@@ -429,19 +424,13 @@ static int pf_q_num_set(const char *val, const struct kernel_param *kp)return hisi_qm_q_num_set (val, kp,PCI_DEVICE_ID_HUAWEI_ZIP_PF ); } -static const struct kernel_param_ops pf_q_num_ops = { - .set = pf_q_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(pf_q_num_ops, pf_q_num_set, param_get_int);static u32 pf_q_num =HZIP_PF_DEF_Q_NUM ;module_param_cb (pf_q_num, &pf_q_num_ops, &pf_q_num,0444 );MODULE_PARM_DESC (pf_q_num,"Number of queues in PF(v1 2-4096, v2 2-1024)" ); -static const struct kernel_param_ops vfs_num_ops = { - .set = vfs_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(vfs_num_ops, vfs_num_set, param_get_int);static u32 vfs_num;module_param_cb (vfs_num, &vfs_num_ops, &vfs_num,0444 );
drivers/dma/dmatest.c +5 -15
@@ -154,20 +154,15 @@ static struct dmatest_info {static int dmatest_run_set (const char *val,const struct kernel_param *kp);static int dmatest_run_get (char *val,const struct kernel_param *kp); -static const struct kernel_param_ops run_ops = { - .set = dmatest_run_set, - .get = dmatest_run_get, -}; +static DEFINE_KERNEL_PARAM_OPS(run_ops, dmatest_run_set, dmatest_run_get);static bool dmatest_run;module_param_cb (run, &run_ops, &dmatest_run,0644 );MODULE_PARM_DESC (run,"Run the test (default: false)" );static int dmatest_chan_set (const char *val,const struct kernel_param *kp);static int dmatest_chan_get (char *val,const struct kernel_param *kp); -static const struct kernel_param_ops multi_chan_ops = { - .set = dmatest_chan_set, - .get = dmatest_chan_get, -}; +static DEFINE_KERNEL_PARAM_OPS(multi_chan_ops, dmatest_chan_set, + dmatest_chan_get);static char test_channel[20 ];static struct kparam_string newchan_kps = {
@@ -178,9 +173,7 @@ module_param_cb(channel, &multi_chan_ops, &newchan_kps, 0644);MODULE_PARM_DESC (channel,"Bus ID of the channel to test (default: any)" );static int dmatest_test_list_get (char *val,const struct kernel_param *kp); -static const struct kernel_param_ops test_list_ops = { - .get = dmatest_test_list_get, -}; +static DEFINE_KERNEL_PARAM_OPS(test_list_ops, NULL, dmatest_test_list_get);module_param_cb (test_list, &test_list_ops,NULL ,0444 );MODULE_PARM_DESC (test_list,"Print current test list" );
@@ -292,10 +285,7 @@ static int dmatest_wait_get(char *val, const struct kernel_param *kp)return param_get_bool (val, kp); } -static const struct kernel_param_ops wait_ops = { - .get = dmatest_wait_get, - .set = param_set_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(wait_ops, param_set_bool, dmatest_wait_get);module_param_cb (wait, &wait_ops, &wait,0444 );MODULE_PARM_DESC (wait,"Wait for tests to complete (default: false)" );
drivers/edac/i10nm_base.c +2 -4
@@ -1284,10 +1284,8 @@ static int set_decoding_via_mca(const char *buf, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops decoding_via_mca_param_ops = { - .set = set_decoding_via_mca, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(decoding_via_mca_param_ops, set_decoding_via_mca, + param_get_int);module_param_cb (decoding_via_mca, &decoding_via_mca_param_ops, &decoding_via_mca,0644 );MODULE_PARM_DESC (decoding_via_mca,"decoding_via_mca: 0=off(default), 1=enable" );
drivers/firmware/efi/efi-pstore.c +2 -4
@@ -43,10 +43,8 @@ static int efi_pstore_disable_set(const char *val, const struct kernel_param *kpreturn 0 ; } -static const struct kernel_param_ops pstore_disable_ops = { - .set = efi_pstore_disable_set, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(pstore_disable_ops, efi_pstore_disable_set, + param_get_bool);module_param_cb (pstore_disable, &pstore_disable_ops, &pstore_disable,0644 );__MODULE_PARM_TYPE (pstore_disable,"bool" );
drivers/firmware/qcom/qcom_scm.c +2 -4
@@ -2725,10 +2725,8 @@ static int set_download_mode(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops download_mode_param_ops = { - .get = get_download_mode, - .set = set_download_mode, -}; +static DEFINE_KERNEL_PARAM_OPS(download_mode_param_ops, set_download_mode, + get_download_mode);module_param_cb (download_mode, &download_mode_param_ops,NULL ,0644 );MODULE_PARM_DESC (download_mode,"download mode: off/0/N for no dump mode, full/on/1/Y for full dump mode, mini for minidump mode and full,mini for both full and minidump mode together are acceptable values" );
drivers/firmware/qemu_fw_cfg.c +2 -4
@@ -897,10 +897,8 @@ static int fw_cfg_cmdline_get(char *buf, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops fw_cfg_cmdline_param_ops = { - .set = fw_cfg_cmdline_set, - .get = fw_cfg_cmdline_get, -}; +static DEFINE_KERNEL_PARAM_OPS(fw_cfg_cmdline_param_ops, fw_cfg_cmdline_set, + fw_cfg_cmdline_get);device_param_cb (ioport, &fw_cfg_cmdline_param_ops,NULL ,S_IRUSR );device_param_cb (mmio, &fw_cfg_cmdline_param_ops,NULL ,S_IRUSR );
drivers/gpu/drm/drm_panic.c +2 -4
@@ -847,10 +847,8 @@ static int drm_panic_type_get(char *buffer, const struct kernel_param *kp) drm_panic_type_map[drm_panic_type]); } -static const struct kernel_param_ops drm_panic_ops = { - .set = drm_panic_type_set, - .get = drm_panic_type_get, -}; +static DEFINE_KERNEL_PARAM_OPS(drm_panic_ops, drm_panic_type_set, + drm_panic_type_get);module_param_cb (panic_screen, &drm_panic_ops,NULL ,0644 ); MODULE_PARM_DESC(panic_screen,
drivers/gpu/drm/i915/i915_mitigations.c +1 -4
@@ -124,10 +124,7 @@ static int mitigations_get(char *buffer, const struct kernel_param *kp)return count; } -static const struct kernel_param_ops ops = { - .set = mitigations_set, - .get = mitigations_get, -}; +static DEFINE_KERNEL_PARAM_OPS(ops, mitigations_set, mitigations_get);module_param_cb_unsafe (mitigations, &ops,NULL ,0600 ); MODULE_PARM_DESC(mitigations,
drivers/gpu/drm/imagination/pvr_fw_trace.c +2 -4
@@ -71,10 +71,8 @@ pvr_fw_trace_init_mask_set(const char *val, const struct kernel_param *kp)return 0 ; } -const struct kernel_param_ops pvr_fw_trace_init_mask_ops = { - .set = pvr_fw_trace_init_mask_set, - .get = param_get_hexint, -}; +DEFINE_KERNEL_PARAM_OPS (pvr_fw_trace_init_mask_ops, pvr_fw_trace_init_mask_set, + param_get_hexint);param_check_hexint (init_fw_trace_mask, &pvr_fw_trace_init_mask);module_param_cb (init_fw_trace_mask, &pvr_fw_trace_init_mask_ops, &pvr_fw_trace_init_mask,0600 );
drivers/hid/hid-cougar.c +2 -4
@@ -314,10 +314,8 @@ static int cougar_param_set_g6_is_space(const char *val,return 0 ; } -static const struct kernel_param_ops cougar_g6_is_space_ops = { - .set = cougar_param_set_g6_is_space, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(cougar_g6_is_space_ops, + cougar_param_set_g6_is_space, param_get_bool);module_param_cb (g6_is_space, &cougar_g6_is_space_ops, &g6_is_space,0644 );static const struct hid_device_id cougar_id_table[] = {
drivers/hid/hid-steam.c +2 -4
@@ -1840,10 +1840,8 @@ static int steam_param_set_lizard_mode(const char *val,return 0 ; } -static const struct kernel_param_ops steam_lizard_mode_ops = { - .set = steam_param_set_lizard_mode, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(steam_lizard_mode_ops, + steam_param_set_lizard_mode, param_get_bool);module_param_cb (lizard_mode, &steam_lizard_mode_ops, &lizard_mode,0644 ); MODULE_PARM_DESC(lizard_mode,
drivers/infiniband/hw/hfi1/driver.c +1 -4
@@ -42,10 +42,7 @@ MODULE_PARM_DESC(cu, "Credit return units");unsigned long hfi1_cap_mask =HFI1_CAP_MASK_DEFAULT ;static int hfi1_caps_set (const char *val,const struct kernel_param *kp);static int hfi1_caps_get (char *buffer,const struct kernel_param *kp); -static const struct kernel_param_ops cap_ops = { - .set = hfi1_caps_set, - .get = hfi1_caps_get -}; +static DEFINE_KERNEL_PARAM_OPS(cap_ops, hfi1_caps_set, hfi1_caps_get);module_param_cb (cap_mask, &cap_ops, &hfi1_cap_mask,S_IWUSR |S_IRUGO );MODULE_PARM_DESC (cap_mask,"Bit mask of enabled/disabled HW features" );
drivers/infiniband/ulp/iser/iscsi_iser.c +2 -4
@@ -90,10 +90,8 @@ module_param_named(debug_level, iser_debug_level, int, S_IRUGO | S_IWUSR);MODULE_PARM_DESC (debug_level,"Enable debug tracing if > 0 (default:disabled)" );static int iscsi_iser_set (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops iscsi_iser_size_ops = { - .set = iscsi_iser_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(iscsi_iser_size_ops, iscsi_iser_set, + param_get_uint);static unsigned int iscsi_max_lun =512 ;module_param_cb (max_lun, &iscsi_iser_size_ops, &iscsi_max_lun,S_IRUGO );
drivers/infiniband/ulp/isert/ib_isert.c +2 -4
@@ -30,10 +30,8 @@ MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:0)");static int isert_sg_tablesize_set (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops sg_tablesize_ops = { - .set = isert_sg_tablesize_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(sg_tablesize_ops, isert_sg_tablesize_set, + param_get_int);static int isert_sg_tablesize =ISCSI_ISER_MIN_SG_TABLESIZE ;module_param_cb (sg_tablesize, &sg_tablesize_ops, &isert_sg_tablesize,0644 );
drivers/infiniband/ulp/srp/ib_srp.c +1 -4
@@ -195,10 +195,7 @@ static int srp_tmo_set(const char *val, const struct kernel_param *kp)return res; } -static const struct kernel_param_ops srp_tmo_ops = { - .get = srp_tmo_get, - .set = srp_tmo_set, -}; +static DEFINE_KERNEL_PARAM_OPS(srp_tmo_ops, srp_tmo_set, srp_tmo_get);static inline struct srp_target_port *host_to_target (struct Scsi_Host *host) {
drivers/input/misc/ati_remote2.c +5 -8
@@ -89,19 +89,16 @@ static int ati_remote2_get_mode_mask(char *buffer,static unsigned int channel_mask =ATI_REMOTE2_MAX_CHANNEL_MASK ;#define param_check_channel_mask (name, p) __param_check(name, p, unsigned int) -static const struct kernel_param_ops param_ops_channel_mask = { - .set = ati_remote2_set_channel_mask, - .get = ati_remote2_get_channel_mask, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_channel_mask, + ati_remote2_set_channel_mask, + ati_remote2_get_channel_mask);module_param (channel_mask, channel_mask,0644 );MODULE_PARM_DESC (channel_mask,"Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>" );static unsigned int mode_mask =ATI_REMOTE2_MAX_MODE_MASK ;#define param_check_mode_mask (name, p) __param_check(name, p, unsigned int) -static const struct kernel_param_ops param_ops_mode_mask = { - .set = ati_remote2_set_mode_mask, - .get = ati_remote2_get_mode_mask, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_mode_mask, ati_remote2_set_mode_mask, + ati_remote2_get_mode_mask);module_param (mode_mask, mode_mask,0644 );MODULE_PARM_DESC (mode_mask,"Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>" );
drivers/input/mouse/psmouse-base.c +2 -4
@@ -45,10 +45,8 @@ MODULE_LICENSE("GPL");static unsigned int psmouse_max_proto =PSMOUSE_AUTO ;static int psmouse_set_maxproto (const char *val,const struct kernel_param *);static int psmouse_get_maxproto (char *buffer,const struct kernel_param *kp); -static const struct kernel_param_ops param_ops_proto_abbrev = { - .set = psmouse_set_maxproto, - .get = psmouse_get_maxproto, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_proto_abbrev, psmouse_set_maxproto, + psmouse_get_maxproto);#define param_check_proto_abbrev (name, p) __param_check(name, p, unsigned int)module_param_named (proto, psmouse_max_proto, proto_abbrev,0644 );MODULE_PARM_DESC (proto,"Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches." );
drivers/media/usb/uvc/uvc_driver.c +2 -4
@@ -2488,10 +2488,8 @@ static int param_set_nodrop(const char *val, const struct kernel_param *kp)return param_set_bool (val, kp); } -static const struct kernel_param_ops param_ops_nodrop = { - .set = param_set_nodrop, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_nodrop, param_set_nodrop, + param_get_uint);param_check_uint (nodrop, &uvc_no_drop_param);module_param_cb (nodrop, ¶m_ops_nodrop, &uvc_no_drop_param,0644 );
drivers/misc/lis3lv02d/lis3lv02d.c +1 -4
@@ -103,10 +103,7 @@ static int param_set_axis(const char *val, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops param_ops_axis = { - .set = param_set_axis, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_axis, param_set_axis, param_get_int);#define param_check_axis (name, p) param_check_int(name, p)
drivers/net/wireless/ath/wil6210/main.c +2 -8
@@ -62,10 +62,7 @@ static int mtu_max_set(const char *val, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops mtu_max_ops = { - .set = mtu_max_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(mtu_max_ops, mtu_max_set, param_get_uint);module_param_cb (mtu_max, &mtu_max_ops, &mtu_max,0444 );MODULE_PARM_DESC (mtu_max," Max MTU value." );
@@ -91,10 +88,7 @@ static int ring_order_set(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops ring_order_ops = { - .set = ring_order_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(ring_order_ops, ring_order_set, param_get_uint);module_param_cb (rx_ring_order, &ring_order_ops, &rx_ring_order,0444 );MODULE_PARM_DESC (rx_ring_order," Rx ring order; size = 1 << order" );
drivers/nvme/host/multipath.c +4 -8
@@ -30,10 +30,8 @@ static int multipath_param_set(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops multipath_param_ops = { - .set = multipath_param_set, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(multipath_param_ops, multipath_param_set, + param_get_bool);module_param_cb (multipath, &multipath_param_ops, &multipath,0444 ); MODULE_PARM_DESC(multipath,
@@ -55,10 +53,8 @@ static int multipath_always_on_set(const char *val,return 0 ; } -static const struct kernel_param_ops multipath_always_on_ops = { - .set = multipath_always_on_set, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(multipath_always_on_ops, multipath_always_on_set, + param_get_bool);module_param_cb (multipath_always_on, &multipath_always_on_ops, &multipath_always_on,0444 );
drivers/nvme/host/pci.c +6 -12
@@ -100,10 +100,8 @@ MODULE_PARM_DESC(sgl_threshold,#define NVME_PCI_MIN_QUEUE_SIZE 2#define NVME_PCI_MAX_QUEUE_SIZE 4095static int io_queue_depth_set (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops io_queue_depth_ops = { - .set = io_queue_depth_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(io_queue_depth_ops, io_queue_depth_set, + param_get_uint);static unsigned int io_queue_depth =1024 ;module_param_cb (io_queue_depth, &io_queue_depth_ops, &io_queue_depth,0644 );
@@ -232,10 +230,8 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp) }static char quirks_param[128 ]; -static const struct kernel_param_ops quirks_param_ops = { - .set = quirks_param_set, - .get = param_get_string, -}; +static DEFINE_KERNEL_PARAM_OPS(quirks_param_ops, quirks_param_set, + param_get_string);static struct kparam_string quirks_param_string = { .maxlen =sizeof (quirks_param),
@@ -257,10 +253,8 @@ static int io_queue_count_set(const char *val, const struct kernel_param *kp)return param_set_uint (val, kp); } -static const struct kernel_param_ops io_queue_count_ops = { - .set = io_queue_count_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(io_queue_count_ops, io_queue_count_set, + param_get_uint);static unsigned int write_queues;module_param_cb (write_queues, &io_queue_count_ops, &write_queues,0644 );
drivers/nvme/target/rdma.c +1 -4
@@ -147,10 +147,7 @@ module_param_named(use_srq, nvmet_rdma_use_srq, bool, 0444);MODULE_PARM_DESC (use_srq,"Use shared receive queue." );static int srq_size_set (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops srq_size_ops = { - .set = srq_size_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(srq_size_ops, srq_size_set, param_get_int);static int nvmet_rdma_srq_size =1024 ;module_param_cb (srq_size, &srq_size_ops, &nvmet_rdma_srq_size,0644 );
drivers/nvme/target/tcp.c +1 -4
@@ -46,10 +46,7 @@ static int set_params(const char *str, const struct kernel_param *kp)return param_store_val (str, kp->arg,0 ,INT_MAX ); } -static const struct kernel_param_ops set_param_ops = { - .set = set_params, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(set_param_ops, set_params, param_get_int);/* Define the socket priority to use for connections were it is desirable * that the NIC consider performing optimized packet processing or filtering.
drivers/platform/x86/acerhdf.c +1 -4
@@ -762,10 +762,7 @@ static int interval_set_uint(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops interval_ops = { - .set = interval_set_uint, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(interval_ops, interval_set_uint, param_get_uint);module_param_cb (interval, &interval_ops, &interval,0000 );MODULE_PARM_DESC (interval,"Polling interval of temperature check" );
drivers/power/supply/bq27xxx_battery.c +2 -4
@@ -1133,10 +1133,8 @@ static int poll_interval_param_set(const char *val, const struct kernel_param *kreturn ret; } -static const struct kernel_param_ops param_ops_poll_interval = { - .get = param_get_uint, - .set = poll_interval_param_set, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_poll_interval, poll_interval_param_set, + param_get_uint);static unsigned int poll_interval =360 ;module_param_cb (poll_interval, ¶m_ops_poll_interval, &poll_interval,0644 );
drivers/power/supply/test_power.c +31 -44
91 lines not on this page · raw message
drivers/scsi/sg.c +2 -4
@@ -1644,10 +1644,8 @@ static int def_reserved_size_set(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops def_reserved_size_ops = { - .set = def_reserved_size_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(def_reserved_size_ops, def_reserved_size_set, + param_get_int);module_param_cb (def_reserved_size, &def_reserved_size_ops, &def_reserved_size,S_IRUGO |S_IWUSR );
drivers/target/target_core_user.c +5 -8
@@ -255,10 +255,9 @@ static int tcmu_get_global_max_data_area(char *buffer,return sprintf (buffer,"%d\n" ,TCMU_PAGES_TO_MBS (tcmu_global_max_pages)); } -static const struct kernel_param_ops tcmu_global_max_data_area_op = { - .set = tcmu_set_global_max_data_area, - .get = tcmu_get_global_max_data_area, -}; +static DEFINE_KERNEL_PARAM_OPS(tcmu_global_max_data_area_op, + tcmu_set_global_max_data_area, + tcmu_get_global_max_data_area);module_param_cb (global_max_data_area_mb, &tcmu_global_max_data_area_op,NULL ,S_IWUSR |S_IRUGO );
@@ -292,10 +291,8 @@ static int tcmu_set_block_netlink(const char *str,return 0 ; } -static const struct kernel_param_ops tcmu_block_netlink_op = { - .set = tcmu_set_block_netlink, - .get = tcmu_get_block_netlink, -}; +static DEFINE_KERNEL_PARAM_OPS(tcmu_block_netlink_op, tcmu_set_block_netlink, + tcmu_get_block_netlink);module_param_cb (block_netlink, &tcmu_block_netlink_op,NULL ,S_IWUSR |S_IRUGO );MODULE_PARM_DESC (block_netlink,"Block new netlink commands." );
drivers/thermal/intel/int340x_thermal/processor_thermal_soc_slider.c +4 -8
@@ -83,10 +83,8 @@ static int slider_def_balance_get(char *buf, const struct kernel_param *kp)return sysfs_emit (buf,"%02x\n" , slider_values[SOC_POWER_SLIDER_BALANCE ]); } -static const struct kernel_param_ops slider_def_balance_ops = { - .set = slider_def_balance_set, - .get = slider_def_balance_get, -}; +static DEFINE_KERNEL_PARAM_OPS(slider_def_balance_ops, slider_def_balance_set, + slider_def_balance_get);module_param_cb (slider_balance, &slider_def_balance_ops,NULL ,0644 );MODULE_PARM_DESC (slider_balance,"Set slider default value for balance" );
@@ -117,10 +115,8 @@ static int slider_def_offset_get(char *buf, const struct kernel_param *kp)return sysfs_emit (buf,"%02x\n" , slider_offset); } -static const struct kernel_param_ops slider_offset_ops = { - .set = slider_def_offset_set, - .get = slider_def_offset_get, -}; +static DEFINE_KERNEL_PARAM_OPS(slider_offset_ops, slider_def_offset_set, + slider_def_offset_get);/* * To enhance power efficiency dynamically, the firmware can optionally
drivers/thermal/intel/intel_powerclamp.c +4 -16
@@ -112,10 +112,7 @@ static int duration_get(char *buf, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops duration_ops = { - .set = duration_set, - .get = duration_get, -}; +static DEFINE_KERNEL_PARAM_OPS(duration_ops, duration_set, duration_get);module_param_cb (duration, &duration_ops,NULL ,0644 );MODULE_PARM_DESC (duration,"forced idle time for each attempt in msec." );
@@ -203,10 +200,7 @@ static int cpumask_get(char *buf, const struct kernel_param *kp)return cpumap_print_to_pagebuf (false, buf, idle_injection_cpu_mask); } -static const struct kernel_param_ops cpumask_ops = { - .set = cpumask_set, - .get = cpumask_get, -}; +static DEFINE_KERNEL_PARAM_OPS(cpumask_ops, cpumask_set, cpumask_get);module_param_cb (cpumask, &cpumask_ops,NULL ,0644 );MODULE_PARM_DESC (cpumask,"Mask of CPUs to use for idle injection." );
@@ -252,10 +246,7 @@ static int max_idle_set(const char *arg, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops max_idle_ops = { - .set = max_idle_set, - .get = param_get_byte, -}; +static DEFINE_KERNEL_PARAM_OPS(max_idle_ops, max_idle_set, param_get_byte);module_param_cb (max_idle, &max_idle_ops, &max_idle,0644 );MODULE_PARM_DESC (max_idle,"maximum injected idle time to the total CPU time ratio in percent range:1-100" );
@@ -299,10 +290,7 @@ static int window_size_set(const char *arg, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops window_size_ops = { - .set = window_size_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(window_size_ops, window_size_set, param_get_int);module_param_cb (window_size, &window_size_ops, &window_size,0644 ); MODULE_PARM_DESC(window_size, "sliding window in number of clamping cycles\n"
drivers/tty/hvc/hvc_iucv.c +2 -4
@@ -1290,10 +1290,8 @@ static int param_get_vmidfilter(char *buffer, const struct kernel_param *kp)#define param_check_vmidfilter (name, p) __param_check(name, p, void) -static const struct kernel_param_ops param_ops_vmidfilter = { - .set = param_set_vmidfilter, - .get = param_get_vmidfilter, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_vmidfilter, param_set_vmidfilter, + param_get_vmidfilter);/** * hvc_iucv_init() - z/VM IUCV HVC device driver initialization
drivers/tty/sysrq.c +2 -4
@@ -1074,10 +1074,8 @@ static int sysrq_reset_seq_param_set(const char *buffer,return 0 ; } -static const struct kernel_param_ops param_ops_sysrq_reset_seq = { - .get = param_get_ushort, - .set = sysrq_reset_seq_param_set, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_sysrq_reset_seq, + sysrq_reset_seq_param_set, param_get_ushort);#define param_check_sysrq_reset_seq (name, p) \ __param_check(name, p, unsigned short)
drivers/ufs/core/ufs-fault-injection.c +1 -4
@@ -11,10 +11,7 @@static int ufs_fault_get (char *buffer,const struct kernel_param *kp);static int ufs_fault_set (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops ufs_fault_ops = { - .get = ufs_fault_get, - .set = ufs_fault_set, -}; +static DEFINE_KERNEL_PARAM_OPS(ufs_fault_ops, ufs_fault_set, ufs_fault_get);enum {FAULT_INJ_STR_SIZE =80 };
drivers/ufs/core/ufs-mcq.c +6 -12
@@ -43,10 +43,8 @@ static int rw_queue_count_set(const char *val, const struct kernel_param *kp) num_possible_cpus()); } -static const struct kernel_param_ops rw_queue_count_ops = { - .set = rw_queue_count_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(rw_queue_count_ops, rw_queue_count_set, + param_get_uint);static unsigned int rw_queues;module_param_cb (rw_queues, &rw_queue_count_ops, &rw_queues,0644 );
@@ -59,10 +57,8 @@ static int read_queue_count_set(const char *val, const struct kernel_param *kp) num_possible_cpus()); } -static const struct kernel_param_ops read_queue_count_ops = { - .set = read_queue_count_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(read_queue_count_ops, read_queue_count_set, + param_get_uint);static unsigned int read_queues;module_param_cb (read_queues, &read_queue_count_ops, &read_queues,0644 );
@@ -75,10 +71,8 @@ static int poll_queue_count_set(const char *val, const struct kernel_param *kp) num_possible_cpus()); } -static const struct kernel_param_ops poll_queue_count_ops = { - .set = poll_queue_count_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(poll_queue_count_ops, poll_queue_count_set, + param_get_uint);static unsigned int poll_queues =1 ;module_param_cb (poll_queues, &poll_queue_count_ops, &poll_queues,0644 );
drivers/ufs/core/ufs-txeq.c +1 -4
@@ -23,10 +23,7 @@ static int txeq_gear_set(const char *val, const struct kernel_param *kp)return param_set_uint_minmax (val, kp,UFS_HS_G1 ,UFS_HS_GEAR_MAX ); } -static const struct kernel_param_ops txeq_gear_ops = { - .set = txeq_gear_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(txeq_gear_ops, txeq_gear_set, param_get_uint);static unsigned int adaptive_txeq_gear =UFS_HS_G6 ;module_param_cb (adaptive_txeq_gear, &txeq_gear_ops, &adaptive_txeq_gear,0644 );
drivers/ufs/core/ufshcd.c +4 -8
@@ -128,10 +128,8 @@ static int uic_cmd_timeout_set(const char *val, const struct kernel_param *kp) UIC_CMD_TIMEOUT_MAX); } -static const struct kernel_param_ops uic_cmd_timeout_ops = { - .set = uic_cmd_timeout_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(uic_cmd_timeout_ops, uic_cmd_timeout_set, + param_get_uint);module_param_cb (uic_cmd_timeout, &uic_cmd_timeout_ops, &uic_cmd_timeout,0644 ); MODULE_PARM_DESC(uic_cmd_timeout,
@@ -145,10 +143,8 @@ static int dev_cmd_timeout_set(const char *val, const struct kernel_param *kp) QUERY_REQ_TIMEOUT_MAX); } -static const struct kernel_param_ops dev_cmd_timeout_ops = { - .set = dev_cmd_timeout_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(dev_cmd_timeout_ops, dev_cmd_timeout_set, + param_get_uint);module_param_cb (dev_cmd_timeout, &dev_cmd_timeout_ops, &dev_cmd_timeout,0644 ); MODULE_PARM_DESC(dev_cmd_timeout,
drivers/usb/core/quirks.c +2 -4
@@ -160,10 +160,8 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops quirks_param_ops = { - .set = quirks_param_set, - .get = param_get_string, -}; +static DEFINE_KERNEL_PARAM_OPS(quirks_param_ops, quirks_param_set, + param_get_string);static struct kparam_string quirks_param_string = { .maxlen =sizeof (quirks_param),
drivers/usb/gadget/legacy/serial.c +1 -4
@@ -121,10 +121,7 @@ static int enable_set(const char *s, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops enable_ops = { - .set = enable_set, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(enable_ops, enable_set, param_get_bool);module_param_cb (enable, &enable_ops, &enable,0644 );
drivers/usb/storage/usb.c +1 -4
@@ -158,10 +158,7 @@ static int delay_use_get(char *s, const struct kernel_param *kp)return format_delay_ms (delay_ms,3 ,"ms" , s,PAGE_SIZE ); } -static const struct kernel_param_ops delay_use_ops = { - .set = delay_use_set, - .get = delay_use_get, -}; +static DEFINE_KERNEL_PARAM_OPS(delay_use_ops, delay_use_set, delay_use_get);module_param_cb (delay_use, &delay_use_ops, &delay_use,0644 );MODULE_PARM_DESC (delay_use,"time to delay before using a new device" );
drivers/vhost/scsi.c +3 -4
@@ -87,10 +87,9 @@ static int vhost_scsi_get_inline_sg_cnt(char *buf,return sprintf (buf,"%u\n" , vhost_scsi_inline_sg_cnt); } -static const struct kernel_param_ops vhost_scsi_inline_sg_cnt_op = { - .get = vhost_scsi_get_inline_sg_cnt, - .set = vhost_scsi_set_inline_sg_cnt, -}; +static DEFINE_KERNEL_PARAM_OPS(vhost_scsi_inline_sg_cnt_op, + vhost_scsi_set_inline_sg_cnt, + vhost_scsi_get_inline_sg_cnt);module_param_cb (inline_sg_cnt, &vhost_scsi_inline_sg_cnt_op,NULL ,0644 );MODULE_PARM_DESC (inline_sg_cnt,"Set the number of scatterlist entries to pre-allocate. The default is 2048." );
drivers/virt/nitro_enclaves/ne_misc_dev.c +2 -4
@@ -86,10 +86,8 @@ struct ne_devs ne_devs = {*/ static int ne_set_kernel_param (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops ne_cpu_pool_ops = { - .get = param_get_string, - .set = ne_set_kernel_param, -}; +static DEFINE_KERNEL_PARAM_OPS(ne_cpu_pool_ops, ne_set_kernel_param, + param_get_string);static char ne_cpus[NE_CPUS_SIZE ];static struct kparam_string ne_cpus_arg = {
drivers/virtio/virtio_mmio.c +2 -4
@@ -748,10 +748,8 @@ static int vm_cmdline_get(char *buffer, const struct kernel_param *kp)return strlen (buffer) +1 ; } -static const struct kernel_param_ops vm_cmdline_param_ops = { - .set = vm_cmdline_set, - .get = vm_cmdline_get, -}; +static DEFINE_KERNEL_PARAM_OPS(vm_cmdline_param_ops, vm_cmdline_set, + vm_cmdline_get);device_param_cb (device, &vm_cmdline_param_ops,NULL ,S_IRUSR );
fs/ceph/super.c +3 -7
@@ -1684,10 +1684,8 @@ static int param_set_metrics(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops param_ops_metrics = { - .set = param_set_metrics, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_metrics, param_set_metrics, + param_get_bool);bool disable_send_metrics = false;module_param_cb (disable_send_metrics, ¶m_ops_metrics, &disable_send_metrics,0644 );
@@ -1695,9 +1693,7 @@ MODULE_PARM_DESC(disable_send_metrics, "Enable sending perf metrics to ceph clus/* for both v1 and v2 syntax */ static bool mount_support = true; -static const struct kernel_param_ops param_ops_mount_syntax = { - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_mount_syntax, NULL, param_get_bool);module_param_cb (mount_syntax_v1, ¶m_ops_mount_syntax, &mount_support,0444 );module_param_cb (mount_syntax_v2, ¶m_ops_mount_syntax, &mount_support,0444 );
fs/fuse/dir.c +1 -4
@@ -71,10 +71,7 @@ static int inval_wq_set(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops inval_wq_ops = { - .set = inval_wq_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(inval_wq_ops, inval_wq_set, param_get_uint);module_param_cb (inval_wq, &inval_wq_ops, &inval_wq,0644 );__MODULE_PARM_TYPE (inval_wq,"uint" ); MODULE_PARM_DESC(inval_wq,
fs/nfs/namespace.c +2 -4
@@ -372,10 +372,8 @@ static int param_get_nfs_timeout(char *buffer, const struct kernel_param *kp)return sysfs_emit (buffer,"%li\n" , num); } -static const struct kernel_param_ops param_ops_nfs_timeout = { - .set = param_set_nfs_timeout, - .get = param_get_nfs_timeout, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_nfs_timeout, param_set_nfs_timeout, + param_get_nfs_timeout);#define param_check_nfs_timeout (name, p) __param_check(name, p, int)module_param (nfs_mountpoint_expiry_timeout, nfs_timeout,0644 );
fs/nfs/super.c +2 -4
@@ -1419,10 +1419,8 @@ static int param_set_portnr(const char *val, const struct kernel_param *kp) *((unsigned int *)kp->arg) = num;return 0 ; } -static const struct kernel_param_ops param_ops_portnr = { - .set = param_set_portnr, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_portnr, param_set_portnr, + param_get_uint);#define param_check_portnr (name, p) __param_check(name, p, unsigned int)module_param_named (callback_tcpport, nfs_callback_set_tcpport, portnr,0644 );
fs/ubifs/super.c +2 -4
@@ -36,10 +36,8 @@ static int ubifs_default_version_set(const char *val, const struct kernel_paramreturn param_set_int (val, kp); } -static const struct kernel_param_ops ubifs_default_version_ops = { - .set = ubifs_default_version_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(ubifs_default_version_ops, + ubifs_default_version_set, param_get_int);int ubifs_default_version =UBIFS_FORMAT_VERSION ;module_param_cb (default_version, &ubifs_default_version_ops, &ubifs_default_version,0600 );
kernel/locking/locktorture.c +2 -4
@@ -98,10 +98,8 @@ static bool cpumask_nonempty(cpumask_var_t mask)return cpumask_available (mask) && !cpumask_empty (mask); } -static const struct kernel_param_ops lt_bind_ops = { - .set = param_set_cpumask, - .get = param_get_cpumask, -}; +static DEFINE_KERNEL_PARAM_OPS(lt_bind_ops, param_set_cpumask, + param_get_cpumask);module_param_cb (bind_readers, <_bind_ops, &bind_readers,0444 );module_param_cb (bind_writers, <_bind_ops, &bind_writers,0444 );
kernel/panic.c +2 -4
@@ -1214,10 +1214,8 @@ static int panic_print_set(const char *val, const struct kernel_param *kp)return param_set_ulong (val, kp); } -static const struct kernel_param_ops panic_print_ops = { - .set = panic_print_set, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(panic_print_ops, panic_print_set, + param_get_ulong);__core_param_cb (panic_print, &panic_print_ops, &panic_print,0644 );static int __init oops_setup (char *s)
kernel/params.c +11 -33
86 lines not on this page · raw message
kernel/power/hibernate.c +2 -4
@@ -1528,10 +1528,8 @@ static int hibernate_compressor_param_set(const char *compressor,return ret; } -static const struct kernel_param_ops hibernate_compressor_param_ops = { - .set = hibernate_compressor_param_set, - .get = param_get_string, -}; +static DEFINE_KERNEL_PARAM_OPS(hibernate_compressor_param_ops, + hibernate_compressor_param_set, param_get_string);static struct kparam_string hibernate_compressor_param_string = { .maxlen =sizeof (hibernate_compressor),
kernel/rcu/tree.c +6 -12
@@ -498,15 +498,11 @@ static int param_set_next_fqs_jiffies(const char *val, const struct kernel_paramreturn ret; } -static const struct kernel_param_ops first_fqs_jiffies_ops = { - .set = param_set_first_fqs_jiffies, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(first_fqs_jiffies_ops, + param_set_first_fqs_jiffies, param_get_ulong); -static const struct kernel_param_ops next_fqs_jiffies_ops = { - .set = param_set_next_fqs_jiffies, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(next_fqs_jiffies_ops, param_set_next_fqs_jiffies, + param_get_ulong);module_param_cb (jiffies_till_first_fqs, &first_fqs_jiffies_ops, &jiffies_till_first_fqs,0644 );module_param_cb (jiffies_till_next_fqs, &next_fqs_jiffies_ops, &jiffies_till_next_fqs,0644 );
@@ -3979,10 +3975,8 @@ static int param_get_do_rcu_barrier(char *buffer, const struct kernel_param *kp)return sprintf (buffer,"%d\n" ,atomic_read ((atomic_t *)kp->arg)); } -static const struct kernel_param_ops do_rcu_barrier_ops = { - .set = param_set_do_rcu_barrier, - .get = param_get_do_rcu_barrier, -}; +static DEFINE_KERNEL_PARAM_OPS(do_rcu_barrier_ops, param_set_do_rcu_barrier, + param_get_do_rcu_barrier);static atomic_t do_rcu_barrier;module_param_cb (do_rcu_barrier, &do_rcu_barrier_ops, &do_rcu_barrier,0644 );
kernel/sched/ext.c +3 -8
@@ -166,20 +166,15 @@ static int set_slice_us(const char *val, const struct kernel_param *kp)return param_set_uint_minmax (val, kp,100 ,100 *USEC_PER_MSEC ); } -static const struct kernel_param_ops slice_us_param_ops = { - .set = set_slice_us, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(slice_us_param_ops, set_slice_us, param_get_uint);static int set_bypass_lb_intv_us (const char *val,const struct kernel_param *kp) {return param_set_uint_minmax (val, kp,0 ,10 *USEC_PER_SEC ); } -static const struct kernel_param_ops bypass_lb_intv_us_param_ops = { - .set = set_bypass_lb_intv_us, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(bypass_lb_intv_us_param_ops, + set_bypass_lb_intv_us, param_get_uint);#undef MODULE_PARAM_PREFIX#define MODULE_PARAM_PREFIX "sched_ext."
kernel/workqueue.c +4 -8
@@ -7162,10 +7162,8 @@ static int wq_affn_dfl_get(char *buffer, const struct kernel_param *kp)return scnprintf (buffer,PAGE_SIZE ,"%s\n" , wq_affn_names[wq_affn_dfl]); } -static const struct kernel_param_ops wq_affn_dfl_ops = { - .set = wq_affn_dfl_set, - .get = wq_affn_dfl_get, -}; +static DEFINE_KERNEL_PARAM_OPS(wq_affn_dfl_ops, wq_affn_dfl_set, + wq_affn_dfl_get);module_param_cb (default_affinity_scope, &wq_affn_dfl_ops,NULL ,0644 );
@@ -7861,10 +7859,8 @@ static int wq_watchdog_param_set_thresh(const char *val,return 0 ; } -static const struct kernel_param_ops wq_watchdog_thresh_ops = { - .set = wq_watchdog_param_set_thresh, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(wq_watchdog_thresh_ops, + wq_watchdog_param_set_thresh, param_get_ulong);module_param_cb (watchdog_thresh, &wq_watchdog_thresh_ops, &wq_watchdog_thresh,0644 );
lib/dynamic_debug.c +2 -4
@@ -807,10 +807,8 @@ int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp) }EXPORT_SYMBOL (param_get_dyndbg_classes); -const struct kernel_param_ops param_ops_dyndbg_classes = { - .set = param_set_dyndbg_classes, - .get = param_get_dyndbg_classes, -}; +DEFINE_KERNEL_PARAM_OPS (param_ops_dyndbg_classes, param_set_dyndbg_classes, + param_get_dyndbg_classes);EXPORT_SYMBOL (param_ops_dyndbg_classes);#define PREFIX_SIZE 128
lib/test_dynamic_debug.c +2 -4
@@ -23,10 +23,8 @@ static int param_get_do_prints(char *buffer, const struct kernel_param *kp)do_prints ();return scnprintf (buffer,PAGE_SIZE ,"did do_prints\n" ); } -static const struct kernel_param_ops param_ops_do_prints = { - .set = param_set_do_prints, - .get = param_get_do_prints, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_do_prints, param_set_do_prints, + param_get_do_prints);module_param_cb (do_prints, ¶m_ops_do_prints,NULL ,0600 );/*
mm/damon/lru_sort.c +7 -12
@@ -405,10 +405,8 @@ static int damon_lru_sort_addr_unit_store(const char *val,return 0 ; } -static const struct kernel_param_ops addr_unit_param_ops = { - .set = damon_lru_sort_addr_unit_store, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(addr_unit_param_ops, + damon_lru_sort_addr_unit_store, param_get_ulong);module_param_cb (addr_unit, &addr_unit_param_ops, &addr_unit,0600 ); MODULE_PARM_DESC(addr_unit,
@@ -446,10 +444,8 @@ static int damon_lru_sort_enabled_load(char *buffer,return sprintf (buffer,"%c\n" ,damon_lru_sort_enabled () ?'Y' :'N' ); } -static const struct kernel_param_ops enabled_param_ops = { - .set = damon_lru_sort_enabled_store, - .get = damon_lru_sort_enabled_load, -}; +static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, damon_lru_sort_enabled_store, + damon_lru_sort_enabled_load);module_param_cb (enabled, &enabled_param_ops, &enabled,0600 ); MODULE_PARM_DESC(enabled,
@@ -478,10 +474,9 @@ static int damon_lru_sort_kdamond_pid_load(char *buffer,return sprintf (buffer,"%d\n" , kdamond_pid); } -static const struct kernel_param_ops kdamond_pid_param_ops = { - .set = damon_lru_sort_kdamond_pid_store, - .get = damon_lru_sort_kdamond_pid_load, -}; +static DEFINE_KERNEL_PARAM_OPS(kdamond_pid_param_ops, + damon_lru_sort_kdamond_pid_store, + damon_lru_sort_kdamond_pid_load);/* * PID of the DAMON thread
mm/damon/reclaim.c +7 -12
@@ -307,10 +307,8 @@ static int damon_reclaim_addr_unit_store(const char *val,return 0 ; } -static const struct kernel_param_ops addr_unit_param_ops = { - .set = damon_reclaim_addr_unit_store, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(addr_unit_param_ops, + damon_reclaim_addr_unit_store, param_get_ulong);module_param_cb (addr_unit, &addr_unit_param_ops, &addr_unit,0600 ); MODULE_PARM_DESC(addr_unit,
@@ -348,10 +346,8 @@ static int damon_reclaim_enabled_load(char *buffer,return sprintf (buffer,"%c\n" ,damon_reclaim_enabled () ?'Y' :'N' ); } -static const struct kernel_param_ops enabled_param_ops = { - .set = damon_reclaim_enabled_store, - .get = damon_reclaim_enabled_load, -}; +static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, damon_reclaim_enabled_store, + damon_reclaim_enabled_load);module_param_cb (enabled, &enabled_param_ops, &enabled,0600 ); MODULE_PARM_DESC(enabled,
@@ -380,10 +376,9 @@ static int damon_reclaim_kdamond_pid_load(char *buffer,return sprintf (buffer,"%d\n" , kdamond_pid); } -static const struct kernel_param_ops kdamond_pid_param_ops = { - .set = damon_reclaim_kdamond_pid_store, - .get = damon_reclaim_kdamond_pid_load, -}; +static DEFINE_KERNEL_PARAM_OPS(kdamond_pid_param_ops, + damon_reclaim_kdamond_pid_store, + damon_reclaim_kdamond_pid_load);/* * PID of the DAMON thread
mm/damon/stat.c +2 -4
@@ -22,10 +22,8 @@ static int damon_stat_enabled_store(static int damon_stat_enabled_load (char *buffer,const struct kernel_param *kp); -static const struct kernel_param_ops enabled_param_ops = { - .set = damon_stat_enabled_store, - .get = damon_stat_enabled_load, -}; +static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, damon_stat_enabled_store, + damon_stat_enabled_load);static bool enabled__read_mostly =IS_ENABLED (CONFIG_DAMON_STAT_ENABLED_DEFAULT );
mm/memory_hotplug.c +4 -8
@@ -109,10 +109,8 @@ static int get_memmap_mode(char *buffer, const struct kernel_param *kp)return sprintf (buffer,"%c\n" , mode ?'Y' :'N' ); } -static const struct kernel_param_ops memmap_mode_ops = { - .set = set_memmap_mode, - .get = get_memmap_mode, -}; +static DEFINE_KERNEL_PARAM_OPS(memmap_mode_ops, set_memmap_mode, + get_memmap_mode);module_param_cb (memmap_on_memory, &memmap_mode_ops, &memmap_mode,0444 );MODULE_PARM_DESC (memmap_on_memory,"Enable memmap on memory for memory hotplug\n" "With value \"force\" it could result in memory wastage due "
@@ -163,10 +161,8 @@ static int get_online_policy(char *buffer, const struct kernel_param *kp)* (auto_movable_ratio, auto_movable_numa_aware) allows for it */ static int online_policy__read_mostly =ONLINE_POLICY_CONTIG_ZONES ; -static const struct kernel_param_ops online_policy_ops = { - .set = set_online_policy, - .get = get_online_policy, -}; +static DEFINE_KERNEL_PARAM_OPS(online_policy_ops, set_online_policy, + get_online_policy);module_param_cb (online_policy, &online_policy_ops, &online_policy,0644 );MODULE_PARM_DESC (online_policy, "Set the online policy (\"contig-zones\", \"auto-movable\") "
mm/page_reporting.c +2 -9
@@ -23,15 +23,8 @@ static int page_order_update_notify(const char *val, const struct kernel_param *return param_set_uint_minmax (val, kp,0 ,MAX_PAGE_ORDER ); } -static const struct kernel_param_ops page_reporting_param_ops = { - .set = &page_order_update_notify, -/* -* For the get op, use param_get_int instead of param_get_uint. -* This is to make sure that when unset the initialized value of -* -1 is shown correctly -*/ - .get = ¶m_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(page_reporting_param_ops, + &page_order_update_notify, ¶m_get_int);module_param_cb (page_reporting_order, &page_reporting_param_ops, &page_reporting_order,0644 );
mm/shuffle.c +2 -4
@@ -23,10 +23,8 @@ static __meminit int shuffle_param_set(const char *val,return 0 ; } -static const struct kernel_param_ops shuffle_param_ops = { - .set = shuffle_param_set, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(shuffle_param_ops, shuffle_param_set, + param_get_bool);module_param_cb (shuffle, &shuffle_param_ops, &shuffle_param,0400 );/*
mm/zswap.c +5 -9
@@ -90,21 +90,17 @@ static DEFINE_STATIC_KEY_MAYBE(CONFIG_ZSWAP_DEFAULT_ON, zswap_ever_enabled);static bool zswap_enabled =IS_ENABLED (CONFIG_ZSWAP_DEFAULT_ON );static int zswap_enabled_param_set (const char *,const struct kernel_param *); -static const struct kernel_param_ops zswap_enabled_param_ops = { - .set = zswap_enabled_param_set, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(zswap_enabled_param_ops, zswap_enabled_param_set, + param_get_bool);module_param_cb (enabled, &zswap_enabled_param_ops, &zswap_enabled,0644 );/* Crypto compressor to use */ static char *zswap_compressor =CONFIG_ZSWAP_COMPRESSOR_DEFAULT ;static int zswap_compressor_param_set (const char *,const struct kernel_param *); -static const struct kernel_param_ops zswap_compressor_param_ops = { - .set = zswap_compressor_param_set, - .get = param_get_charp, - .free = param_free_charp, -}; +static DEFINE_KERNEL_PARAM_OPS_FREE(zswap_compressor_param_ops, + zswap_compressor_param_set, param_get_charp, + param_free_charp);module_param_cb (compressor, &zswap_compressor_param_ops, &zswap_compressor,0644 );
net/batman-adv/bat_algo.c +2 -4
@@ -134,10 +134,8 @@ static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)return param_set_copystring (algo_name, kp); } -static const struct kernel_param_ops batadv_param_ops_ra = { - .set = batadv_param_set_ra, - .get = param_get_string, -}; +static DEFINE_KERNEL_PARAM_OPS(batadv_param_ops_ra, batadv_param_set_ra, + param_get_string);static struct kparam_string batadv_param_string_ra = { .maxlen =sizeof (batadv_routing_algo),
net/ceph/ceph_common.c +2 -3
@@ -52,9 +52,8 @@ static int param_get_supported_features(char *buffer, {return sprintf (buffer,"0x%llx" ,CEPH_FEATURES_SUPPORTED_DEFAULT ); } -static const struct kernel_param_ops param_ops_supported_features = { - .get = param_get_supported_features, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_supported_features, NULL, + param_get_supported_features);module_param_cb (supported_features, ¶m_ops_supported_features,NULL ,0444 );
net/ipv4/tcp_dctcp.c +2 -4
@@ -64,10 +64,8 @@ static int dctcp_shift_g_set(const char *val, const struct kernel_param *kp)return param_set_uint_minmax (val, kp,0 ,10 ); } -static const struct kernel_param_ops dctcp_shift_g_ops = { - .set = dctcp_shift_g_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(dctcp_shift_g_ops, dctcp_shift_g_set, + param_get_uint);module_param_cb (dctcp_shift_g, &dctcp_shift_g_ops, &dctcp_shift_g,0644 );MODULE_PARM_DESC (dctcp_shift_g,"parameter g for updating dctcp_alpha" );
net/sunrpc/auth.c +2 -4
@@ -83,10 +83,8 @@ static int param_get_hashtbl_sz(char *buffer, const struct kernel_param *kp)#define param_check_hashtbl_sz (name, p) __param_check(name, p, unsigned int); -static const struct kernel_param_ops param_ops_hashtbl_sz = { - .set = param_set_hashtbl_sz, - .get = param_get_hashtbl_sz, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_hashtbl_sz, param_set_hashtbl_sz, + param_get_hashtbl_sz);module_param_named (auth_hashtable_size, auth_hashbits, hashtbl_sz,0644 );MODULE_PARM_DESC (auth_hashtable_size,"RPC credential cache hashtable size" );
net/sunrpc/xprtsock.c +6 -12
@@ -3710,10 +3710,8 @@ static int param_set_portnr(const char *val, const struct kernel_param *kp) RPC_MAX_RESVPORT); } -static const struct kernel_param_ops param_ops_portnr = { - .set = param_set_portnr, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_portnr, param_set_portnr, + param_get_uint);#define param_check_portnr (name, p) \ __param_check(name, p, unsigned int);
@@ -3729,10 +3727,8 @@ static int param_set_slot_table_size(const char *val, RPC_MAX_SLOT_TABLE); } -static const struct kernel_param_ops param_ops_slot_table_size = { - .set = param_set_slot_table_size, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_slot_table_size, + param_set_slot_table_size, param_get_uint);#define param_check_slot_table_size (name, p) \ __param_check(name, p, unsigned int);
@@ -3745,10 +3741,8 @@ static int param_set_max_slot_table_size(const char *val, RPC_MAX_SLOT_TABLE_LIMIT); } -static const struct kernel_param_ops param_ops_max_slot_table_size = { - .set = param_set_max_slot_table_size, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_max_slot_table_size, + param_set_max_slot_table_size, param_get_uint);#define param_check_max_slot_table_size (name, p) \ __param_check(name, p, unsigned int);
samples/damon/mtier.c +2 -4
@@ -38,10 +38,8 @@ module_param(node0_mem_free_bp, ulong, 0600);static int damon_sample_mtier_enable_store (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops enabled_param_ops = { - .set = damon_sample_mtier_enable_store, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, + damon_sample_mtier_enable_store, param_get_bool);static bool enabled__read_mostly ;module_param_cb (enabled, &enabled_param_ops, &enabled,0600 );
samples/damon/prcl.c +2 -4
@@ -22,10 +22,8 @@ module_param(target_pid, int, 0600);static int damon_sample_prcl_enable_store (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops enabled_param_ops = { - .set = damon_sample_prcl_enable_store, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, + damon_sample_prcl_enable_store, param_get_bool);static bool enabled__read_mostly ;module_param_cb (enabled, &enabled_param_ops, &enabled,0600 );
samples/damon/wsse.c +2 -4
@@ -23,10 +23,8 @@ module_param(target_pid, int, 0600);static int damon_sample_wsse_enable_store (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops enabled_param_ops = { - .set = damon_sample_wsse_enable_store, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, + damon_sample_wsse_enable_store, param_get_bool);static bool enabled__read_mostly ;module_param_cb (enabled, &enabled_param_ops, &enabled,0600 );
security/apparmor/lsm.c +12 -22
@@ -1767,38 +1767,30 @@ static struct security_hook_list apparmor_hooks[] __ro_after_init = {static int param_set_aabool (const char *val,const struct kernel_param *kp);static int param_get_aabool (char *buffer,const struct kernel_param *kp);#define param_check_aabool param_check_bool -static const struct kernel_param_ops param_ops_aabool = { - .flags =KERNEL_PARAM_OPS_FL_NOARG , - .set = param_set_aabool, - .get = param_get_aabool -}; +static DEFINE_KERNEL_PARAM_OPS_NOARG(param_ops_aabool, param_set_aabool, + param_get_aabool);static int param_set_aauint (const char *val,const struct kernel_param *kp);static int param_get_aauint (char *buffer,const struct kernel_param *kp);#define param_check_aauint param_check_uint -static const struct kernel_param_ops param_ops_aauint = { - .set = param_set_aauint, - .get = param_get_aauint -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_aauint, param_set_aauint, + param_get_aauint);static int param_set_aacompressionlevel (const char *val,const struct kernel_param *kp);static int param_get_aacompressionlevel (char *buffer,const struct kernel_param *kp);#define param_check_aacompressionlevel param_check_int -static const struct kernel_param_ops param_ops_aacompressionlevel = { - .set = param_set_aacompressionlevel, - .get = param_get_aacompressionlevel -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_aacompressionlevel, + param_set_aacompressionlevel, + param_get_aacompressionlevel);static int param_set_aalockpolicy (const char *val,const struct kernel_param *kp);static int param_get_aalockpolicy (char *buffer,const struct kernel_param *kp);#define param_check_aalockpolicy param_check_bool -static const struct kernel_param_ops param_ops_aalockpolicy = { - .flags =KERNEL_PARAM_OPS_FL_NOARG , - .set = param_set_aalockpolicy, - .get = param_get_aalockpolicy -}; +static DEFINE_KERNEL_PARAM_OPS_NOARG(param_ops_aalockpolicy, + param_set_aalockpolicy, + param_get_aalockpolicy);static int param_set_debug (const char *val,const struct kernel_param *kp);static int param_get_debug (char *buffer,const struct kernel_param *kp);
@@ -1879,10 +1871,8 @@ module_param_named(paranoid_load, aa_g_paranoid_load, aabool, S_IRUGO);static int param_get_aaintbool (char *buffer,const struct kernel_param *kp);static int param_set_aaintbool (const char *val,const struct kernel_param *kp);#define param_check_aaintbool param_check_int -static const struct kernel_param_ops param_ops_aaintbool = { - .set = param_set_aaintbool, - .get = param_get_aaintbool -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_aaintbool, param_set_aaintbool, + param_get_aaintbool);/* Boot time disable flag */ static int apparmor_enabled__ro_after_init =1 ;module_param_named (enabled, apparmor_enabled, aaintbool,0444 );
sound/hda/controllers/intel.c +1 -4
@@ -164,10 +164,7 @@ MODULE_PARM_DESC(ctl_dev_id, "Use control device identifier (based on codec addr#ifdef CONFIG_PM static int param_set_xint (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops param_ops_xint = { - .set = param_set_xint, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_xint, param_set_xint, param_get_int);#define param_check_xint param_check_intstatic int power_save =CONFIG_SND_HDA_POWER_SAVE_DEFAULT ;
sound/usb/card.c +2 -5
@@ -118,11 +118,8 @@ static int param_set_quirkp(const char *val,return param_set_charp (val, kp); } -static const struct kernel_param_ops param_ops_quirkp = { - .set = param_set_quirkp, - .get = param_get_charp, - .free = param_free_charp, -}; +static DEFINE_KERNEL_PARAM_OPS_FREE(param_ops_quirkp, param_set_quirkp, + param_get_charp, param_free_charp);#define param_check_quirkp param_check_charp
Signature · 1 line
2.34.1
Sean Christopherson
maintainerRe: [PATCH 04/11] treewide: Convert struct kernel_param_ops initializers to DEFINE_KERNEL_PARAM_OPS
Quoted 10 lines · Kees Cook
Using Coccinelle, rewrite every struct
kernel_param_opsinitializer that sets .get into a DEFINE_KERNEL_PARAM_OPS-family macro invocation, for example:@@
declarer nameDEFINE_KERNEL_PARAM_OPS;
identifier OPS;
expression SET, GET;
@@
- const structkernel_param_opsOPS = {
Review
Quoted 4 lines
(quoted diff) +1
-3- .set = SET, - .get = GET, - }; + DEFINE_KERNEL_PARAM_OPS(OPS, SET, GET);
IMO, "OPS, GET, SET" is more intuitive, especially since that's the order used by DEFINE_SIMPLE_ATTRIBUTE and DEFINE_DEBUGFS_ATTRIBUTE.
Re: [PATCH 04/11] treewide: Convert struct kernel_param_ops initializers to DEFINE_KERNEL_PARAM_OPS
In reply to Kees CookQuoted 16 lines · Kees Cook
Using Coccinelle, rewrite every struct
kernel_param_opsinitializer that sets .get into a DEFINE_KERNEL_PARAM_OPS-family macro invocation, for example:@@
declarer nameDEFINE_KERNEL_PARAM_OPS;
identifier OPS;
expression SET, GET;
@@
- const structkernel_param_opsOPS = {(quoted diff) +1
-3- .set = SET, - .get = GET, - }; + DEFINE_KERNEL_PARAM_OPS(OPS, SET, GET);
Quoted 5 lines
Using the macro for initialization means future changes can manipulate the struct layout and callback prototypes without having to change every initializer.
Signed-off-by Kees Cook <[email protected]>
For ACPI and hibernation:
Quoted 2,480 lines
--- mm/kfence/core.c | 7 +- arch/powerpc/kvm/book3s_hv.c | 5 +- arch/s390/kernel/perf_cpum_sf.c | 6 +- arch/um/drivers/vfio_kern.c | 6 +- arch/um/drivers/virtio_uml.c | 6 +- arch/x86/kernel/msr.c | 6 +- arch/x86/kvm/mmu/mmu.c | 12 +-- arch/x86/kvm/svm/avic.c | 6 +- arch/x86/kvm/vmx/vmx.c | 6 +- arch/x86/platform/uv/uv_nmi.c | 12 +-- block/disk-events.c | 6 +- drivers/acpi/sysfs.c | 25 +++---- drivers/block/loop.c | 12 +-- drivers/block/null_blk/main.c | 12 +-- drivers/block/rnbd/rnbd-srv.c | 6 +- drivers/block/ublk_drv.c | 7 +- drivers/char/ipmi/ipmi_msghandler.c | 6 +- drivers/char/ipmi/ipmi_watchdog.c | 17 ++--- drivers/crypto/hisilicon/hpre/hpre_main.c | 16 +--- drivers/crypto/hisilicon/sec2/sec_main.c | 23 ++---- drivers/crypto/hisilicon/zip/zip_crypto.c | 5 +- drivers/crypto/hisilicon/zip/zip_main.c | 21 ++---- drivers/dma/dmatest.c | 20 ++--- drivers/edac/i10nm_base.c | 6 +- drivers/firmware/efi/efi-pstore.c | 6 +- drivers/firmware/qcom/qcom_scm.c | 6 +- drivers/firmware/qemu_fw_cfg.c | 6 +- drivers/gpu/drm/drm_panic.c | 6 +- drivers/gpu/drm/i915/i915_mitigations.c | 5 +- drivers/gpu/drm/imagination/pvr_fw_trace.c | 6 +- drivers/hid/hid-cougar.c | 6 +- drivers/hid/hid-steam.c | 6 +- drivers/infiniband/hw/hfi1/driver.c | 5 +- drivers/infiniband/ulp/iser/iscsi_iser.c | 6 +- drivers/infiniband/ulp/isert/ib_isert.c | 6 +- drivers/infiniband/ulp/srp/ib_srp.c | 5 +- drivers/input/misc/ati_remote2.c | 13 ++-- drivers/input/mouse/psmouse-base.c | 6 +- drivers/media/usb/uvc/uvc_driver.c | 6 +- drivers/misc/lis3lv02d/lis3lv02d.c | 5 +- drivers/net/wireless/ath/wil6210/main.c | 10 +-- drivers/nvme/host/multipath.c | 12 +-- drivers/nvme/host/pci.c | 18 ++--- drivers/nvme/target/rdma.c | 5 +- drivers/nvme/target/tcp.c | 5 +- drivers/platform/x86/acerhdf.c | 5 +- drivers/power/supply/bq27xxx_battery.c | 6 +- drivers/power/supply/test_power.c | 75 ++++++++----------- drivers/scsi/sg.c | 6 +- drivers/target/target_core_user.c | 13 ++-- .../processor_thermal_soc_slider.c | 12 +-- drivers/thermal/intel/intel_powerclamp.c | 20 +---- drivers/tty/hvc/hvc_iucv.c | 6 +- drivers/tty/sysrq.c | 6 +- drivers/ufs/core/ufs-fault-injection.c | 5 +- drivers/ufs/core/ufs-mcq.c | 18 ++--- drivers/ufs/core/ufs-txeq.c | 5 +- drivers/ufs/core/ufshcd.c | 12 +-- drivers/usb/core/quirks.c | 6 +- drivers/usb/gadget/legacy/serial.c | 5 +- drivers/usb/storage/usb.c | 5 +- drivers/vhost/scsi.c | 7 +- drivers/virt/nitro_enclaves/ne_misc_dev.c | 6 +- drivers/virtio/virtio_mmio.c | 6 +- fs/ceph/super.c | 10 +-- fs/fuse/dir.c | 5 +- fs/nfs/namespace.c | 6 +- fs/nfs/super.c | 6 +- fs/ubifs/super.c | 6 +- kernel/locking/locktorture.c | 6 +- kernel/panic.c | 6 +- kernel/params.c | 44 +++-------- kernel/power/hibernate.c | 6 +- kernel/rcu/tree.c | 18 ++--- kernel/sched/ext.c | 11 +-- kernel/workqueue.c | 12 +-- lib/dynamic_debug.c | 6 +- lib/test_dynamic_debug.c | 6 +- mm/damon/lru_sort.c | 19 ++--- mm/damon/reclaim.c | 19 ++--- mm/damon/stat.c | 6 +- mm/memory_hotplug.c | 12 +-- mm/page_reporting.c | 11 +-- mm/shuffle.c | 6 +- mm/zswap.c | 14 ++-- net/batman-adv/bat_algo.c | 6 +- net/ceph/ceph_common.c | 5 +- net/ipv4/tcp_dctcp.c | 6 +- net/sunrpc/auth.c | 6 +- net/sunrpc/xprtsock.c | 18 ++--- samples/damon/mtier.c | 6 +- samples/damon/prcl.c | 6 +- samples/damon/wsse.c | 6 +- security/apparmor/lsm.c | 34 +++------ sound/hda/controllers/intel.c | 5 +- sound/usb/card.c | 7 +- 96 files changed, 307 insertions(+), 660 deletions(-)mm/kfence/core.c +3
-4@@ -92,10 +92,9 @@ static int param_get_sample_interval(char *buffer, const struct kernel_param *kpreturn param_get_ulong (buffer, kp); } -static const struct kernel_param_ops sample_interval_param_ops = { - .set = param_set_sample_interval, - .get = param_get_sample_interval, -}; +static DEFINE_KERNEL_PARAM_OPS(sample_interval_param_ops, + param_set_sample_interval, + param_get_sample_interval);module_param_cb (sample_interval, &sample_interval_param_ops, &kfence_sample_interval,0600 );/* Pool usage% threshold when currently covered allocations are skipped. */ arch/powerpc/kvm/book3s_hv.c +1
-4@@ -114,10 +114,7 @@ module_param(one_vm_per_core, bool, S_IRUGO | S_IWUSR);MODULE_PARM_DESC (one_vm_per_core,"Only run vCPUs from the same VM on a core (requires POWER8 or older)" );#ifdef CONFIG_KVM_XICS -static const struct kernel_param_ops module_param_ops = { - .set = param_set_int, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(module_param_ops, param_set_int, param_get_int);module_param_cb (kvm_irq_bypass, &module_param_ops, &kvm_irq_bypass,0644 );MODULE_PARM_DESC (kvm_irq_bypass,"Bypass passthrough interrupt optimization" );arch/s390/kernel/perf_cpum_sf.c +2
-4@@ -2029,10 +2029,8 @@ static int param_set_sfb_size(const char *val, const struct kernel_param *kp) }#define param_check_sfb_size (name, p) __param_check(name, p, void) -static const struct kernel_param_ops param_ops_sfb_size = { - .set = param_set_sfb_size, - .get = param_get_sfb_size, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_sfb_size, param_set_sfb_size, + param_get_sfb_size);enum {RS_INIT_FAILURE_BSDES =2 ,/* Bad basic sampling size */ arch/um/drivers/vfio_kern.c +2
-4@@ -628,10 +628,8 @@ static int uml_vfio_cmdline_get(char *buffer, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops uml_vfio_cmdline_param_ops = { - .set = uml_vfio_cmdline_set, - .get = uml_vfio_cmdline_get, -}; +static DEFINE_KERNEL_PARAM_OPS(uml_vfio_cmdline_param_ops, uml_vfio_cmdline_set, + uml_vfio_cmdline_get);device_param_cb (device, ¨_vfio_cmdline_param_ops,NULL ,0400 ); __uml_help(uml_vfio_cmdline_param_ops,arch/um/drivers/virtio_uml.c +2
-4@@ -1398,10 +1398,8 @@ static int vu_cmdline_get(char *buffer, const struct kernel_param *kp)return strlen (buffer) +1 ; } -static const struct kernel_param_ops vu_cmdline_param_ops = { - .set = vu_cmdline_set, - .get = vu_cmdline_get, -}; +static DEFINE_KERNEL_PARAM_OPS(vu_cmdline_param_ops, vu_cmdline_set, + vu_cmdline_get);device_param_cb (device, &vu_cmdline_param_ops,NULL ,S_IRUSR ); __uml_help(vu_cmdline_param_ops,arch/x86/kernel/msr.c +2
-4@@ -322,10 +322,8 @@ static int get_allow_writes(char *buf, const struct kernel_param *kp)return sprintf (buf,"%s\n" , res); } -static const struct kernel_param_ops allow_writes_ops = { - .set = set_allow_writes, - .get = get_allow_writes -}; +static DEFINE_KERNEL_PARAM_OPS(allow_writes_ops, set_allow_writes, + get_allow_writes);module_param_cb (allow_writes, &allow_writes_ops,NULL ,0600 );arch/x86/kvm/mmu/mmu.c +4
-8@@ -74,15 +74,11 @@ static int get_nx_huge_pages(char *buffer, const struct kernel_param *kp);static int set_nx_huge_pages (const char *val,const struct kernel_param *kp);static int set_nx_huge_pages_recovery_param (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops nx_huge_pages_ops = { - .set = set_nx_huge_pages, - .get = get_nx_huge_pages, -}; +static DEFINE_KERNEL_PARAM_OPS(nx_huge_pages_ops, set_nx_huge_pages, + get_nx_huge_pages); -static const struct kernel_param_ops nx_huge_pages_recovery_param_ops = { - .set = set_nx_huge_pages_recovery_param, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(nx_huge_pages_recovery_param_ops, + set_nx_huge_pages_recovery_param, param_get_uint);module_param_cb (nx_huge_pages, &nx_huge_pages_ops, &nx_huge_pages,0644 );__MODULE_PARM_TYPE (nx_huge_pages,"bool" );arch/x86/kvm/svm/avic.c +1
-5@@ -87,11 +87,7 @@ static int avic_param_get(char *buffer, const struct kernel_param *kp)return param_get_bool (buffer, kp); } -static const struct kernel_param_ops avic_ops = { - .flags =KERNEL_PARAM_OPS_FL_NOARG , - .set = avic_param_set, - .get = avic_param_get, -}; +static DEFINE_KERNEL_PARAM_OPS_NOARG(avic_ops, avic_param_set, avic_param_get);/* * Enable / disable AVIC. In "auto" mode (default behavior), AVIC is enabled arch/x86/kvm/vmx/vmx.c +2
-4@@ -465,10 +465,8 @@ static int vmentry_l1d_flush_get(char *s, const struct kernel_param *kp) }#endif -static const struct kernel_param_ops vmentry_l1d_flush_ops = { - .set = vmentry_l1d_flush_set, - .get = vmentry_l1d_flush_get, -}; +static DEFINE_KERNEL_PARAM_OPS(vmentry_l1d_flush_ops, vmentry_l1d_flush_set, + vmentry_l1d_flush_get);module_param_cb (vmentry_l1d_flush, &vmentry_l1d_flush_ops,NULL ,0644 ); static __always_inline void vmx_disable_fb_clear(struct vcpu_vmx *vmx)arch/x86/platform/uv/uv_nmi.c +4
-8@@ -123,10 +123,8 @@ static int param_set_local64(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops param_ops_local64 = { - .get = param_get_local64, - .set = param_set_local64, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_local64, param_set_local64, + param_get_local64);#define param_check_local64 (name, p) __param_check(name, p, local64_t)static local64_t uv_nmi_count;@@ -232,10 +230,8 @@ static int param_set_action(const char *val, const struct kernel_param *kp)return -EINVAL ; } -static const struct kernel_param_ops param_ops_action = { - .get = param_get_action, - .set = param_set_action, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_action, param_set_action, + param_get_action);#define param_check_action (name, p) __param_check(name, p, enum action_t)module_param_named (action, uv_nmi_action, action,0644 );block/disk-events.c +2
-4@@ -416,10 +416,8 @@ static int disk_events_set_dfl_poll_msecs(const char *val,return 0 ; } -static const struct kernel_param_ops disk_events_dfl_poll_msecs_param_ops = { - .set = disk_events_set_dfl_poll_msecs, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(disk_events_dfl_poll_msecs_param_ops, + disk_events_set_dfl_poll_msecs, param_get_ulong);#undef MODULE_PARAM_PREFIX#define MODULE_PARAM_PREFIX "block."drivers/acpi/sysfs.c +9
-16@@ -138,15 +138,11 @@ static int param_get_debug_level(char *buffer, const struct kernel_param *kp)return result; } -static const struct kernel_param_ops param_ops_debug_layer = { - .set = param_set_uint, - .get = param_get_debug_layer, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_debug_layer, param_set_uint, + param_get_debug_layer); -static const struct kernel_param_ops param_ops_debug_level = { - .set = param_set_uint, - .get = param_get_debug_level, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_debug_level, param_set_uint, + param_get_debug_level);module_param_cb (debug_layer, ¶m_ops_debug_layer, &acpi_dbg_layer,0644 );module_param_cb (debug_level, ¶m_ops_debug_level, &acpi_dbg_level,0644 );@@ -201,15 +197,12 @@ static int param_get_trace_method_name(char *buffer, const struct kernel_param *return sysfs_emit (buffer,"%s\n" , acpi_gbl_trace_method_name); } -static const struct kernel_param_ops param_ops_trace_method = { - .set = param_set_trace_method_name, - .get = param_get_trace_method_name, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_trace_method, + param_set_trace_method_name, + param_get_trace_method_name); -static const struct kernel_param_ops param_ops_trace_attrib = { - .set = param_set_uint, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_trace_attrib, param_set_uint, + param_get_uint);module_param_cb (trace_method_name, ¶m_ops_trace_method, &trace_method_name,0644 );module_param_cb (trace_debug_layer, ¶m_ops_trace_attrib, &acpi_gbl_trace_dbg_layer,0644 );drivers/block/loop.c +4
-8@@ -1806,10 +1806,8 @@ static int max_loop_param_set_int(const char *val,return 0 ; } -static const struct kernel_param_ops max_loop_param_ops = { - .set = max_loop_param_set_int, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(max_loop_param_ops, max_loop_param_set_int, + param_get_int);module_param_cb (max_loop, &max_loop_param_ops, &max_loop,0444 );MODULE_PARM_DESC (max_loop,"Maximum number of loop devices" );@@ -1836,10 +1834,8 @@ static int loop_set_hw_queue_depth(const char *s, const struct kernel_param *p)return 0 ; } -static const struct kernel_param_ops loop_hw_qdepth_param_ops = { - .set = loop_set_hw_queue_depth, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(loop_hw_qdepth_param_ops, + loop_set_hw_queue_depth, param_get_int);device_param_cb (hw_queue_depth, &loop_hw_qdepth_param_ops, &hw_queue_depth,0444 );MODULE_PARM_DESC (hw_queue_depth,"Queue depth for each hardware queue. Default: " __stringify(LOOP_DEFAULT_HW_Q_DEPTH ));drivers/block/null_blk/main.c +4
-8@@ -149,10 +149,8 @@ static int null_set_queue_mode(const char *str, const struct kernel_param *kp)return null_param_store_val (str, &g_queue_mode,NULL_Q_BIO ,NULL_Q_MQ ); } -static const struct kernel_param_ops null_queue_mode_param_ops = { - .set = null_set_queue_mode, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(null_queue_mode_param_ops, null_set_queue_mode, + param_get_int);device_param_cb (queue_mode, &null_queue_mode_param_ops, &g_queue_mode,0444 );MODULE_PARM_DESC (queue_mode,"Block interface to use (0=bio,1=rq,2=multiqueue)" );@@ -193,10 +191,8 @@ static int null_set_irqmode(const char *str, const struct kernel_param *kp) NULL_IRQ_TIMER); } -static const struct kernel_param_ops null_irqmode_param_ops = { - .set = null_set_irqmode, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(null_irqmode_param_ops, null_set_irqmode, + param_get_int);device_param_cb (irqmode, &null_irqmode_param_ops, &g_irqmode,0444 );MODULE_PARM_DESC (irqmode,"IRQ completion handler. 0-none, 1-softirq, 2-timer" );drivers/block/rnbd/rnbd-srv.c +2
-4@@ -49,10 +49,8 @@ static struct kparam_string dev_search_path_kparam_str = { .string = dev_search_path }; -static const struct kernel_param_ops dev_search_path_ops = { - .set = dev_search_path_set, - .get = param_get_string, -}; +static DEFINE_KERNEL_PARAM_OPS(dev_search_path_ops, dev_search_path_set, + param_get_string);module_param_cb (dev_search_path, &dev_search_path_ops, &dev_search_path_kparam_str,0444 );drivers/block/ublk_drv.c +3
-4@@ -5874,10 +5874,9 @@ static int ublk_get_max_unprivileged_ublks(char *buf,return sysfs_emit (buf,"%u\n" , unprivileged_ublks_max); } -static const struct kernel_param_ops ublk_max_unprivileged_ublks_ops = { - .set = ublk_set_max_unprivileged_ublks, - .get = ublk_get_max_unprivileged_ublks, -}; +static DEFINE_KERNEL_PARAM_OPS(ublk_max_unprivileged_ublks_ops, + ublk_set_max_unprivileged_ublks, + ublk_get_max_unprivileged_ublks);module_param_cb (ublks_max, &ublk_max_unprivileged_ublks_ops, &unprivileged_ublks_max,0644 );drivers/char/ipmi/ipmi_msghandler.c +2
-4@@ -102,10 +102,8 @@ static int panic_op_read_handler(char *buffer, const struct kernel_param *kp)return sprintf (buffer,"%s\n" , event_str); } -static const struct kernel_param_ops panic_op_ops = { - .set = panic_op_write_handler, - .get = panic_op_read_handler -}; +static DEFINE_KERNEL_PARAM_OPS(panic_op_ops, panic_op_write_handler, + panic_op_read_handler);module_param_cb (panic_op, &panic_op_ops,NULL ,0600 );MODULE_PARM_DESC (panic_op,"Sets if the IPMI driver will attempt to store panic information in the event log in the event of a panic. Set to 'none' for no, 'event' for a single event, or 'string' for a generic event and the panic string in IPMI OEM events." );drivers/char/ipmi/ipmi_watchdog.c +5
-12@@ -193,10 +193,8 @@ static int set_param_timeout(const char *val, const struct kernel_param *kp)return rv; } -static const struct kernel_param_ops param_ops_timeout = { - .set = set_param_timeout, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_timeout, set_param_timeout, + param_get_int);#define param_check_timeout param_check_inttypedef int (*action_fn )(const char *intval,char *outval);@@ -259,17 +257,12 @@ static int set_param_wdog_ifnum(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops param_ops_wdog_ifnum = { - .set = set_param_wdog_ifnum, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_wdog_ifnum, set_param_wdog_ifnum, + param_get_int);#define param_check_wdog_ifnum param_check_int -static const struct kernel_param_ops param_ops_str = { - .set = set_param_str, - .get = get_param_str, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_str, set_param_str, get_param_str);module_param (ifnum_to_use, wdog_ifnum,0644 ); MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog "drivers/crypto/hisilicon/hpre/hpre_main.c +4
-12@@ -420,10 +420,8 @@ static int hpre_cluster_regs_show(struct seq_file *s, void *unused)DEFINE_SHOW_ATTRIBUTE (hpre_cluster_regs); -static const struct kernel_param_ops hpre_uacce_mode_ops = { - .set = uacce_mode_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(hpre_uacce_mode_ops, uacce_mode_set, + param_get_int);/* * uacce_mode = 0 means hpre only register to crypto, @@ -441,19 +439,13 @@ static int pf_q_num_set(const char *val, const struct kernel_param *kp)return hisi_qm_q_num_set (val, kp,PCI_DEVICE_ID_HUAWEI_HPRE_PF ); } -static const struct kernel_param_ops hpre_pf_q_num_ops = { - .set = pf_q_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(hpre_pf_q_num_ops, pf_q_num_set, param_get_int);static u32 pf_q_num =HPRE_PF_DEF_Q_NUM ;module_param_cb (pf_q_num, &hpre_pf_q_num_ops, &pf_q_num,0444 );MODULE_PARM_DESC (pf_q_num,"Number of queues in PF of CS(2-1024)" ); -static const struct kernel_param_ops vfs_num_ops = { - .set = vfs_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(vfs_num_ops, vfs_num_set, param_get_int);static u32 vfs_num;module_param_cb (vfs_num, &vfs_num_ops, &vfs_num,0444 );drivers/crypto/hisilicon/sec2/sec_main.c +7
-16@@ -362,10 +362,8 @@ static int sec_pf_q_num_set(const char *val, const struct kernel_param *kp)return hisi_qm_q_num_set (val, kp,PCI_DEVICE_ID_HUAWEI_SEC_PF ); } -static const struct kernel_param_ops sec_pf_q_num_ops = { - .set = sec_pf_q_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(sec_pf_q_num_ops, sec_pf_q_num_set, + param_get_int);static u32 pf_q_num =SEC_PF_DEF_Q_NUM ;module_param_cb (pf_q_num, &sec_pf_q_num_ops, &pf_q_num,0444 );@@ -391,18 +389,13 @@ static int sec_ctx_q_num_set(const char *val, const struct kernel_param *kp)return param_set_int (val, kp); } -static const struct kernel_param_ops sec_ctx_q_num_ops = { - .set = sec_ctx_q_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(sec_ctx_q_num_ops, sec_ctx_q_num_set, + param_get_int);static u32 ctx_q_num =SEC_CTX_Q_NUM_DEF ;module_param_cb (ctx_q_num, &sec_ctx_q_num_ops, &ctx_q_num,0444 );MODULE_PARM_DESC (ctx_q_num,"Queue num in ctx (2 default, 2, 4, ..., 32)" ); -static const struct kernel_param_ops vfs_num_ops = { - .set = vfs_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(vfs_num_ops, vfs_num_set, param_get_int);static u32 vfs_num;module_param_cb (vfs_num, &vfs_num_ops, &vfs_num,0444 );@@ -454,10 +447,8 @@ u64 sec_get_alg_bitmap(struct hisi_qm *qm, u32 high, u32 low)return ((u64 )cap_val_h <<SEC_ALG_BITMAP_SHIFT ) | (u64 )cap_val_l; } -static const struct kernel_param_ops sec_uacce_mode_ops = { - .set = uacce_mode_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(sec_uacce_mode_ops, uacce_mode_set, + param_get_int);/* * uacce_mode = 0 means sec only register to crypto, drivers/crypto/hisilicon/zip/zip_crypto.c +1
-4@@ -108,10 +108,7 @@ static int sgl_sge_nr_set(const char *val, const struct kernel_param *kp)return param_set_ushort (val, kp); } -static const struct kernel_param_ops sgl_sge_nr_ops = { - .set = sgl_sge_nr_set, - .get = param_get_ushort, -}; +static DEFINE_KERNEL_PARAM_OPS(sgl_sge_nr_ops, sgl_sge_nr_set, param_get_ushort);static u16 sgl_sge_nr =HZIP_SGL_SGE_NR ;module_param_cb (sgl_sge_nr, &sgl_sge_nr_ops, &sgl_sge_nr,0444 );drivers/crypto/hisilicon/zip/zip_main.c +5
-16@@ -394,10 +394,7 @@ static int perf_mode_set(const char *val, const struct kernel_param *kp)return param_set_int (val, kp); } -static const struct kernel_param_ops zip_com_perf_ops = { - .set = perf_mode_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(zip_com_perf_ops, perf_mode_set, param_get_int);/* * perf_mode = 0 means enable high compression rate mode, @@ -408,10 +405,8 @@ static u32 perf_mode = HZIP_HIGH_COMP_RATE;module_param_cb (perf_mode, &zip_com_perf_ops, &perf_mode,0444 );MODULE_PARM_DESC (perf_mode,"ZIP high perf mode 0(default), 1(enable)" ); -static const struct kernel_param_ops zip_uacce_mode_ops = { - .set = uacce_mode_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(zip_uacce_mode_ops, uacce_mode_set, + param_get_int);/* * uacce_mode = 0 means zip only register to crypto, @@ -429,19 +424,13 @@ static int pf_q_num_set(const char *val, const struct kernel_param *kp)return hisi_qm_q_num_set (val, kp,PCI_DEVICE_ID_HUAWEI_ZIP_PF ); } -static const struct kernel_param_ops pf_q_num_ops = { - .set = pf_q_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(pf_q_num_ops, pf_q_num_set, param_get_int);static u32 pf_q_num =HZIP_PF_DEF_Q_NUM ;module_param_cb (pf_q_num, &pf_q_num_ops, &pf_q_num,0444 );MODULE_PARM_DESC (pf_q_num,"Number of queues in PF(v1 2-4096, v2 2-1024)" ); -static const struct kernel_param_ops vfs_num_ops = { - .set = vfs_num_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(vfs_num_ops, vfs_num_set, param_get_int);static u32 vfs_num;module_param_cb (vfs_num, &vfs_num_ops, &vfs_num,0444 );drivers/dma/dmatest.c +5
-15@@ -154,20 +154,15 @@ static struct dmatest_info {static int dmatest_run_set (const char *val,const struct kernel_param *kp);static int dmatest_run_get (char *val,const struct kernel_param *kp); -static const struct kernel_param_ops run_ops = { - .set = dmatest_run_set, - .get = dmatest_run_get, -}; +static DEFINE_KERNEL_PARAM_OPS(run_ops, dmatest_run_set, dmatest_run_get);static bool dmatest_run;module_param_cb (run, &run_ops, &dmatest_run,0644 );MODULE_PARM_DESC (run,"Run the test (default: false)" );static int dmatest_chan_set (const char *val,const struct kernel_param *kp);static int dmatest_chan_get (char *val,const struct kernel_param *kp); -static const struct kernel_param_ops multi_chan_ops = { - .set = dmatest_chan_set, - .get = dmatest_chan_get, -}; +static DEFINE_KERNEL_PARAM_OPS(multi_chan_ops, dmatest_chan_set, + dmatest_chan_get);static char test_channel[20 ];static struct kparam_string newchan_kps = {@@ -178,9 +173,7 @@ module_param_cb(channel, &multi_chan_ops, &newchan_kps, 0644);MODULE_PARM_DESC (channel,"Bus ID of the channel to test (default: any)" );static int dmatest_test_list_get (char *val,const struct kernel_param *kp); -static const struct kernel_param_ops test_list_ops = { - .get = dmatest_test_list_get, -}; +static DEFINE_KERNEL_PARAM_OPS(test_list_ops, NULL, dmatest_test_list_get);module_param_cb (test_list, &test_list_ops,NULL ,0444 );MODULE_PARM_DESC (test_list,"Print current test list" );@@ -292,10 +285,7 @@ static int dmatest_wait_get(char *val, const struct kernel_param *kp)return param_get_bool (val, kp); } -static const struct kernel_param_ops wait_ops = { - .get = dmatest_wait_get, - .set = param_set_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(wait_ops, param_set_bool, dmatest_wait_get);module_param_cb (wait, &wait_ops, &wait,0444 );MODULE_PARM_DESC (wait,"Wait for tests to complete (default: false)" );drivers/edac/i10nm_base.c +2
-4@@ -1284,10 +1284,8 @@ static int set_decoding_via_mca(const char *buf, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops decoding_via_mca_param_ops = { - .set = set_decoding_via_mca, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(decoding_via_mca_param_ops, set_decoding_via_mca, + param_get_int);module_param_cb (decoding_via_mca, &decoding_via_mca_param_ops, &decoding_via_mca,0644 );MODULE_PARM_DESC (decoding_via_mca,"decoding_via_mca: 0=off(default), 1=enable" );drivers/firmware/efi/efi-pstore.c +2
-4@@ -43,10 +43,8 @@ static int efi_pstore_disable_set(const char *val, const struct kernel_param *kpreturn 0 ; } -static const struct kernel_param_ops pstore_disable_ops = { - .set = efi_pstore_disable_set, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(pstore_disable_ops, efi_pstore_disable_set, + param_get_bool);module_param_cb (pstore_disable, &pstore_disable_ops, &pstore_disable,0644 );__MODULE_PARM_TYPE (pstore_disable,"bool" );drivers/firmware/qcom/qcom_scm.c +2
-4@@ -2725,10 +2725,8 @@ static int set_download_mode(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops download_mode_param_ops = { - .get = get_download_mode, - .set = set_download_mode, -}; +static DEFINE_KERNEL_PARAM_OPS(download_mode_param_ops, set_download_mode, + get_download_mode);module_param_cb (download_mode, &download_mode_param_ops,NULL ,0644 );MODULE_PARM_DESC (download_mode,"download mode: off/0/N for no dump mode, full/on/1/Y for full dump mode, mini for minidump mode and full,mini for both full and minidump mode together are acceptable values" );drivers/firmware/qemu_fw_cfg.c +2
-4@@ -897,10 +897,8 @@ static int fw_cfg_cmdline_get(char *buf, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops fw_cfg_cmdline_param_ops = { - .set = fw_cfg_cmdline_set, - .get = fw_cfg_cmdline_get, -}; +static DEFINE_KERNEL_PARAM_OPS(fw_cfg_cmdline_param_ops, fw_cfg_cmdline_set, + fw_cfg_cmdline_get);device_param_cb (ioport, &fw_cfg_cmdline_param_ops,NULL ,S_IRUSR );device_param_cb (mmio, &fw_cfg_cmdline_param_ops,NULL ,S_IRUSR );drivers/gpu/drm/drm_panic.c +2
-4@@ -847,10 +847,8 @@ static int drm_panic_type_get(char *buffer, const struct kernel_param *kp) drm_panic_type_map[drm_panic_type]); } -static const struct kernel_param_ops drm_panic_ops = { - .set = drm_panic_type_set, - .get = drm_panic_type_get, -}; +static DEFINE_KERNEL_PARAM_OPS(drm_panic_ops, drm_panic_type_set, + drm_panic_type_get);module_param_cb (panic_screen, &drm_panic_ops,NULL ,0644 ); MODULE_PARM_DESC(panic_screen,drivers/gpu/drm/i915/i915_mitigations.c +1
-4@@ -124,10 +124,7 @@ static int mitigations_get(char *buffer, const struct kernel_param *kp)return count; } -static const struct kernel_param_ops ops = { - .set = mitigations_set, - .get = mitigations_get, -}; +static DEFINE_KERNEL_PARAM_OPS(ops, mitigations_set, mitigations_get);module_param_cb_unsafe (mitigations, &ops,NULL ,0600 ); MODULE_PARM_DESC(mitigations,drivers/gpu/drm/imagination/pvr_fw_trace.c +2
-4@@ -71,10 +71,8 @@ pvr_fw_trace_init_mask_set(const char *val, const struct kernel_param *kp)return 0 ; } -const struct kernel_param_ops pvr_fw_trace_init_mask_ops = { - .set = pvr_fw_trace_init_mask_set, - .get = param_get_hexint, -}; +DEFINE_KERNEL_PARAM_OPS (pvr_fw_trace_init_mask_ops, pvr_fw_trace_init_mask_set, + param_get_hexint);param_check_hexint (init_fw_trace_mask, &pvr_fw_trace_init_mask);module_param_cb (init_fw_trace_mask, &pvr_fw_trace_init_mask_ops, &pvr_fw_trace_init_mask,0600 );drivers/hid/hid-cougar.c +2
-4@@ -314,10 +314,8 @@ static int cougar_param_set_g6_is_space(const char *val,return 0 ; } -static const struct kernel_param_ops cougar_g6_is_space_ops = { - .set = cougar_param_set_g6_is_space, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(cougar_g6_is_space_ops, + cougar_param_set_g6_is_space, param_get_bool);module_param_cb (g6_is_space, &cougar_g6_is_space_ops, &g6_is_space,0644 );static const struct hid_device_id cougar_id_table[] = {drivers/hid/hid-steam.c +2
-4@@ -1840,10 +1840,8 @@ static int steam_param_set_lizard_mode(const char *val,return 0 ; } -static const struct kernel_param_ops steam_lizard_mode_ops = { - .set = steam_param_set_lizard_mode, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(steam_lizard_mode_ops, + steam_param_set_lizard_mode, param_get_bool);module_param_cb (lizard_mode, &steam_lizard_mode_ops, &lizard_mode,0644 ); MODULE_PARM_DESC(lizard_mode,drivers/infiniband/hw/hfi1/driver.c +1
-4@@ -42,10 +42,7 @@ MODULE_PARM_DESC(cu, "Credit return units");unsigned long hfi1_cap_mask =HFI1_CAP_MASK_DEFAULT ;static int hfi1_caps_set (const char *val,const struct kernel_param *kp);static int hfi1_caps_get (char *buffer,const struct kernel_param *kp); -static const struct kernel_param_ops cap_ops = { - .set = hfi1_caps_set, - .get = hfi1_caps_get -}; +static DEFINE_KERNEL_PARAM_OPS(cap_ops, hfi1_caps_set, hfi1_caps_get);module_param_cb (cap_mask, &cap_ops, &hfi1_cap_mask,S_IWUSR |S_IRUGO );MODULE_PARM_DESC (cap_mask,"Bit mask of enabled/disabled HW features" );drivers/infiniband/ulp/iser/iscsi_iser.c +2
-4@@ -90,10 +90,8 @@ module_param_named(debug_level, iser_debug_level, int, S_IRUGO | S_IWUSR);MODULE_PARM_DESC (debug_level,"Enable debug tracing if > 0 (default:disabled)" );static int iscsi_iser_set (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops iscsi_iser_size_ops = { - .set = iscsi_iser_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(iscsi_iser_size_ops, iscsi_iser_set, + param_get_uint);static unsigned int iscsi_max_lun =512 ;module_param_cb (max_lun, &iscsi_iser_size_ops, &iscsi_max_lun,S_IRUGO );drivers/infiniband/ulp/isert/ib_isert.c +2
-4@@ -30,10 +30,8 @@ MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:0)");static int isert_sg_tablesize_set (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops sg_tablesize_ops = { - .set = isert_sg_tablesize_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(sg_tablesize_ops, isert_sg_tablesize_set, + param_get_int);static int isert_sg_tablesize =ISCSI_ISER_MIN_SG_TABLESIZE ;module_param_cb (sg_tablesize, &sg_tablesize_ops, &isert_sg_tablesize,0644 );drivers/infiniband/ulp/srp/ib_srp.c +1
-4@@ -195,10 +195,7 @@ static int srp_tmo_set(const char *val, const struct kernel_param *kp)return res; } -static const struct kernel_param_ops srp_tmo_ops = { - .get = srp_tmo_get, - .set = srp_tmo_set, -}; +static DEFINE_KERNEL_PARAM_OPS(srp_tmo_ops, srp_tmo_set, srp_tmo_get);static inline struct srp_target_port *host_to_target (struct Scsi_Host *host) {drivers/input/misc/ati_remote2.c +5
-8@@ -89,19 +89,16 @@ static int ati_remote2_get_mode_mask(char *buffer,static unsigned int channel_mask =ATI_REMOTE2_MAX_CHANNEL_MASK ;#define param_check_channel_mask (name, p) __param_check(name, p, unsigned int) -static const struct kernel_param_ops param_ops_channel_mask = { - .set = ati_remote2_set_channel_mask, - .get = ati_remote2_get_channel_mask, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_channel_mask, + ati_remote2_set_channel_mask, + ati_remote2_get_channel_mask);module_param (channel_mask, channel_mask,0644 );MODULE_PARM_DESC (channel_mask,"Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>" );static unsigned int mode_mask =ATI_REMOTE2_MAX_MODE_MASK ;#define param_check_mode_mask (name, p) __param_check(name, p, unsigned int) -static const struct kernel_param_ops param_ops_mode_mask = { - .set = ati_remote2_set_mode_mask, - .get = ati_remote2_get_mode_mask, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_mode_mask, ati_remote2_set_mode_mask, + ati_remote2_get_mode_mask);module_param (mode_mask, mode_mask,0644 );MODULE_PARM_DESC (mode_mask,"Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>" );drivers/input/mouse/psmouse-base.c +2
-4@@ -45,10 +45,8 @@ MODULE_LICENSE("GPL");static unsigned int psmouse_max_proto =PSMOUSE_AUTO ;static int psmouse_set_maxproto (const char *val,const struct kernel_param *);static int psmouse_get_maxproto (char *buffer,const struct kernel_param *kp); -static const struct kernel_param_ops param_ops_proto_abbrev = { - .set = psmouse_set_maxproto, - .get = psmouse_get_maxproto, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_proto_abbrev, psmouse_set_maxproto, + psmouse_get_maxproto);#define param_check_proto_abbrev (name, p) __param_check(name, p, unsigned int)module_param_named (proto, psmouse_max_proto, proto_abbrev,0644 );MODULE_PARM_DESC (proto,"Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches." );drivers/media/usb/uvc/uvc_driver.c +2
-4@@ -2488,10 +2488,8 @@ static int param_set_nodrop(const char *val, const struct kernel_param *kp)return param_set_bool (val, kp); } -static const struct kernel_param_ops param_ops_nodrop = { - .set = param_set_nodrop, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_nodrop, param_set_nodrop, + param_get_uint);param_check_uint (nodrop, &uvc_no_drop_param);module_param_cb (nodrop, ¶m_ops_nodrop, &uvc_no_drop_param,0644 );drivers/misc/lis3lv02d/lis3lv02d.c +1
-4@@ -103,10 +103,7 @@ static int param_set_axis(const char *val, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops param_ops_axis = { - .set = param_set_axis, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_axis, param_set_axis, param_get_int);#define param_check_axis (name, p) param_check_int(name, p)drivers/net/wireless/ath/wil6210/main.c +2
-8@@ -62,10 +62,7 @@ static int mtu_max_set(const char *val, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops mtu_max_ops = { - .set = mtu_max_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(mtu_max_ops, mtu_max_set, param_get_uint);module_param_cb (mtu_max, &mtu_max_ops, &mtu_max,0444 );MODULE_PARM_DESC (mtu_max," Max MTU value." );@@ -91,10 +88,7 @@ static int ring_order_set(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops ring_order_ops = { - .set = ring_order_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(ring_order_ops, ring_order_set, param_get_uint);module_param_cb (rx_ring_order, &ring_order_ops, &rx_ring_order,0444 );MODULE_PARM_DESC (rx_ring_order," Rx ring order; size = 1 << order" );drivers/nvme/host/multipath.c +4
-8@@ -30,10 +30,8 @@ static int multipath_param_set(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops multipath_param_ops = { - .set = multipath_param_set, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(multipath_param_ops, multipath_param_set, + param_get_bool);module_param_cb (multipath, &multipath_param_ops, &multipath,0444 ); MODULE_PARM_DESC(multipath,@@ -55,10 +53,8 @@ static int multipath_always_on_set(const char *val,return 0 ; } -static const struct kernel_param_ops multipath_always_on_ops = { - .set = multipath_always_on_set, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(multipath_always_on_ops, multipath_always_on_set, + param_get_bool);module_param_cb (multipath_always_on, &multipath_always_on_ops, &multipath_always_on,0444 );drivers/nvme/host/pci.c +6
-12@@ -100,10 +100,8 @@ MODULE_PARM_DESC(sgl_threshold,#define NVME_PCI_MIN_QUEUE_SIZE 2#define NVME_PCI_MAX_QUEUE_SIZE 4095static int io_queue_depth_set (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops io_queue_depth_ops = { - .set = io_queue_depth_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(io_queue_depth_ops, io_queue_depth_set, + param_get_uint);static unsigned int io_queue_depth =1024 ;module_param_cb (io_queue_depth, &io_queue_depth_ops, &io_queue_depth,0644 );@@ -232,10 +230,8 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp) }static char quirks_param[128 ]; -static const struct kernel_param_ops quirks_param_ops = { - .set = quirks_param_set, - .get = param_get_string, -}; +static DEFINE_KERNEL_PARAM_OPS(quirks_param_ops, quirks_param_set, + param_get_string);static struct kparam_string quirks_param_string = { .maxlen =sizeof (quirks_param),@@ -257,10 +253,8 @@ static int io_queue_count_set(const char *val, const struct kernel_param *kp)return param_set_uint (val, kp); } -static const struct kernel_param_ops io_queue_count_ops = { - .set = io_queue_count_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(io_queue_count_ops, io_queue_count_set, + param_get_uint);static unsigned int write_queues;module_param_cb (write_queues, &io_queue_count_ops, &write_queues,0644 );drivers/nvme/target/rdma.c +1
-4@@ -147,10 +147,7 @@ module_param_named(use_srq, nvmet_rdma_use_srq, bool, 0444);MODULE_PARM_DESC (use_srq,"Use shared receive queue." );static int srq_size_set (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops srq_size_ops = { - .set = srq_size_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(srq_size_ops, srq_size_set, param_get_int);static int nvmet_rdma_srq_size =1024 ;module_param_cb (srq_size, &srq_size_ops, &nvmet_rdma_srq_size,0644 );drivers/nvme/target/tcp.c +1
-4@@ -46,10 +46,7 @@ static int set_params(const char *str, const struct kernel_param *kp)return param_store_val (str, kp->arg,0 ,INT_MAX ); } -static const struct kernel_param_ops set_param_ops = { - .set = set_params, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(set_param_ops, set_params, param_get_int);/* Define the socket priority to use for connections were it is desirable * that the NIC consider performing optimized packet processing or filtering. drivers/platform/x86/acerhdf.c +1
-4@@ -762,10 +762,7 @@ static int interval_set_uint(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops interval_ops = { - .set = interval_set_uint, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(interval_ops, interval_set_uint, param_get_uint);module_param_cb (interval, &interval_ops, &interval,0000 );MODULE_PARM_DESC (interval,"Polling interval of temperature check" );drivers/power/supply/bq27xxx_battery.c +2
-4@@ -1133,10 +1133,8 @@ static int poll_interval_param_set(const char *val, const struct kernel_param *kreturn ret; } -static const struct kernel_param_ops param_ops_poll_interval = { - .get = param_get_uint, - .set = poll_interval_param_set, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_poll_interval, poll_interval_param_set, + param_get_uint);static unsigned int poll_interval =360 ;module_param_cb (poll_interval, ¶m_ops_poll_interval, &poll_interval,0644 );drivers/power/supply/test_power.c +31
-44@@ -649,60 +649,47 @@ static int param_set_battery_extension(const char *key,#define param_get_battery_extension param_get_bool -static const struct kernel_param_ops param_ops_ac_online = { - .set = param_set_ac_online, - .get = param_get_ac_online, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_ac_online, param_set_ac_online, + param_get_ac_online); -static const struct kernel_param_ops param_ops_usb_online = { - .set = param_set_usb_online, - .get = param_get_usb_online, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_usb_online, param_set_usb_online, + param_get_usb_online); -static const struct kernel_param_ops param_ops_battery_status = { - .set = param_set_battery_status, - .get = param_get_battery_status, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_battery_status, + param_set_battery_status, + param_get_battery_status); -static const struct kernel_param_ops param_ops_battery_present = { - .set = param_set_battery_present, - .get = param_get_battery_present, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_battery_present, + param_set_battery_present, + param_get_battery_present); -static const struct kernel_param_ops param_ops_battery_technology = { - .set = param_set_battery_technology, - .get = param_get_battery_technology, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_battery_technology, + param_set_battery_technology, + param_get_battery_technology); -static const struct kernel_param_ops param_ops_battery_health = { - .set = param_set_battery_health, - .get = param_get_battery_health, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_battery_health, + param_set_battery_health, + param_get_battery_health); -static const struct kernel_param_ops param_ops_battery_capacity = { - .set = param_set_battery_capacity, - .get = param_get_battery_capacity, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_battery_capacity, + param_set_battery_capacity, + param_get_battery_capacity); -static const struct kernel_param_ops param_ops_battery_voltage = { - .set = param_set_battery_voltage, - .get = param_get_battery_voltage, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_battery_voltage, + param_set_battery_voltage, + param_get_battery_voltage); -static const struct kernel_param_ops param_ops_battery_charge_counter = { - .set = param_set_battery_charge_counter, - .get = param_get_battery_charge_counter, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_battery_charge_counter, + param_set_battery_charge_counter, + param_get_battery_charge_counter); -static const struct kernel_param_ops param_ops_battery_current = { - .set = param_set_battery_current, - .get = param_get_battery_current, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_battery_current, + param_set_battery_current, + param_get_battery_current); -static const struct kernel_param_ops param_ops_battery_extension = { - .set = param_set_battery_extension, - .get = param_get_battery_extension, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_battery_extension, + param_set_battery_extension, + param_get_battery_extension);#define param_check_ac_online (name, p) __param_check(name, p, void);#define param_check_usb_online (name, p) __param_check(name, p, void);drivers/scsi/sg.c +2
-4@@ -1644,10 +1644,8 @@ static int def_reserved_size_set(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops def_reserved_size_ops = { - .set = def_reserved_size_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(def_reserved_size_ops, def_reserved_size_set, + param_get_int);module_param_cb (def_reserved_size, &def_reserved_size_ops, &def_reserved_size,S_IRUGO |S_IWUSR );drivers/target/target_core_user.c +5
-8@@ -255,10 +255,9 @@ static int tcmu_get_global_max_data_area(char *buffer,return sprintf (buffer,"%d\n" ,TCMU_PAGES_TO_MBS (tcmu_global_max_pages)); } -static const struct kernel_param_ops tcmu_global_max_data_area_op = { - .set = tcmu_set_global_max_data_area, - .get = tcmu_get_global_max_data_area, -}; +static DEFINE_KERNEL_PARAM_OPS(tcmu_global_max_data_area_op, + tcmu_set_global_max_data_area, + tcmu_get_global_max_data_area);module_param_cb (global_max_data_area_mb, &tcmu_global_max_data_area_op,NULL ,S_IWUSR |S_IRUGO );@@ -292,10 +291,8 @@ static int tcmu_set_block_netlink(const char *str,return 0 ; } -static const struct kernel_param_ops tcmu_block_netlink_op = { - .set = tcmu_set_block_netlink, - .get = tcmu_get_block_netlink, -}; +static DEFINE_KERNEL_PARAM_OPS(tcmu_block_netlink_op, tcmu_set_block_netlink, + tcmu_get_block_netlink);module_param_cb (block_netlink, &tcmu_block_netlink_op,NULL ,S_IWUSR |S_IRUGO );MODULE_PARM_DESC (block_netlink,"Block new netlink commands." );drivers/thermal/intel/int340x_thermal/processor_thermal_soc_slider.c +4
-8@@ -83,10 +83,8 @@ static int slider_def_balance_get(char *buf, const struct kernel_param *kp)return sysfs_emit (buf,"%02x\n" , slider_values[SOC_POWER_SLIDER_BALANCE ]); } -static const struct kernel_param_ops slider_def_balance_ops = { - .set = slider_def_balance_set, - .get = slider_def_balance_get, -}; +static DEFINE_KERNEL_PARAM_OPS(slider_def_balance_ops, slider_def_balance_set, + slider_def_balance_get);module_param_cb (slider_balance, &slider_def_balance_ops,NULL ,0644 );MODULE_PARM_DESC (slider_balance,"Set slider default value for balance" );@@ -117,10 +115,8 @@ static int slider_def_offset_get(char *buf, const struct kernel_param *kp)return sysfs_emit (buf,"%02x\n" , slider_offset); } -static const struct kernel_param_ops slider_offset_ops = { - .set = slider_def_offset_set, - .get = slider_def_offset_get, -}; +static DEFINE_KERNEL_PARAM_OPS(slider_offset_ops, slider_def_offset_set, + slider_def_offset_get);/* * To enhance power efficiency dynamically, the firmware can optionally drivers/thermal/intel/intel_powerclamp.c +4
-16@@ -112,10 +112,7 @@ static int duration_get(char *buf, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops duration_ops = { - .set = duration_set, - .get = duration_get, -}; +static DEFINE_KERNEL_PARAM_OPS(duration_ops, duration_set, duration_get);module_param_cb (duration, &duration_ops,NULL ,0644 );MODULE_PARM_DESC (duration,"forced idle time for each attempt in msec." );@@ -203,10 +200,7 @@ static int cpumask_get(char *buf, const struct kernel_param *kp)return cpumap_print_to_pagebuf (false, buf, idle_injection_cpu_mask); } -static const struct kernel_param_ops cpumask_ops = { - .set = cpumask_set, - .get = cpumask_get, -}; +static DEFINE_KERNEL_PARAM_OPS(cpumask_ops, cpumask_set, cpumask_get);module_param_cb (cpumask, &cpumask_ops,NULL ,0644 );MODULE_PARM_DESC (cpumask,"Mask of CPUs to use for idle injection." );@@ -252,10 +246,7 @@ static int max_idle_set(const char *arg, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops max_idle_ops = { - .set = max_idle_set, - .get = param_get_byte, -}; +static DEFINE_KERNEL_PARAM_OPS(max_idle_ops, max_idle_set, param_get_byte);module_param_cb (max_idle, &max_idle_ops, &max_idle,0644 );MODULE_PARM_DESC (max_idle,"maximum injected idle time to the total CPU time ratio in percent range:1-100" );@@ -299,10 +290,7 @@ static int window_size_set(const char *arg, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops window_size_ops = { - .set = window_size_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(window_size_ops, window_size_set, param_get_int);module_param_cb (window_size, &window_size_ops, &window_size,0644 ); MODULE_PARM_DESC(window_size, "sliding window in number of clamping cycles\n"drivers/tty/hvc/hvc_iucv.c +2
-4@@ -1290,10 +1290,8 @@ static int param_get_vmidfilter(char *buffer, const struct kernel_param *kp)#define param_check_vmidfilter (name, p) __param_check(name, p, void) -static const struct kernel_param_ops param_ops_vmidfilter = { - .set = param_set_vmidfilter, - .get = param_get_vmidfilter, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_vmidfilter, param_set_vmidfilter, + param_get_vmidfilter);/** * hvc_iucv_init() - z/VM IUCV HVC device driver initialization drivers/tty/sysrq.c +2
-4@@ -1074,10 +1074,8 @@ static int sysrq_reset_seq_param_set(const char *buffer,return 0 ; } -static const struct kernel_param_ops param_ops_sysrq_reset_seq = { - .get = param_get_ushort, - .set = sysrq_reset_seq_param_set, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_sysrq_reset_seq, + sysrq_reset_seq_param_set, param_get_ushort);#define param_check_sysrq_reset_seq (name, p) \ __param_check(name, p, unsigned short)drivers/ufs/core/ufs-fault-injection.c +1
-4@@ -11,10 +11,7 @@static int ufs_fault_get (char *buffer,const struct kernel_param *kp);static int ufs_fault_set (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops ufs_fault_ops = { - .get = ufs_fault_get, - .set = ufs_fault_set, -}; +static DEFINE_KERNEL_PARAM_OPS(ufs_fault_ops, ufs_fault_set, ufs_fault_get);enum {FAULT_INJ_STR_SIZE =80 };drivers/ufs/core/ufs-mcq.c +6
-12@@ -43,10 +43,8 @@ static int rw_queue_count_set(const char *val, const struct kernel_param *kp) num_possible_cpus()); } -static const struct kernel_param_ops rw_queue_count_ops = { - .set = rw_queue_count_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(rw_queue_count_ops, rw_queue_count_set, + param_get_uint);static unsigned int rw_queues;module_param_cb (rw_queues, &rw_queue_count_ops, &rw_queues,0644 );@@ -59,10 +57,8 @@ static int read_queue_count_set(const char *val, const struct kernel_param *kp) num_possible_cpus()); } -static const struct kernel_param_ops read_queue_count_ops = { - .set = read_queue_count_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(read_queue_count_ops, read_queue_count_set, + param_get_uint);static unsigned int read_queues;module_param_cb (read_queues, &read_queue_count_ops, &read_queues,0644 );@@ -75,10 +71,8 @@ static int poll_queue_count_set(const char *val, const struct kernel_param *kp) num_possible_cpus()); } -static const struct kernel_param_ops poll_queue_count_ops = { - .set = poll_queue_count_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(poll_queue_count_ops, poll_queue_count_set, + param_get_uint);static unsigned int poll_queues =1 ;module_param_cb (poll_queues, &poll_queue_count_ops, &poll_queues,0644 );drivers/ufs/core/ufs-txeq.c +1
-4@@ -23,10 +23,7 @@ static int txeq_gear_set(const char *val, const struct kernel_param *kp)return param_set_uint_minmax (val, kp,UFS_HS_G1 ,UFS_HS_GEAR_MAX ); } -static const struct kernel_param_ops txeq_gear_ops = { - .set = txeq_gear_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(txeq_gear_ops, txeq_gear_set, param_get_uint);static unsigned int adaptive_txeq_gear =UFS_HS_G6 ;module_param_cb (adaptive_txeq_gear, &txeq_gear_ops, &adaptive_txeq_gear,0644 );drivers/ufs/core/ufshcd.c +4
-8@@ -128,10 +128,8 @@ static int uic_cmd_timeout_set(const char *val, const struct kernel_param *kp) UIC_CMD_TIMEOUT_MAX); } -static const struct kernel_param_ops uic_cmd_timeout_ops = { - .set = uic_cmd_timeout_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(uic_cmd_timeout_ops, uic_cmd_timeout_set, + param_get_uint);module_param_cb (uic_cmd_timeout, &uic_cmd_timeout_ops, &uic_cmd_timeout,0644 ); MODULE_PARM_DESC(uic_cmd_timeout,@@ -145,10 +143,8 @@ static int dev_cmd_timeout_set(const char *val, const struct kernel_param *kp) QUERY_REQ_TIMEOUT_MAX); } -static const struct kernel_param_ops dev_cmd_timeout_ops = { - .set = dev_cmd_timeout_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(dev_cmd_timeout_ops, dev_cmd_timeout_set, + param_get_uint);module_param_cb (dev_cmd_timeout, &dev_cmd_timeout_ops, &dev_cmd_timeout,0644 ); MODULE_PARM_DESC(dev_cmd_timeout,drivers/usb/core/quirks.c +2
-4@@ -160,10 +160,8 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops quirks_param_ops = { - .set = quirks_param_set, - .get = param_get_string, -}; +static DEFINE_KERNEL_PARAM_OPS(quirks_param_ops, quirks_param_set, + param_get_string);static struct kparam_string quirks_param_string = { .maxlen =sizeof (quirks_param),drivers/usb/gadget/legacy/serial.c +1
-4@@ -121,10 +121,7 @@ static int enable_set(const char *s, const struct kernel_param *kp)return ret; } -static const struct kernel_param_ops enable_ops = { - .set = enable_set, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(enable_ops, enable_set, param_get_bool);module_param_cb (enable, &enable_ops, &enable,0644 );drivers/usb/storage/usb.c +1
-4@@ -158,10 +158,7 @@ static int delay_use_get(char *s, const struct kernel_param *kp)return format_delay_ms (delay_ms,3 ,"ms" , s,PAGE_SIZE ); } -static const struct kernel_param_ops delay_use_ops = { - .set = delay_use_set, - .get = delay_use_get, -}; +static DEFINE_KERNEL_PARAM_OPS(delay_use_ops, delay_use_set, delay_use_get);module_param_cb (delay_use, &delay_use_ops, &delay_use,0644 );MODULE_PARM_DESC (delay_use,"time to delay before using a new device" );drivers/vhost/scsi.c +3
-4@@ -87,10 +87,9 @@ static int vhost_scsi_get_inline_sg_cnt(char *buf,return sprintf (buf,"%u\n" , vhost_scsi_inline_sg_cnt); } -static const struct kernel_param_ops vhost_scsi_inline_sg_cnt_op = { - .get = vhost_scsi_get_inline_sg_cnt, - .set = vhost_scsi_set_inline_sg_cnt, -}; +static DEFINE_KERNEL_PARAM_OPS(vhost_scsi_inline_sg_cnt_op, + vhost_scsi_set_inline_sg_cnt, + vhost_scsi_get_inline_sg_cnt);module_param_cb (inline_sg_cnt, &vhost_scsi_inline_sg_cnt_op,NULL ,0644 );MODULE_PARM_DESC (inline_sg_cnt,"Set the number of scatterlist entries to pre-allocate. The default is 2048." );drivers/virt/nitro_enclaves/ne_misc_dev.c +2
-4@@ -86,10 +86,8 @@ struct ne_devs ne_devs = {*/ static int ne_set_kernel_param (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops ne_cpu_pool_ops = { - .get = param_get_string, - .set = ne_set_kernel_param, -}; +static DEFINE_KERNEL_PARAM_OPS(ne_cpu_pool_ops, ne_set_kernel_param, + param_get_string);static char ne_cpus[NE_CPUS_SIZE ];static struct kparam_string ne_cpus_arg = {drivers/virtio/virtio_mmio.c +2
-4@@ -748,10 +748,8 @@ static int vm_cmdline_get(char *buffer, const struct kernel_param *kp)return strlen (buffer) +1 ; } -static const struct kernel_param_ops vm_cmdline_param_ops = { - .set = vm_cmdline_set, - .get = vm_cmdline_get, -}; +static DEFINE_KERNEL_PARAM_OPS(vm_cmdline_param_ops, vm_cmdline_set, + vm_cmdline_get);device_param_cb (device, &vm_cmdline_param_ops,NULL ,S_IRUSR );fs/ceph/super.c +3
-7@@ -1684,10 +1684,8 @@ static int param_set_metrics(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops param_ops_metrics = { - .set = param_set_metrics, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_metrics, param_set_metrics, + param_get_bool);bool disable_send_metrics = false;module_param_cb (disable_send_metrics, ¶m_ops_metrics, &disable_send_metrics,0644 );@@ -1695,9 +1693,7 @@ MODULE_PARM_DESC(disable_send_metrics, "Enable sending perf metrics to ceph clus/* for both v1 and v2 syntax */ static bool mount_support = true; -static const struct kernel_param_ops param_ops_mount_syntax = { - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_mount_syntax, NULL, param_get_bool);module_param_cb (mount_syntax_v1, ¶m_ops_mount_syntax, &mount_support,0444 );module_param_cb (mount_syntax_v2, ¶m_ops_mount_syntax, &mount_support,0444 );fs/fuse/dir.c +1
-4@@ -71,10 +71,7 @@ static int inval_wq_set(const char *val, const struct kernel_param *kp)return 0 ; } -static const struct kernel_param_ops inval_wq_ops = { - .set = inval_wq_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(inval_wq_ops, inval_wq_set, param_get_uint);module_param_cb (inval_wq, &inval_wq_ops, &inval_wq,0644 );__MODULE_PARM_TYPE (inval_wq,"uint" ); MODULE_PARM_DESC(inval_wq,fs/nfs/namespace.c +2
-4@@ -372,10 +372,8 @@ static int param_get_nfs_timeout(char *buffer, const struct kernel_param *kp)return sysfs_emit (buffer,"%li\n" , num); } -static const struct kernel_param_ops param_ops_nfs_timeout = { - .set = param_set_nfs_timeout, - .get = param_get_nfs_timeout, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_nfs_timeout, param_set_nfs_timeout, + param_get_nfs_timeout);#define param_check_nfs_timeout (name, p) __param_check(name, p, int)module_param (nfs_mountpoint_expiry_timeout, nfs_timeout,0644 );fs/nfs/super.c +2
-4@@ -1419,10 +1419,8 @@ static int param_set_portnr(const char *val, const struct kernel_param *kp) *((unsigned int *)kp->arg) = num;return 0 ; } -static const struct kernel_param_ops param_ops_portnr = { - .set = param_set_portnr, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_portnr, param_set_portnr, + param_get_uint);#define param_check_portnr (name, p) __param_check(name, p, unsigned int)module_param_named (callback_tcpport, nfs_callback_set_tcpport, portnr,0644 );fs/ubifs/super.c +2
-4@@ -36,10 +36,8 @@ static int ubifs_default_version_set(const char *val, const struct kernel_paramreturn param_set_int (val, kp); } -static const struct kernel_param_ops ubifs_default_version_ops = { - .set = ubifs_default_version_set, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(ubifs_default_version_ops, + ubifs_default_version_set, param_get_int);int ubifs_default_version =UBIFS_FORMAT_VERSION ;module_param_cb (default_version, &ubifs_default_version_ops, &ubifs_default_version,0600 );kernel/locking/locktorture.c +2
-4@@ -98,10 +98,8 @@ static bool cpumask_nonempty(cpumask_var_t mask)return cpumask_available (mask) && !cpumask_empty (mask); } -static const struct kernel_param_ops lt_bind_ops = { - .set = param_set_cpumask, - .get = param_get_cpumask, -}; +static DEFINE_KERNEL_PARAM_OPS(lt_bind_ops, param_set_cpumask, + param_get_cpumask);module_param_cb (bind_readers, <_bind_ops, &bind_readers,0444 );module_param_cb (bind_writers, <_bind_ops, &bind_writers,0444 );kernel/panic.c +2
-4@@ -1214,10 +1214,8 @@ static int panic_print_set(const char *val, const struct kernel_param *kp)return param_set_ulong (val, kp); } -static const struct kernel_param_ops panic_print_ops = { - .set = panic_print_set, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(panic_print_ops, panic_print_set, + param_get_ulong);__core_param_cb (panic_print, &panic_print_ops, &panic_print,0644 );static int __init oops_setup (char *s)kernel/params.c +11
-33@@ -297,11 +297,8 @@ void param_free_charp(void *arg) }EXPORT_SYMBOL (param_free_charp); -const struct kernel_param_ops param_ops_charp = { - .set = param_set_charp, - .get = param_get_charp, - .free = param_free_charp, -}; +DEFINE_KERNEL_PARAM_OPS_FREE (param_ops_charp, param_set_charp, param_get_charp, + param_free_charp);EXPORT_SYMBOL (param_ops_charp);/* Actually could be a bool or an int, for historical reasons. */ @@ -322,11 +319,7 @@ int param_get_bool(char *buffer, const struct kernel_param *kp) }EXPORT_SYMBOL (param_get_bool); -const struct kernel_param_ops param_ops_bool = { - .flags =KERNEL_PARAM_OPS_FL_NOARG , - .set = param_set_bool, - .get = param_get_bool, -}; +DEFINE_KERNEL_PARAM_OPS_NOARG (param_ops_bool, param_set_bool, param_get_bool);EXPORT_SYMBOL (param_ops_bool);int param_set_bool_enable_only (const char *val,const struct kernel_param *kp)@@ -353,11 +346,8 @@ int param_set_bool_enable_only(const char *val, const struct kernel_param *kp) }EXPORT_SYMBOL_GPL (param_set_bool_enable_only); -const struct kernel_param_ops param_ops_bool_enable_only = { - .flags =KERNEL_PARAM_OPS_FL_NOARG , - .set = param_set_bool_enable_only, - .get = param_get_bool, -}; +DEFINE_KERNEL_PARAM_OPS_NOARG (param_ops_bool_enable_only, + param_set_bool_enable_only, param_get_bool);EXPORT_SYMBOL_GPL (param_ops_bool_enable_only);/* This one must be bool. */ @@ -381,10 +371,7 @@ int param_get_invbool(char *buffer, const struct kernel_param *kp) }EXPORT_SYMBOL (param_get_invbool); -const struct kernel_param_ops param_ops_invbool = { - .set = param_set_invbool, - .get = param_get_invbool, -}; +DEFINE_KERNEL_PARAM_OPS (param_ops_invbool, param_set_invbool, param_get_invbool);EXPORT_SYMBOL (param_ops_invbool);int param_set_bint (const char *val,const struct kernel_param *kp)@@ -403,11 +390,7 @@ int param_set_bint(const char *val, const struct kernel_param *kp) }EXPORT_SYMBOL (param_set_bint); -const struct kernel_param_ops param_ops_bint = { - .flags =KERNEL_PARAM_OPS_FL_NOARG , - .set = param_set_bint, - .get = param_get_int, -}; +DEFINE_KERNEL_PARAM_OPS_NOARG (param_ops_bint, param_set_bint, param_get_int);EXPORT_SYMBOL (param_ops_bint);/* We break the rule and mangle the string. */ @@ -515,11 +498,8 @@ static void param_array_free(void *arg) arr->ops->free (arr->elem + arr->elemsize * i); } -const struct kernel_param_ops param_array_ops = { - .set = param_array_set, - .get = param_array_get, - .free = param_array_free, -}; +DEFINE_KERNEL_PARAM_OPS_FREE (param_array_ops, param_array_set, param_array_get, + param_array_free);EXPORT_SYMBOL (param_array_ops);int param_set_copystring (const char *val,const struct kernel_param *kp)@@ -544,10 +524,8 @@ int param_get_string(char *buffer, const struct kernel_param *kp) }EXPORT_SYMBOL (param_get_string); -const struct kernel_param_ops param_ops_string = { - .set = param_set_copystring, - .get = param_get_string, -}; +DEFINE_KERNEL_PARAM_OPS (param_ops_string, param_set_copystring, + param_get_string);EXPORT_SYMBOL (param_ops_string);/* sysfs output in /sys/modules/XYZ/parameters/ */ kernel/power/hibernate.c +2
-4@@ -1528,10 +1528,8 @@ static int hibernate_compressor_param_set(const char *compressor,return ret; } -static const struct kernel_param_ops hibernate_compressor_param_ops = { - .set = hibernate_compressor_param_set, - .get = param_get_string, -}; +static DEFINE_KERNEL_PARAM_OPS(hibernate_compressor_param_ops, + hibernate_compressor_param_set, param_get_string);static struct kparam_string hibernate_compressor_param_string = { .maxlen =sizeof (hibernate_compressor),kernel/rcu/tree.c +6
-12@@ -498,15 +498,11 @@ static int param_set_next_fqs_jiffies(const char *val, const struct kernel_paramreturn ret; } -static const struct kernel_param_ops first_fqs_jiffies_ops = { - .set = param_set_first_fqs_jiffies, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(first_fqs_jiffies_ops, + param_set_first_fqs_jiffies, param_get_ulong); -static const struct kernel_param_ops next_fqs_jiffies_ops = { - .set = param_set_next_fqs_jiffies, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(next_fqs_jiffies_ops, param_set_next_fqs_jiffies, + param_get_ulong);module_param_cb (jiffies_till_first_fqs, &first_fqs_jiffies_ops, &jiffies_till_first_fqs,0644 );module_param_cb (jiffies_till_next_fqs, &next_fqs_jiffies_ops, &jiffies_till_next_fqs,0644 );@@ -3979,10 +3975,8 @@ static int param_get_do_rcu_barrier(char *buffer, const struct kernel_param *kp)return sprintf (buffer,"%d\n" ,atomic_read ((atomic_t *)kp->arg)); } -static const struct kernel_param_ops do_rcu_barrier_ops = { - .set = param_set_do_rcu_barrier, - .get = param_get_do_rcu_barrier, -}; +static DEFINE_KERNEL_PARAM_OPS(do_rcu_barrier_ops, param_set_do_rcu_barrier, + param_get_do_rcu_barrier);static atomic_t do_rcu_barrier;module_param_cb (do_rcu_barrier, &do_rcu_barrier_ops, &do_rcu_barrier,0644 );kernel/sched/ext.c +3
-8@@ -166,20 +166,15 @@ static int set_slice_us(const char *val, const struct kernel_param *kp)return param_set_uint_minmax (val, kp,100 ,100 *USEC_PER_MSEC ); } -static const struct kernel_param_ops slice_us_param_ops = { - .set = set_slice_us, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(slice_us_param_ops, set_slice_us, param_get_uint);static int set_bypass_lb_intv_us (const char *val,const struct kernel_param *kp) {return param_set_uint_minmax (val, kp,0 ,10 *USEC_PER_SEC ); } -static const struct kernel_param_ops bypass_lb_intv_us_param_ops = { - .set = set_bypass_lb_intv_us, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(bypass_lb_intv_us_param_ops, + set_bypass_lb_intv_us, param_get_uint);#undef MODULE_PARAM_PREFIX#define MODULE_PARAM_PREFIX "sched_ext."kernel/workqueue.c +4
-8@@ -7162,10 +7162,8 @@ static int wq_affn_dfl_get(char *buffer, const struct kernel_param *kp)return scnprintf (buffer,PAGE_SIZE ,"%s\n" , wq_affn_names[wq_affn_dfl]); } -static const struct kernel_param_ops wq_affn_dfl_ops = { - .set = wq_affn_dfl_set, - .get = wq_affn_dfl_get, -}; +static DEFINE_KERNEL_PARAM_OPS(wq_affn_dfl_ops, wq_affn_dfl_set, + wq_affn_dfl_get);module_param_cb (default_affinity_scope, &wq_affn_dfl_ops,NULL ,0644 );@@ -7861,10 +7859,8 @@ static int wq_watchdog_param_set_thresh(const char *val,return 0 ; } -static const struct kernel_param_ops wq_watchdog_thresh_ops = { - .set = wq_watchdog_param_set_thresh, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(wq_watchdog_thresh_ops, + wq_watchdog_param_set_thresh, param_get_ulong);module_param_cb (watchdog_thresh, &wq_watchdog_thresh_ops, &wq_watchdog_thresh,0644 );lib/dynamic_debug.c +2
-4@@ -807,10 +807,8 @@ int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp) }EXPORT_SYMBOL (param_get_dyndbg_classes); -const struct kernel_param_ops param_ops_dyndbg_classes = { - .set = param_set_dyndbg_classes, - .get = param_get_dyndbg_classes, -}; +DEFINE_KERNEL_PARAM_OPS (param_ops_dyndbg_classes, param_set_dyndbg_classes, + param_get_dyndbg_classes);EXPORT_SYMBOL (param_ops_dyndbg_classes);#define PREFIX_SIZE 128lib/test_dynamic_debug.c +2
-4@@ -23,10 +23,8 @@ static int param_get_do_prints(char *buffer, const struct kernel_param *kp)do_prints ();return scnprintf (buffer,PAGE_SIZE ,"did do_prints\n" ); } -static const struct kernel_param_ops param_ops_do_prints = { - .set = param_set_do_prints, - .get = param_get_do_prints, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_do_prints, param_set_do_prints, + param_get_do_prints);module_param_cb (do_prints, ¶m_ops_do_prints,NULL ,0600 );/* mm/damon/lru_sort.c +7
-12@@ -405,10 +405,8 @@ static int damon_lru_sort_addr_unit_store(const char *val,return 0 ; } -static const struct kernel_param_ops addr_unit_param_ops = { - .set = damon_lru_sort_addr_unit_store, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(addr_unit_param_ops, + damon_lru_sort_addr_unit_store, param_get_ulong);module_param_cb (addr_unit, &addr_unit_param_ops, &addr_unit,0600 ); MODULE_PARM_DESC(addr_unit,@@ -446,10 +444,8 @@ static int damon_lru_sort_enabled_load(char *buffer,return sprintf (buffer,"%c\n" ,damon_lru_sort_enabled () ?'Y' :'N' ); } -static const struct kernel_param_ops enabled_param_ops = { - .set = damon_lru_sort_enabled_store, - .get = damon_lru_sort_enabled_load, -}; +static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, damon_lru_sort_enabled_store, + damon_lru_sort_enabled_load);module_param_cb (enabled, &enabled_param_ops, &enabled,0600 ); MODULE_PARM_DESC(enabled,@@ -478,10 +474,9 @@ static int damon_lru_sort_kdamond_pid_load(char *buffer,return sprintf (buffer,"%d\n" , kdamond_pid); } -static const struct kernel_param_ops kdamond_pid_param_ops = { - .set = damon_lru_sort_kdamond_pid_store, - .get = damon_lru_sort_kdamond_pid_load, -}; +static DEFINE_KERNEL_PARAM_OPS(kdamond_pid_param_ops, + damon_lru_sort_kdamond_pid_store, + damon_lru_sort_kdamond_pid_load);/* * PID of the DAMON thread mm/damon/reclaim.c +7
-12@@ -307,10 +307,8 @@ static int damon_reclaim_addr_unit_store(const char *val,return 0 ; } -static const struct kernel_param_ops addr_unit_param_ops = { - .set = damon_reclaim_addr_unit_store, - .get = param_get_ulong, -}; +static DEFINE_KERNEL_PARAM_OPS(addr_unit_param_ops, + damon_reclaim_addr_unit_store, param_get_ulong);module_param_cb (addr_unit, &addr_unit_param_ops, &addr_unit,0600 ); MODULE_PARM_DESC(addr_unit,@@ -348,10 +346,8 @@ static int damon_reclaim_enabled_load(char *buffer,return sprintf (buffer,"%c\n" ,damon_reclaim_enabled () ?'Y' :'N' ); } -static const struct kernel_param_ops enabled_param_ops = { - .set = damon_reclaim_enabled_store, - .get = damon_reclaim_enabled_load, -}; +static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, damon_reclaim_enabled_store, + damon_reclaim_enabled_load);module_param_cb (enabled, &enabled_param_ops, &enabled,0600 ); MODULE_PARM_DESC(enabled,@@ -380,10 +376,9 @@ static int damon_reclaim_kdamond_pid_load(char *buffer,return sprintf (buffer,"%d\n" , kdamond_pid); } -static const struct kernel_param_ops kdamond_pid_param_ops = { - .set = damon_reclaim_kdamond_pid_store, - .get = damon_reclaim_kdamond_pid_load, -}; +static DEFINE_KERNEL_PARAM_OPS(kdamond_pid_param_ops, + damon_reclaim_kdamond_pid_store, + damon_reclaim_kdamond_pid_load);/* * PID of the DAMON thread mm/damon/stat.c +2
-4@@ -22,10 +22,8 @@ static int damon_stat_enabled_store(static int damon_stat_enabled_load (char *buffer,const struct kernel_param *kp); -static const struct kernel_param_ops enabled_param_ops = { - .set = damon_stat_enabled_store, - .get = damon_stat_enabled_load, -}; +static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, damon_stat_enabled_store, + damon_stat_enabled_load);static bool enabled__read_mostly =IS_ENABLED (CONFIG_DAMON_STAT_ENABLED_DEFAULT );mm/memory_hotplug.c +4
-8@@ -109,10 +109,8 @@ static int get_memmap_mode(char *buffer, const struct kernel_param *kp)return sprintf (buffer,"%c\n" , mode ?'Y' :'N' ); } -static const struct kernel_param_ops memmap_mode_ops = { - .set = set_memmap_mode, - .get = get_memmap_mode, -}; +static DEFINE_KERNEL_PARAM_OPS(memmap_mode_ops, set_memmap_mode, + get_memmap_mode);module_param_cb (memmap_on_memory, &memmap_mode_ops, &memmap_mode,0444 );MODULE_PARM_DESC (memmap_on_memory,"Enable memmap on memory for memory hotplug\n" "With value \"force\" it could result in memory wastage due "@@ -163,10 +161,8 @@ static int get_online_policy(char *buffer, const struct kernel_param *kp)* (auto_movable_ratio, auto_movable_numa_aware) allows for it */ static int online_policy__read_mostly =ONLINE_POLICY_CONTIG_ZONES ; -static const struct kernel_param_ops online_policy_ops = { - .set = set_online_policy, - .get = get_online_policy, -}; +static DEFINE_KERNEL_PARAM_OPS(online_policy_ops, set_online_policy, + get_online_policy);module_param_cb (online_policy, &online_policy_ops, &online_policy,0644 );MODULE_PARM_DESC (online_policy, "Set the online policy (\"contig-zones\", \"auto-movable\") "mm/page_reporting.c +2
-9@@ -23,15 +23,8 @@ static int page_order_update_notify(const char *val, const struct kernel_param *return param_set_uint_minmax (val, kp,0 ,MAX_PAGE_ORDER ); } -static const struct kernel_param_ops page_reporting_param_ops = { - .set = &page_order_update_notify, -/* -* For the get op, use param_get_int instead of param_get_uint. -* This is to make sure that when unset the initialized value of -* -1 is shown correctly -*/ - .get = ¶m_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(page_reporting_param_ops, + &page_order_update_notify, ¶m_get_int);module_param_cb (page_reporting_order, &page_reporting_param_ops, &page_reporting_order,0644 );mm/shuffle.c +2
-4@@ -23,10 +23,8 @@ static __meminit int shuffle_param_set(const char *val,return 0 ; } -static const struct kernel_param_ops shuffle_param_ops = { - .set = shuffle_param_set, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(shuffle_param_ops, shuffle_param_set, + param_get_bool);module_param_cb (shuffle, &shuffle_param_ops, &shuffle_param,0400 );/* mm/zswap.c +5
-9@@ -90,21 +90,17 @@ static DEFINE_STATIC_KEY_MAYBE(CONFIG_ZSWAP_DEFAULT_ON, zswap_ever_enabled);static bool zswap_enabled =IS_ENABLED (CONFIG_ZSWAP_DEFAULT_ON );static int zswap_enabled_param_set (const char *,const struct kernel_param *); -static const struct kernel_param_ops zswap_enabled_param_ops = { - .set = zswap_enabled_param_set, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(zswap_enabled_param_ops, zswap_enabled_param_set, + param_get_bool);module_param_cb (enabled, &zswap_enabled_param_ops, &zswap_enabled,0644 );/* Crypto compressor to use */ static char *zswap_compressor =CONFIG_ZSWAP_COMPRESSOR_DEFAULT ;static int zswap_compressor_param_set (const char *,const struct kernel_param *); -static const struct kernel_param_ops zswap_compressor_param_ops = { - .set = zswap_compressor_param_set, - .get = param_get_charp, - .free = param_free_charp, -}; +static DEFINE_KERNEL_PARAM_OPS_FREE(zswap_compressor_param_ops, + zswap_compressor_param_set, param_get_charp, + param_free_charp);module_param_cb (compressor, &zswap_compressor_param_ops, &zswap_compressor,0644 );net/batman-adv/bat_algo.c +2
-4@@ -134,10 +134,8 @@ static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)return param_set_copystring (algo_name, kp); } -static const struct kernel_param_ops batadv_param_ops_ra = { - .set = batadv_param_set_ra, - .get = param_get_string, -}; +static DEFINE_KERNEL_PARAM_OPS(batadv_param_ops_ra, batadv_param_set_ra, + param_get_string);static struct kparam_string batadv_param_string_ra = { .maxlen =sizeof (batadv_routing_algo),net/ceph/ceph_common.c +2
-3@@ -52,9 +52,8 @@ static int param_get_supported_features(char *buffer, {return sprintf (buffer,"0x%llx" ,CEPH_FEATURES_SUPPORTED_DEFAULT ); } -static const struct kernel_param_ops param_ops_supported_features = { - .get = param_get_supported_features, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_supported_features, NULL, + param_get_supported_features);module_param_cb (supported_features, ¶m_ops_supported_features,NULL ,0444 );net/ipv4/tcp_dctcp.c +2
-4@@ -64,10 +64,8 @@ static int dctcp_shift_g_set(const char *val, const struct kernel_param *kp)return param_set_uint_minmax (val, kp,0 ,10 ); } -static const struct kernel_param_ops dctcp_shift_g_ops = { - .set = dctcp_shift_g_set, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(dctcp_shift_g_ops, dctcp_shift_g_set, + param_get_uint);module_param_cb (dctcp_shift_g, &dctcp_shift_g_ops, &dctcp_shift_g,0644 );MODULE_PARM_DESC (dctcp_shift_g,"parameter g for updating dctcp_alpha" );net/sunrpc/auth.c +2
-4@@ -83,10 +83,8 @@ static int param_get_hashtbl_sz(char *buffer, const struct kernel_param *kp)#define param_check_hashtbl_sz (name, p) __param_check(name, p, unsigned int); -static const struct kernel_param_ops param_ops_hashtbl_sz = { - .set = param_set_hashtbl_sz, - .get = param_get_hashtbl_sz, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_hashtbl_sz, param_set_hashtbl_sz, + param_get_hashtbl_sz);module_param_named (auth_hashtable_size, auth_hashbits, hashtbl_sz,0644 );MODULE_PARM_DESC (auth_hashtable_size,"RPC credential cache hashtable size" );net/sunrpc/xprtsock.c +6
-12@@ -3710,10 +3710,8 @@ static int param_set_portnr(const char *val, const struct kernel_param *kp) RPC_MAX_RESVPORT); } -static const struct kernel_param_ops param_ops_portnr = { - .set = param_set_portnr, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_portnr, param_set_portnr, + param_get_uint);#define param_check_portnr (name, p) \ __param_check(name, p, unsigned int);@@ -3729,10 +3727,8 @@ static int param_set_slot_table_size(const char *val, RPC_MAX_SLOT_TABLE); } -static const struct kernel_param_ops param_ops_slot_table_size = { - .set = param_set_slot_table_size, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_slot_table_size, + param_set_slot_table_size, param_get_uint);#define param_check_slot_table_size (name, p) \ __param_check(name, p, unsigned int);@@ -3745,10 +3741,8 @@ static int param_set_max_slot_table_size(const char *val, RPC_MAX_SLOT_TABLE_LIMIT); } -static const struct kernel_param_ops param_ops_max_slot_table_size = { - .set = param_set_max_slot_table_size, - .get = param_get_uint, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_max_slot_table_size, + param_set_max_slot_table_size, param_get_uint);#define param_check_max_slot_table_size (name, p) \ __param_check(name, p, unsigned int);samples/damon/mtier.c +2
-4@@ -38,10 +38,8 @@ module_param(node0_mem_free_bp, ulong, 0600);static int damon_sample_mtier_enable_store (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops enabled_param_ops = { - .set = damon_sample_mtier_enable_store, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, + damon_sample_mtier_enable_store, param_get_bool);static bool enabled__read_mostly ;module_param_cb (enabled, &enabled_param_ops, &enabled,0600 );samples/damon/prcl.c +2
-4@@ -22,10 +22,8 @@ module_param(target_pid, int, 0600);static int damon_sample_prcl_enable_store (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops enabled_param_ops = { - .set = damon_sample_prcl_enable_store, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, + damon_sample_prcl_enable_store, param_get_bool);static bool enabled__read_mostly ;module_param_cb (enabled, &enabled_param_ops, &enabled,0600 );samples/damon/wsse.c +2
-4@@ -23,10 +23,8 @@ module_param(target_pid, int, 0600);static int damon_sample_wsse_enable_store (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops enabled_param_ops = { - .set = damon_sample_wsse_enable_store, - .get = param_get_bool, -}; +static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, + damon_sample_wsse_enable_store, param_get_bool);static bool enabled__read_mostly ;module_param_cb (enabled, &enabled_param_ops, &enabled,0600 );security/apparmor/lsm.c +12
-22@@ -1767,38 +1767,30 @@ static struct security_hook_list apparmor_hooks[] __ro_after_init = {static int param_set_aabool (const char *val,const struct kernel_param *kp);static int param_get_aabool (char *buffer,const struct kernel_param *kp);#define param_check_aabool param_check_bool -static const struct kernel_param_ops param_ops_aabool = { - .flags =KERNEL_PARAM_OPS_FL_NOARG , - .set = param_set_aabool, - .get = param_get_aabool -}; +static DEFINE_KERNEL_PARAM_OPS_NOARG(param_ops_aabool, param_set_aabool, + param_get_aabool);static int param_set_aauint (const char *val,const struct kernel_param *kp);static int param_get_aauint (char *buffer,const struct kernel_param *kp);#define param_check_aauint param_check_uint -static const struct kernel_param_ops param_ops_aauint = { - .set = param_set_aauint, - .get = param_get_aauint -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_aauint, param_set_aauint, + param_get_aauint);static int param_set_aacompressionlevel (const char *val,const struct kernel_param *kp);static int param_get_aacompressionlevel (char *buffer,const struct kernel_param *kp);#define param_check_aacompressionlevel param_check_int -static const struct kernel_param_ops param_ops_aacompressionlevel = { - .set = param_set_aacompressionlevel, - .get = param_get_aacompressionlevel -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_aacompressionlevel, + param_set_aacompressionlevel, + param_get_aacompressionlevel);static int param_set_aalockpolicy (const char *val,const struct kernel_param *kp);static int param_get_aalockpolicy (char *buffer,const struct kernel_param *kp);#define param_check_aalockpolicy param_check_bool -static const struct kernel_param_ops param_ops_aalockpolicy = { - .flags =KERNEL_PARAM_OPS_FL_NOARG , - .set = param_set_aalockpolicy, - .get = param_get_aalockpolicy -}; +static DEFINE_KERNEL_PARAM_OPS_NOARG(param_ops_aalockpolicy, + param_set_aalockpolicy, + param_get_aalockpolicy);static int param_set_debug (const char *val,const struct kernel_param *kp);static int param_get_debug (char *buffer,const struct kernel_param *kp);@@ -1879,10 +1871,8 @@ module_param_named(paranoid_load, aa_g_paranoid_load, aabool, S_IRUGO);static int param_get_aaintbool (char *buffer,const struct kernel_param *kp);static int param_set_aaintbool (const char *val,const struct kernel_param *kp);#define param_check_aaintbool param_check_int -static const struct kernel_param_ops param_ops_aaintbool = { - .set = param_set_aaintbool, - .get = param_get_aaintbool -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_aaintbool, param_set_aaintbool, + param_get_aaintbool);/* Boot time disable flag */ static int apparmor_enabled__ro_after_init =1 ;module_param_named (enabled, apparmor_enabled, aaintbool,0444 );sound/hda/controllers/intel.c +1
-4@@ -164,10 +164,7 @@ MODULE_PARM_DESC(ctl_dev_id, "Use control device identifier (based on codec addr#ifdef CONFIG_PM static int param_set_xint (const char *val,const struct kernel_param *kp); -static const struct kernel_param_ops param_ops_xint = { - .set = param_set_xint, - .get = param_get_int, -}; +static DEFINE_KERNEL_PARAM_OPS(param_ops_xint, param_set_xint, param_get_int);#define param_check_xint param_check_intstatic int power_save =CONFIG_SND_HDA_POWER_SAVE_DEFAULT ;sound/usb/card.c +2
-6@@ -118,11 +118,8 @@ static int param_set_quirkp(const char *val,return param_set_charp (val, kp); } -static const struct kernel_param_ops param_ops_quirkp = { - .set = param_set_quirkp, - .get = param_get_charp, - .free = param_free_charp, -}; +static DEFINE_KERNEL_PARAM_OPS_FREE(param_ops_quirkp, param_set_quirkp, + param_get_charp, param_free_charp);#define param_check_quirkp param_check_charp --2.34.1
Re: [PATCH 04/11] treewide: Convert struct kernel_param_ops initializers to DEFINE_KERNEL_PARAM_OPS
In reply to Kees CookQuoted 21 lines · On Thu, 21 May 2026 06:33:17 -0700 Kees Cook <[email protected]> wrote:
Using Coccinelle, rewrite every struct
kernel_param_opsinitializer that sets .get into a DEFINE_KERNEL_PARAM_OPS-family macro invocation, for example:@@
declarer nameDEFINE_KERNEL_PARAM_OPS;
identifier OPS;
expression SET, GET;
@@
- const structkernel_param_opsOPS = {(quoted diff) +1
-3- .set = SET, - .get = GET, - }; + DEFINE_KERNEL_PARAM_OPS(OPS, SET, GET);Using the macro for initialization means future changes can manipulate the struct layout and callback prototypes without having to change every initializer.
Signed-off-by Kees Cook <[email protected]>---
[...]
Quoted 3 lines
mm/damon/lru_sort.c | 19 ++--- mm/damon/reclaim.c | 19 ++--- mm/damon/stat.c | 6 +-
[...]
Quoted 3 lines
samples/damon/mtier.c | 6 +- samples/damon/prcl.c | 6 +- samples/damon/wsse.c | 6 +-
For the above DAMON part changes,
Thanks,
SJ
[...]
Petr Pavlu
maintainerRe: [PATCH 04/11] treewide: Convert struct kernel_param_ops initializers to DEFINE_KERNEL_PARAM_OPS
In reply to Kees CookQuoted 15 lines · Kees Cook
Using Coccinelle, rewrite every struct
kernel_param_opsinitializer that sets .get into a DEFINE_KERNEL_PARAM_OPS-family macro invocation, for example:@@
declarer nameDEFINE_KERNEL_PARAM_OPS;
identifier OPS;
expression SET, GET;
@@
- const structkernel_param_opsOPS = {(quoted diff) +1
-3- .set = SET, - .get = GET, - }; + DEFINE_KERNEL_PARAM_OPS(OPS, SET, GET);
Quoted 3 lines
Using the macro for initialization means future changes can manipulate the struct layout and callback prototypes without having to change every initializer.
Nit: For consistency, I suggest also converting the few remaining kernel_param_ops instances that specify only .set and no .get, such as simdisk_param_ops_filename.
Signature · 2 lines
Thanks, Petr
Re: [PATCH 04/11] treewide: Convert struct kernel_param_ops initializers to DEFINE_KERNEL_PARAM_OPS
Quoted 21 lines · Petr Pavlu
Quoted 15 lines · Kees Cook
Using Coccinelle, rewrite every struct
kernel_param_opsinitializer that sets .get into a DEFINE_KERNEL_PARAM_OPS-family macro invocation, for example:@@
declarer nameDEFINE_KERNEL_PARAM_OPS;
identifier OPS;
expression SET, GET;
@@
- const structkernel_param_opsOPS = {(quoted diff) +1
-3- .set = SET, - .get = GET, - }; + DEFINE_KERNEL_PARAM_OPS(OPS, SET, GET);Quoted 3 lines
Using the macro for initialization means future changes can manipulate the struct layout and callback prototypes without having to change every initializer.
Quoted 7 lines
Nit: For consistency, I suggest also converting the few remaining
kernel_param_opsinstances that specify only .set and no .get, such assimdisk_param_ops_filename.--
Thanks,
Petr
for the dynamic-debug changes
Kees Cook
maintainerPATCH 5/11 moduleparam: Rename .get field to .get_str
In reply to Kees CookNow that every kernel_param_ops initializer in the tree goes through DEFINE_KERNEL_PARAM_OPS, no source file outside kernel/params.c and include/linux/moduleparam.h references the .get field by name. Take advantage of that to rename the field to .get_str.
The bare .get name is now free for the next commit, which adds it back as a struct seq_buf *-based callback.
--- include/linux/moduleparam.h | 8 ++++---- kernel/params.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-)
include/linux/moduleparam.h +4 -4
@@ -63,7 +63,7 @@ struct kernel_param_ops {/* Returns 0, or -errno. arg is in kp->arg. */ int (*set)(const char *val,const struct kernel_param *kp);/* Returns length written or -errno. Buffer is 4k (ie. be short!) */ -int (*get)(char *buffer,const struct kernel_param *kp); +int (*get_str)(char *buffer,const struct kernel_param *kp);/* Optional function to free kp->arg when module unloaded. */ void (*free)(void *arg); };
@@ -82,7 +82,7 @@ struct kernel_param_ops {#define DEFINE_KERNEL_PARAM_OPS (_name, _set, _get) \ const struct kernel_param_ops _name = { \ .set = (_set), \ - .get = (_get), \ + .get_str = (_get), \ }/* As DEFINE_KERNEL_PARAM_OPS, with KERNEL_PARAM_OPS_FL_NOARG set. */
@@ -90,14 +90,14 @@ struct kernel_param_ops {const struct kernel_param_ops _name = { \ .flags =KERNEL_PARAM_OPS_FL_NOARG , \ .set = (_set), \ - .get = (_get), \ + .get_str = (_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 = (_get), \ + .get_str = (_get), \ .free = (_free), \ }
kernel/params.c +3 -3
@@ -467,7 +467,7 @@ static int param_array_get(char *buffer, const struct kernel_param *kp)for (i = off =0 ; i < (arr->num ? *arr->num : arr->max); i++) { p.arg = arr->elem + arr->elemsize * i;check_kparam_locked (p.mod); - ret = arr->ops->get (elem_buf, &p); + ret = arr->ops->get_str (elem_buf, &p);if (ret <0 ) goto out; ret =min (ret, (int )(PAGE_SIZE -1 - off));
@@ -554,11 +554,11 @@ static ssize_t param_attr_show(const struct module_attribute *mattr,int count;const struct param_attribute *attribute =to_param_attr (mattr); -if (!attribute->param->ops->get) +if (!attribute->param->ops->get_str)return -EPERM ;kernel_param_lock (mk->mod); - count = attribute->param->ops->get (buf, attribute->param); + count = attribute->param->ops->get_str (buf, attribute->param);kernel_param_unlock (mk->mod);return count; }
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH 05/11] moduleparam: Rename .get field to .get_str
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] The commit message claims that all `kernel_param_ops` initializers in the tree now use the…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] The commit message claims that all kernel_param_ops initializers in the tree now use the DEFINE_KERNEL_PARAM_OPS macro, but several files (e.g., arch/xtensa/platforms/iss/simdisk.c, drivers/video/fbdev/uvesafb.c, drivers/mtd/ubi/block.c, drivers/target/target_core_user.c) still use direct struct initialization.
- [Low] Renaming the .get field to .get_str in struct kernel_param_ops breaks the kernel build when Rust is enabled (CONFIG_RUST=y).
--
commit 1952ed67c747da9c1d8185a27ee2651d4cdb0689
Author: Kees Cook <[email protected]>
moduleparam: Rename .get field to .get_str
This commit renames the .get callback in struct kernel_param_ops to .get_str. It frees up the .get name for a future commit that will re-add it as a seq_buf-based callback.
Quoted 2 lines
Now that every
kernel_param_opsinitializer in the tree goes throughDEFINE_KERNEL_PARAM_OPS, no source file outsidekernel/params.cand
[Severity: Low]
This isn't a bug, but is this description entirely accurate?
Several files like arch/xtensa/platforms/iss/simdisk.c, drivers/video/fbdev/uvesafb.c, and drivers/mtd/ubi/block.c still use direct struct initialization because they only define .set.
Quoted 2 lines
include/linux/moduleparam.hreferences the .get field by name. Take advantage of that to rename the field to .get_str.
[ ... ]
include/linux/moduleparam.h struct kernel_param_ops { · line 66
Quoted 10 lines
include/linux/moduleparam.h +1
-1@@ -63,7 +63,7 @@ struct kernel_param_ops {/* Returns 0, or -errno. arg is in kp->arg. */ int (*set)(const char *val,const struct kernel_param *kp);/* Returns length written or -errno. Buffer is 4k (ie. be short!) */ -int (*get)(char *buffer,const struct kernel_param *kp); +int (*get_str)(char *buffer,const struct kernel_param *kp);
[Severity: Low]
Does this break the kernel build when CONFIG_RUST=y?
In rust/kernel/module_param.rs, the make_param_ops! macro explicitly initializes the generated C struct with get: None. When bindgen reflects the renamed field, compilation will fail because the get field no longer exists and the new get_str field is uninitialized.
Even though this is resolved later in the series by removing the get_str field entirely, does this intermediate breakage cause issues for git bisect?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Kees Cook
maintainerPATCH 6/11 moduleparam: Add seq_buf-based .get callback alongside .get_str
In reply to Kees CookAdd a new struct kernel_param_ops::get callback whose signature takes a struct seq_buf instead of a raw char buffer:
int (*get)(struct seq_buf *sb, const struct kernel_param *kp);
The previously-legacy .get field is now .get_str (char *buffer); .get is the new seq_buf-aware form. param_attr_show() prefers .get when set, otherwise falls back to .get_str. WARN_ON_ONCE() if both are set. Return contract for .get:
< 0 : errno propagated to userspace; seq_buf contents discarded = 0 : success; length derived from seq_buf_used()
Quoted 1 line
0 : forbidden; the dispatcher WARN_ON_ONCE()s and treats as 0
The default policy on seq_buf_has_overflowed() is silent truncation, matching scnprintf()/sysfs_emit() behaviour. Callbacks that want a specific overflow errno can check seq_buf_has_overflowed() and return their preferred error.
No callbacks use .get yet; the legacy path is still the only one in use after this commit. A subsequent commit teaches DEFINE_KERNEL_PARAM_OPS to route initializers by type.
--- include/linux/moduleparam.h | 13 ++++++++++++- kernel/params.c | 26 ++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-)
include/linux/moduleparam.h +12 -1
@@ -7,6 +7,7 @@#include <linux/build_bug.h> #include <linux/compiler.h> #include <linux/init.h> +#include <linux/seq_buf.h> #include <linux/stringify.h> #include <linux/sysfs.h> #include <linux/types.h>
@@ -62,7 +63,17 @@ struct kernel_param_ops {unsigned int flags;/* Returns 0, or -errno. arg is in kp->arg. */ int (*set)(const char *val,const struct kernel_param *kp); -/* Returns length written or -errno. Buffer is 4k (ie. be short!) */ +/* +* 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);
kernel/params.c +24 -2
@@ -553,12 +553,34 @@ 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; -if (!attribute->param->ops->get_str) +if (!ops->get && !ops->get_str)return -EPERM ; +WARN_ON_ONCE (ops->get && ops->get_str); +kernel_param_lock (mk->mod); - count = attribute->param->ops->get_str (buf, attribute->param); +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); + }kernel_param_unlock (mk->mod);return count; }
Signature · 1 line
2.34.1
Re: [PATCH 06/11] moduleparam: Add seq_buf-based .get callback alongside .get_str
Quoted 19 lines · Kees Cook
Add a new struct
kernel_param_ops::getcallback whose signature takes a structseq_bufinstead of a raw char buffer:int (*get)(struct seq_buf *sb, const struct kernel_param *kp);The previously-legacy .get field is now .get_str (char *buffer); .get is the new seq_buf-aware form.
param_attr_show()prefers .get when set, otherwise falls back to .get_str.WARN_ON_ONCE()if both are set. Return contract for .get:< 0 : errno propagated to userspace;
seq_bufcontents discarded = 0 : success; length derived fromseq_buf_used()Quoted 1 line
0 : forbidden; the dispatcher WARN_ON_ONCE()s and treats as 0
The default policy on
seq_buf_has_overflowed()is silent truncation, matching scnprintf()/sysfs_emit() behaviour. Callbacks that want a specific overflow errno can checkseq_buf_has_overflowed()and return their preferred error.
Quoted 5 lines
No callbacks use .get yet; the legacy path is still the only one in use after this commit. A subsequent commit teaches
DEFINE_KERNEL_PARAM_OPSto route initializers by type.Signed-off-by Kees Cook <[email protected]>
-- Petr
[email protected]
AI reviewRe: [PATCH 06/11] moduleparam: Add seq_buf-based .get callback alongside .get_str
In reply to Kees CookThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Silent data truncation and spurious kernel warning when the sysfs buffer is exactly filled. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Silent data truncation and spurious kernel warning when the sysfs buffer is exactly filled. --
commit 6802395b5f9f236d2cc29365e6d39e6de2eae4ca
Author: Kees Cook <[email protected]>
moduleparam: Add seq_buf-based .get callback alongside .get_str
This commit adds a new seq_buf-based .get callback to struct kernel_param_ops to format parameter values safely. It updates param_attr_show() to prefer this new callback when available, using a page-sized buffer. The legacy .get_str callback is retained as a fallback.
Quoted 4 lines
kernel/params.c +0
-0
[ ... ]
Quoted 1 line
kernel/params.c +0
-0@@ -553,12 +553,34 @@ static ssize_t param_attr_show(const struct module_attribute *mattr,
[ ... ]
Quoted 8 lines
kernel/params.c +6
-1kernel_param_lock (mk->mod); - count = attribute->param->ops->get_str (buf, attribute->param); +if (ops->get) { +struct seq_buf s; + +seq_buf_init (&s, buf,PAGE_SIZE ); + count = ops->get (&s, attribute->param); +if (count >=0 ) {
kernel/params.c static ssize_t param_attr_show(const struct module_attribute *mattr, · line 579
Quoted 10 lines
kernel/params.c +10
-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--;
[Severity: Medium]
Does this code silently truncate data and trigger a kernel warning when the buffer is exactly filled?
If the .get() callback writes exactly PAGE_SIZE bytes without triggering an overflow, seq_buf_has_overflowed(&s) will evaluate to false because s.len exactly equals s.size. In this case, count remains PAGE_SIZE.
However, seq_buf_str(&s) unconditionally writes a NUL byte at the end of the buffer, which will replace the last byte of valid data at PAGE_SIZE - 1.
Furthermore, returning PAGE_SIZE causes the sysfs core to print a bad count warning to dmesg and truncate the count anyway. Should this code explicitly decrement count when count == PAGE_SIZE to avoid overwriting data and causing the warning?
Quoted 7 lines
kernel/params.c +4
-0+ } + }else { + count = ops->get_str (buf, attribute->param); + }kernel_param_unlock (mk->mod);return count; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Kees Cook
maintainerPATCH 7/11 moduleparam: Route DEFINE_KERNEL_PARAM_OPS get pointer via _Generic
In reply to Kees CookMake the DEFINE_KERNEL_PARAM_OPS family route their _get argument to either .get (struct seq_buf *) or .get_str (char *) at compile time based on the pointer's actual function signature. Two helper macros do the routing:
_KERNEL_PARAM_OPS_GET - return the pointer if it has the seq_buf
signature, otherwise NULL of that type
_KERNEL_PARAM_OPS_GET_STR - mirror image for the char * signature
Both use _Generic; only the two valid function-pointer types are listed, so any third-party type is a compile error rather than silently falling through.
Now a callback whose body has been migrated from char * to struct seq_buf * needs no change at its kernel_param_ops initialization site, because the macro picks up the new type automatically and assigns to the correct field.
--- include/linux/moduleparam.h | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-)
include/linux/moduleparam.h +26 -7
@@ -85,15 +85,32 @@ struct kernel_param_ops {* * static DEFINE_KERNEL_PARAM_OPS(my_ops, my_set, my_get); * -* Routing the @_set and @_get function pointers through the macro -* (rather than naming the struct fields at every call site) lets the -* field layout change in one place when callbacks are migrated to a -* new signature. +* @_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_str = (_get), \ + .get = _KERNEL_PARAM_OPS_GET(_get), \ + .get_str = _KERNEL_PARAM_OPS_GET_STR(_get), \ }/* As DEFINE_KERNEL_PARAM_OPS, with KERNEL_PARAM_OPS_FL_NOARG set. */
@@ -101,14 +118,16 @@ struct kernel_param_ops {const struct kernel_param_ops _name = { \ .flags =KERNEL_PARAM_OPS_FL_NOARG , \ .set = (_set), \ - .get_str = (_get), \ + .get =_KERNEL_PARAM_OPS_GET (_get), \ + .get_str =_KERNEL_PARAM_OPS_GET_STR (_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_str = (_get), \ + .get = _KERNEL_PARAM_OPS_GET(_get), \ + .get_str = _KERNEL_PARAM_OPS_GET_STR(_get), \ .free = (_free), \ }
Signature · 1 line
2.34.1
Re: [PATCH 07/11] moduleparam: Route DEFINE_KERNEL_PARAM_OPS get pointer via _Generic
Quoted 74 lines · Kees Cook
Make the
DEFINE_KERNEL_PARAM_OPSfamily route their_getargument to either .get (structseq_buf*) or .get_str (char *) at compile time based on the pointer's actual function signature. Two helper macros do the routing:
_KERNEL_PARAM_OPS_GET- return the pointer if it has theseq_buf
signature, otherwise NULL of that type
_KERNEL_PARAM_OPS_GET_STR- mirror image for the char * signatureBoth use
_Generic; only the two valid function-pointer types are listed, so any third-party type is a compile error rather than silently falling through.Now a callback whose body has been migrated from char * to struct
seq_buf* needs no change at itskernel_param_opsinitialization site, because the macro picks up the new type automatically and assigns to the correct field.Signed-off-by Kees Cook <[email protected]>--- include/linux/moduleparam.h | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-)include/linux/moduleparam.h +24
-6@@ -85,15 +85,32 @@ struct kernel_param_ops {* * static DEFINE_KERNEL_PARAM_OPS(my_ops, my_set, my_get); * -* Routing the @_set and @_get function pointers through the macro -* (rather than naming the struct fields at every call site) lets the -* field layout change in one place when callbacks are migrated to a -* new signature. +* @_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_str = (_get), \ + .get = _KERNEL_PARAM_OPS_GET(_get), \ + .get_str = _KERNEL_PARAM_OPS_GET_STR(_get), \ }/* As DEFINE_KERNEL_PARAM_OPS, with KERNEL_PARAM_OPS_FL_NOARG set. */ @@ -101,14 +118,16 @@ struct kernel_param_ops {const struct kernel_param_ops _name = { \ .flags =KERNEL_PARAM_OPS_FL_NOARG , \ .set = (_set), \ - .get_str = (_get), \ + .get =_KERNEL_PARAM_OPS_GET (_get), \ + .get_str =_KERNEL_PARAM_OPS_GET_STR (_get), \ }
include/linux/moduleparam.h struct kernel_param_ops { · line 133
Quoted 10 lines
include/linux/moduleparam.h +2
-1/* 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_str = (_get), \ + .get = _KERNEL_PARAM_OPS_GET(_get), \ + .get_str = _KERNEL_PARAM_OPS_GET_STR(_get), \ .free = (_free), \ }
-- Petr
Kees Cook
maintainerPATCH 8/11 params: Convert generic kernel_param_ops .get helpers to seq_buf
In reply to Kees CookConvert the generic struct kernel_param_ops .get helpers in kernel/params.c directly to the seq_buf signature, drop their legacy "char *" form, and refresh prototypes in <linux/moduleparam.h>:
param_get_byte/short/ushort/int/uint/long/ulong/ullong/hexint param_get_charp/bool/invbool/string
param_array_get
The STANDARD_PARAM_DEF() macro expands to a seq_buf body for every numeric helper. param_array_get() now writes element output directly into the parent seq_buf when the element ops provide .get; it only allocates the per-call PAGE_SIZE bounce buffer when the element ops still use the legacy .get_str path. The common "rewrite the prior element's trailing newline as a comma" step lives outside both branches so the two paths share it.
The non-core changes in this commit (arch/x86/kvm, mm/kfence, drivers/dma/dmatest, security/apparmor) are the small set of callers that directly invoke one of the converted generic helpers from their own .get callback (e.g. an apparmor wrapper that adds a capability check and then delegates to param_get_bool()). Because the helpers' signature changes here, these wrappers must move in lockstep. Each of them is updated to take "struct seq_buf *" and pass it through; param_get_debug() in apparmor also pulls aa_print_debug_params() (and its val_mask_to_str() helper, in security/apparmor/lib.c) over to seq_buf, since that is the only consumer. No other behavioural change is intended.
Custom .get callbacks that do not delegate to a generic helper (and therefore still match the .get_str signature) are routed automatically to the .get_str field by the DEFINE_KERNEL_PARAM_OPS _Generic dispatcher and are deliberately left alone here, to be changed separately within their respective subsystems.
--- include/linux/moduleparam.h | 26 +++++------ security/apparmor/include/lib.h | 3 +- mm/kfence/core.c | 8 ++-- arch/x86/kvm/mmu/mmu.c | 16 ++++--- arch/x86/kvm/svm/avic.c | 8 ++-- drivers/dma/dmatest.c | 14 +++--- kernel/params.c | 80 ++++++++++++++++++++------------- security/apparmor/lib.c | 27 +++++------ security/apparmor/lsm.c | 25 ++++++----- 9 files changed, 114 insertions(+), 93 deletions(-)
include/linux/moduleparam.h +13 -13
@@ -500,61 +500,61 @@ void module_destroy_params(const struct kernel_param *params, unsigned int num);extern const struct kernel_param_ops param_ops_byte;int param_set_byte (const char *val,const struct kernel_param *kp); -int param_get_byte (char *buffer,const struct kernel_param *kp); +int param_get_byte (struct seq_buf *s,const struct kernel_param *kp);#define param_check_byte (name, p) __param_check(name, p, unsigned char)extern const struct kernel_param_ops param_ops_short;int param_set_short (const char *val,const struct kernel_param *kp); -int param_get_short (char *buffer,const struct kernel_param *kp); +int param_get_short (struct seq_buf *s,const struct kernel_param *kp);#define param_check_short (name, p) __param_check(name, p, short)extern const struct kernel_param_ops param_ops_ushort;int param_set_ushort (const char *val,const struct kernel_param *kp); -int param_get_ushort (char *buffer,const struct kernel_param *kp); +int param_get_ushort (struct seq_buf *s,const struct kernel_param *kp);#define param_check_ushort (name, p) __param_check(name, p, unsigned short)extern const struct kernel_param_ops param_ops_int;int param_set_int (const char *val,const struct kernel_param *kp); -int param_get_int (char *buffer,const struct kernel_param *kp); +int param_get_int (struct seq_buf *s,const struct kernel_param *kp);#define param_check_int (name, p) __param_check(name, p, int)extern const struct kernel_param_ops param_ops_uint;int param_set_uint (const char *val,const struct kernel_param *kp); -int param_get_uint (char *buffer,const struct kernel_param *kp); +int param_get_uint (struct seq_buf *s,const struct kernel_param *kp);int param_set_uint_minmax (const char *val,const struct kernel_param *kp,unsigned int min,unsigned int max);#define param_check_uint (name, p) __param_check(name, p, unsigned int)extern const struct kernel_param_ops param_ops_long;int param_set_long (const char *val,const struct kernel_param *kp); -int param_get_long (char *buffer,const struct kernel_param *kp); +int param_get_long (struct seq_buf *s,const struct kernel_param *kp);#define param_check_long (name, p) __param_check(name, p, long)extern const struct kernel_param_ops param_ops_ulong;int param_set_ulong (const char *val,const struct kernel_param *kp); -int param_get_ulong (char *buffer,const struct kernel_param *kp); +int param_get_ulong (struct seq_buf *s,const struct kernel_param *kp);#define param_check_ulong (name, p) __param_check(name, p, unsigned long)extern const struct kernel_param_ops param_ops_ullong;int param_set_ullong (const char *val,const struct kernel_param *kp); -int param_get_ullong (char *buffer,const struct kernel_param *kp); +int param_get_ullong (struct seq_buf *s,const struct kernel_param *kp);#define param_check_ullong (name, p) __param_check(name, p, unsigned long long)extern const struct kernel_param_ops param_ops_hexint;int param_set_hexint (const char *val,const struct kernel_param *kp); -int param_get_hexint (char *buffer,const struct kernel_param *kp); +int param_get_hexint (struct seq_buf *s,const struct kernel_param *kp);#define param_check_hexint (name, p) param_check_uint(name, p)extern const struct kernel_param_ops param_ops_charp;int param_set_charp (const char *val,const struct kernel_param *kp); -int param_get_charp (char *buffer,const struct kernel_param *kp); +int param_get_charp (struct seq_buf *s,const struct kernel_param *kp);void param_free_charp (void *arg);#define param_check_charp (name, p) __param_check(name, p, char *)/* We used to allow int as well as bool. We're taking that away! */ extern const struct kernel_param_ops param_ops_bool;int param_set_bool (const char *val,const struct kernel_param *kp); -int param_get_bool (char *buffer,const struct kernel_param *kp); +int param_get_bool (struct seq_buf *s,const struct kernel_param *kp);#define param_check_bool (name, p) __param_check(name, p, bool)extern const struct kernel_param_ops param_ops_bool_enable_only;
@@ -564,7 +564,7 @@ int param_set_bool_enable_only(const char *val, const struct kernel_param *kp);extern const struct kernel_param_ops param_ops_invbool;int param_set_invbool (const char *val,const struct kernel_param *kp); -int param_get_invbool (char *buffer,const struct kernel_param *kp); +int param_get_invbool (struct seq_buf *s,const struct kernel_param *kp);#define param_check_invbool (name, p) __param_check(name, p, bool)/* An int, which can only be set like a bool (though it shows as an int). */
@@ -677,7 +677,7 @@ extern const struct kernel_param_ops param_array_ops;extern const struct kernel_param_ops param_ops_string;int param_set_copystring (const char *val,const struct kernel_param *kp); -int param_get_string (char *buffer,const struct kernel_param *kp); +int param_get_string (struct seq_buf *s,const struct kernel_param *kp);/* for exporting parameters in /sys/module/.../parameters */
security/apparmor/include/lib.h +2 -1
@@ -13,6 +13,7 @@#include <linux/slab.h> #include <linux/fs.h> #include <linux/lsm_hooks.h> +#include <linux/seq_buf.h> #include "match.h"
@@ -72,7 +73,7 @@ do { \#endif int aa_parse_debug_params (const char *str); -int aa_print_debug_params (char *buffer); +int aa_print_debug_params (struct seq_buf *s); #define AA_ERROR(fmt, args...) \ pr_err_ratelimited("AppArmor: " fmt, ##args)
mm/kfence/core.c +5 -3
@@ -84,10 +84,12 @@ static int param_set_sample_interval(const char *val, const struct kernel_paramreturn 0 ; } -static int param_get_sample_interval (char *buffer,const struct kernel_param *kp) +static int param_get_sample_interval (struct seq_buf *buffer,const struct kernel_param *kp) { -if (!READ_ONCE (kfence_enabled)) -return sprintf (buffer,"0\n" ); +if (!READ_ONCE (kfence_enabled)) { +seq_buf_puts (buffer,"0\n" ); +return 0 ; + }return param_get_ulong (buffer, kp); }
arch/x86/kvm/mmu/mmu.c +10 -6
@@ -70,7 +70,7 @@ static uint __read_mostly nx_huge_pages_recovery_ratio = 0;static uint __read_mostly nx_huge_pages_recovery_ratio =60 ;#endif -static int get_nx_huge_pages (char *buffer,const struct kernel_param *kp); +static int get_nx_huge_pages (struct seq_buf *buffer,const struct kernel_param *kp);static int set_nx_huge_pages (const char *val,const struct kernel_param *kp);static int set_nx_huge_pages_recovery_param (const char *val,const struct kernel_param *kp);
@@ -7493,15 +7493,19 @@ static void kvm_wake_nx_recovery_thread(struct kvm *kvm)vhost_task_wake (nx_thread); } -static int get_nx_huge_pages (char *buffer,const struct kernel_param *kp) +static int get_nx_huge_pages (struct seq_buf *buffer,const struct kernel_param *kp) {int val = *(int *)kp->arg; -if (nx_hugepage_mitigation_hard_disabled) -return sysfs_emit (buffer,"never\n" ); +if (nx_hugepage_mitigation_hard_disabled) { +seq_buf_puts (buffer,"never\n" ); +return 0 ; + } -if (val ==-1 ) -return sysfs_emit (buffer,"auto\n" ); +if (val ==-1 ) { +seq_buf_puts (buffer,"auto\n" ); +return 0 ; + }return param_get_bool (buffer, kp); }
arch/x86/kvm/svm/avic.c +5 -3
@@ -77,12 +77,14 @@ static int avic_param_set(const char *val, const struct kernel_param *kp)return param_set_bint (val, kp); } -static int avic_param_get (char *buffer,const struct kernel_param *kp) +static int avic_param_get (struct seq_buf *buffer,const struct kernel_param *kp) {int val = *(int *)kp->arg; -if (val ==AVIC_AUTO_MODE ) -return sysfs_emit (buffer,"N\n" ); +if (val ==AVIC_AUTO_MODE ) { +seq_buf_puts (buffer,"N\n" ); +return 0 ; + }return param_get_bool (buffer, kp); }
drivers/dma/dmatest.c +7 -7
@@ -153,14 +153,14 @@ static struct dmatest_info { };static int dmatest_run_set (const char *val,const struct kernel_param *kp); -static int dmatest_run_get (char *val,const struct kernel_param *kp); +static int dmatest_run_get (struct seq_buf *val,const struct kernel_param *kp); static DEFINE_KERNEL_PARAM_OPS(run_ops, dmatest_run_set, dmatest_run_get);static bool dmatest_run;module_param_cb (run, &run_ops, &dmatest_run,0644 );MODULE_PARM_DESC (run,"Run the test (default: false)" );static int dmatest_chan_set (const char *val,const struct kernel_param *kp); -static int dmatest_chan_get (char *val,const struct kernel_param *kp); +static int dmatest_chan_get (struct seq_buf *val,const struct kernel_param *kp); static DEFINE_KERNEL_PARAM_OPS(multi_chan_ops, dmatest_chan_set, dmatest_chan_get);
@@ -172,7 +172,7 @@ static struct kparam_string newchan_kps = {module_param_cb (channel, &multi_chan_ops, &newchan_kps,0644 );MODULE_PARM_DESC (channel,"Bus ID of the channel to test (default: any)" ); -static int dmatest_test_list_get (char *val,const struct kernel_param *kp); +static int dmatest_test_list_get (struct seq_buf *val,const struct kernel_param *kp); static DEFINE_KERNEL_PARAM_OPS(test_list_ops, NULL, dmatest_test_list_get);module_param_cb (test_list, &test_list_ops,NULL ,0444 );MODULE_PARM_DESC (test_list,"Print current test list" );
@@ -274,7 +274,7 @@ static bool is_threaded_test_pending(struct dmatest_info *info)return false; } -static int dmatest_wait_get (char *val,const struct kernel_param *kp) +static int dmatest_wait_get (struct seq_buf *val,const struct kernel_param *kp) {struct dmatest_info *info = &test_info;struct dmatest_params *params = &info->params;
@@ -1164,7 +1164,7 @@ static void start_threaded_tests(struct dmatest_info *info)run_pending_tests (info); } -static int dmatest_run_get (char *val,const struct kernel_param *kp) +static int dmatest_run_get (struct seq_buf *val,const struct kernel_param *kp) {struct dmatest_info *info = &test_info;
@@ -1292,7 +1292,7 @@ static int dmatest_chan_set(const char *val, const struct kernel_param *kp)return ret; } -static int dmatest_chan_get (char *val,const struct kernel_param *kp) +static int dmatest_chan_get (struct seq_buf *val,const struct kernel_param *kp) {struct dmatest_info *info = &test_info;
@@ -1306,7 +1306,7 @@ static int dmatest_chan_get(char *val, const struct kernel_param *kp)return param_get_string (val, kp); } -static int dmatest_test_list_get (char *val,const struct kernel_param *kp) +static int dmatest_test_list_get (struct seq_buf *val,const struct kernel_param *kp) {struct dmatest_info *info = &test_info;struct dmatest_chan *dtc;
kernel/params.c +48 -32
137 lines not on this page · raw message
security/apparmor/lib.c +11 -16
@@ -85,37 +85,32 @@ int aa_parse_debug_params(const char *str)/** * val_mask_to_str - convert a perm mask to its short string -* @str: character buffer to store string in (at least 10 characters) -* @size: size of the @str buffer +* @s: seq_buf to store string in * @table: NUL-terminated character buffer of permission characters (NOT NULL) * @mask: permission mask to convert */ -static int val_mask_to_str (char *str,size_t size, -const struct val_table_ent *table,u32 mask) +static void val_mask_to_str (struct seq_buf *s, +const struct val_table_ent *table,u32 mask) {const struct val_table_ent *ent; -int total =0 ; +bool first = true;for (ent = table; ent->str; ent++) {if (ent->value && (ent->value & mask) == ent->value) { -int len =scnprintf (str, size,"%s%s" , total ?"," :"" , - ent->str); - size -= len; - str += len; - total += len; +seq_buf_printf (s,"%s%s" , first ?"" :"," , ent->str); + first = false; mask &= ~ent->value; } } - -return total; } -int aa_print_debug_params (char *buffer) +int aa_print_debug_params (struct seq_buf *s) {if (!aa_g_debug) -return sprintf (buffer,"N" ); -return val_mask_to_str (buffer,PAGE_SIZE , debug_values_table, - aa_g_debug); +seq_buf_puts (s,"N" ); +else +val_mask_to_str (s, debug_values_table, aa_g_debug); +return 0 ; }bool aa_resize_str_table (struct aa_str_table *t,int newsize,gfp_t gfp)
security/apparmor/lsm.c +13 -12
@@ -16,6 +16,7 @@#include <linux/namei.h> #include <linux/ptrace.h> #include <linux/ctype.h> +#include <linux/seq_buf.h> #include <linux/sysctl.h> #include <linux/sysfs.h> #include <linux/audit.h>
@@ -1765,20 +1766,20 @@ static struct security_hook_list apparmor_hooks[] __ro_after_init = {*/ static int param_set_aabool (const char *val,const struct kernel_param *kp); -static int param_get_aabool (char *buffer,const struct kernel_param *kp); +static int param_get_aabool (struct seq_buf *buffer,const struct kernel_param *kp);#define param_check_aabool param_check_bool static DEFINE_KERNEL_PARAM_OPS_NOARG(param_ops_aabool, param_set_aabool, param_get_aabool);static int param_set_aauint (const char *val,const struct kernel_param *kp); -static int param_get_aauint (char *buffer,const struct kernel_param *kp); +static int param_get_aauint (struct seq_buf *buffer,const struct kernel_param *kp);#define param_check_aauint param_check_uint static DEFINE_KERNEL_PARAM_OPS(param_ops_aauint, param_set_aauint, param_get_aauint);static int param_set_aacompressionlevel (const char *val,const struct kernel_param *kp); -static int param_get_aacompressionlevel (char *buffer, +static int param_get_aacompressionlevel (struct seq_buf *buffer,const struct kernel_param *kp);#define param_check_aacompressionlevel param_check_int static DEFINE_KERNEL_PARAM_OPS(param_ops_aacompressionlevel,
@@ -1786,14 +1787,14 @@ static DEFINE_KERNEL_PARAM_OPS(param_ops_aacompressionlevel, param_get_aacompressionlevel);static int param_set_aalockpolicy (const char *val,const struct kernel_param *kp); -static int param_get_aalockpolicy (char *buffer,const struct kernel_param *kp); +static int param_get_aalockpolicy (struct seq_buf *buffer,const struct kernel_param *kp);#define param_check_aalockpolicy param_check_bool static DEFINE_KERNEL_PARAM_OPS_NOARG(param_ops_aalockpolicy, param_set_aalockpolicy, param_get_aalockpolicy);static int param_set_debug (const char *val,const struct kernel_param *kp); -static int param_get_debug (char *buffer,const struct kernel_param *kp); +static int param_get_debug (struct seq_buf *buffer,const struct kernel_param *kp);static int param_set_audit (const char *val,const struct kernel_param *kp);static int param_get_audit (char *buffer,const struct kernel_param *kp);
@@ -1868,7 +1869,7 @@ module_param_named(path_max, aa_g_path_max, aauint, S_IRUSR);bool aa_g_paranoid_load =IS_ENABLED (CONFIG_SECURITY_APPARMOR_PARANOID_LOAD );module_param_named (paranoid_load, aa_g_paranoid_load, aabool,S_IRUGO ); -static int param_get_aaintbool (char *buffer,const struct kernel_param *kp); +static int param_get_aaintbool (struct seq_buf *buffer,const struct kernel_param *kp);static int param_set_aaintbool (const char *val,const struct kernel_param *kp);#define param_check_aaintbool param_check_int static DEFINE_KERNEL_PARAM_OPS(param_ops_aaintbool, param_set_aaintbool,
@@ -1898,7 +1899,7 @@ static int param_set_aalockpolicy(const char *val, const struct kernel_param *kpreturn param_set_bool (val, kp); } -static int param_get_aalockpolicy (char *buffer,const struct kernel_param *kp) +static int param_get_aalockpolicy (struct seq_buf *buffer,const struct kernel_param *kp) {if (!apparmor_enabled)return -EINVAL ;
@@ -1916,7 +1917,7 @@ static int param_set_aabool(const char *val, const struct kernel_param *kp)return param_set_bool (val, kp); } -static int param_get_aabool (char *buffer,const struct kernel_param *kp) +static int param_get_aabool (struct seq_buf *buffer,const struct kernel_param *kp) {if (!apparmor_enabled)return -EINVAL ;
@@ -1942,7 +1943,7 @@ static int param_set_aauint(const char *val, const struct kernel_param *kp)return error; } -static int param_get_aauint (char *buffer,const struct kernel_param *kp) +static int param_get_aauint (struct seq_buf *buffer,const struct kernel_param *kp) {if (!apparmor_enabled)return -EINVAL ;
@@ -1978,7 +1979,7 @@ static int param_set_aaintbool(const char *val, const struct kernel_param *kp)* display in the /sys filesystem, while keeping it "int" for the LSM * infrastructure. */ -static int param_get_aaintbool (char *buffer,const struct kernel_param *kp) +static int param_get_aaintbool (struct seq_buf *buffer,const struct kernel_param *kp) {struct kernel_param kp_local;bool value;
@@ -2011,7 +2012,7 @@ static int param_set_aacompressionlevel(const char *val,return error; } -static int param_get_aacompressionlevel (char *buffer, +static int param_get_aacompressionlevel (struct seq_buf *buffer,const struct kernel_param *kp) {if (!apparmor_enabled)
@@ -2021,7 +2022,7 @@ static int param_get_aacompressionlevel(char *buffer,return param_get_int (buffer, kp); } -static int param_get_debug (char *buffer,const struct kernel_param *kp) +static int param_get_debug (struct seq_buf *buffer,const struct kernel_param *kp) {if (!apparmor_enabled)return -EINVAL ;
Signature · 1 line
2.34.1
Petr Pavlu
maintainerRe: [PATCH 08/11] params: Convert generic kernel_param_ops .get helpers to seq_buf
Quoted 93 lines · Kees Cook
Convert the generic struct
kernel_param_ops.get helpers inkernel/params.cdirectly to theseq_bufsignature, drop their legacy "char *" form, and refresh prototypes in <linux/moduleparam.h>:param_get_byte/short/ushort/int/uint/long/ulong/ullong/hexint param_get_charp/bool/invbool/string
param_array_getThe
STANDARD_PARAM_DEF()macro expands to aseq_bufbody for every numeric helper.param_array_get()now writes element output directly into the parentseq_bufwhen the element ops provide .get; it only allocates the per-callPAGE_SIZEbounce buffer when the element ops still use the legacy .get_str path. The common "rewrite the prior element's trailing newline as a comma" step lives outside both branches so the two paths share it.The non-core changes in this commit (
arch/x86/kvm, mm/kfence,drivers/dma/dmatest,security/apparmor) are the small set of callers that directly invoke one of the converted generic helpers from their own .get callback (e.g. an apparmor wrapper that adds a capability check and then delegates toparam_get_bool()). Because the helpers' signature changes here, these wrappers must move in lockstep. Each of them is updated to take "structseq_buf*" and pass it through;param_get_debug()in apparmor also pullsaa_print_debug_params()(and itsval_mask_to_str()helper, insecurity/apparmor/lib.c) over toseq_buf, since that is the only consumer. No other behavioural change is intended.Custom .get callbacks that do not delegate to a generic helper (and therefore still match the .get_str signature) are routed automatically to the .get_str field by the
DEFINE_KERNEL_PARAM_OPS_Genericdispatcher and are deliberately left alone here, to be changed separately within their respective subsystems.Signed-off-by Kees Cook <[email protected]>---
[...]kernel/params.c +27
-17@@ -453,36 +457,46 @@ static int param_array_set(const char *val, const struct kernel_param *kp) arr->num ?: &temp_num); } -static int param_array_get (char *buffer,const struct kernel_param *kp) +static int param_array_get (struct seq_buf *s,const struct kernel_param *kp) { -int i, off, ret; -char *elem_buf;const struct kparam_array *arr = kp->arr;struct kernel_param p = *kp; +char *elem_buf =NULL ; +int i, ret =0 ; - elem_buf =kmalloc (PAGE_SIZE ,GFP_KERNEL ); -if (!elem_buf) -return -ENOMEM ; +for (i =0 ; i < (arr->num ? *arr->num : arr->max); i++) { +size_t before = s->len; -for (i = off =0 ; i < (arr->num ? *arr->num : arr->max); i++) { p.arg = arr->elem + arr->elemsize * i;check_kparam_locked (p.mod); - ret = arr->ops->get_str (elem_buf, &p); -if (ret <0 ) - goto out; - ret =min (ret, (int )(PAGE_SIZE -1 - off)); -if (!ret) + +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); + } + +/* Nothing got written (e.g. overflow) — stop. */ +if (s->len == before)break ; +/* Replace the previous element's trailing newline with a comma. */ -if (i) - buffer[off -1 ] =',' ; -memcpy (buffer + off, elem_buf, ret); - off += ret; -if (off ==PAGE_SIZE -1 )
kernel/params.c static int param_array_set(const char *val, const struct kernel_param *kp) · line 502
Quoted 10 lines
kernel/params.c +3
-3-break ; +if (i && s->buffer[before -1 ] =='\n' ) + s->buffer[before -1 ] =',' ; } - buffer[off] ='\0' ; - ret = off; + ret =0 ; out:kfree (elem_buf);return ret;
Since you're almost completely rewriting the logic in param_array_get(), I suggest tightening it up a bit. The function could warn or return an error when a kernel_param_ops::get/get_str() call adds a string that doesn't terminate with '\n', specifically, when the call adds either a zero-length string or a non-zero-length string that ends with a different character (unless an overflow occurred).
The updated code silently stops the loop when a get call returns a zero-length string. Similarly, handling of a string not terminated by '\n' is halfway there because of the added check "s->buffer[before - 1] == '\n'".
Signature · 2 lines
Thanks, Petr
[email protected]
AI reviewRe: [PATCH 08/11] params: Convert generic kernel_param_ops .get helpers to seq_buf
In reply to Kees CookThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Information Leak / Uninitialized Memory Disclosure in param_array_get() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Information Leak / Uninitialized Memory Disclosure in param_array_get() --
commit 4bb10449d07e3a1b177001d61d53053c25dd4767
Author: Kees Cook <[email protected]>
params: Convert generic kernel_param_ops .get helpers to seq_buf
This commit converts the generic kernel parameter .get helpers in kernel/params.c to use the seq_buf signature instead of char pointers. It allows param_array_get to write element output directly into the parent seq_buf when supported, updating various dependent callers to match the new signature.
Quoted 4 lines
kernel/params.c +0
-0
[ ... ]
Quoted 1 line
kernel/params.c +0
-0@@ -453,36 +457,46 @@ static int param_array_set(const char *val, const struct kernel_param *kp)
[ ... ]
Quoted 3 lines
kernel/params.c +1
-1-static int param_array_get (char *buffer,const struct kernel_param *kp) +static int param_array_get (struct seq_buf *s,const struct kernel_param *kp) {
[ ... ]
Quoted 17 lines
kernel/params.c +8
-6-for (i = off =0 ; i < (arr->num ? *arr->num : arr->max); i++) { +for (i =0 ; i < (arr->num ? *arr->num : arr->max); i++) { +size_t before = s->len; p.arg = arr->elem + arr->elemsize * i;check_kparam_locked (p.mod); - ret = arr->ops->get_str (elem_buf, &p); -if (ret <0 ) - goto out; - ret =min (ret, (int )(PAGE_SIZE -1 - off)); -if (!ret) + +if (arr->ops->get) { + ret = arr->ops->get (s, &p); +if (ret <0 ) + goto out; + }else {
[ ... ]
kernel/params.c static int param_array_set(const char *val, const struct kernel_param *kp) · line 493
Quoted 9 lines
kernel/params.c +8
-0+ ret = arr->ops->get_str (elem_buf, &p); +if (ret <0 ) + goto out; +seq_buf_putmem (s, elem_buf, ret); + } + +/* Nothing got written (e.g. overflow) — stop. */ +if (s->len == before)break ;
[Severity: High]
When a seq_buf overflows, it calls seq_buf_set_overflow() which sets s->len = s->size. Because of this, does s->len actually equal before when an overflow occurs?
If s->len becomes s->size, the condition s->len == before will evaluate to false, causing the loop to continue for one more iteration rather than breaking. On the next iteration, before will be s->size, the write will fail again, and the loop will finally break.
Because the overflow mechanism sets the length to the buffer size without actually writing data into the remaining space, could this leak uninitialized kernel heap memory to userspace when sysfs returns the buffer?
Quoted 18 lines
kernel/params.c +5
-8+ +/* Replace the previous element's trailing newline with a comma. */ -if (i) - buffer[off -1 ] =',' ; -memcpy (buffer + off, elem_buf, ret); - off += ret; -if (off ==PAGE_SIZE -1 ) -break ; +if (i && s->buffer[before -1 ] =='\n' ) + s->buffer[before -1 ] =',' ; } - buffer[off] ='\0' ; - ret = off; + ret =0 ; out:kfree (elem_buf);return ret; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Kees Cook
maintainerPATCH 9/11 treewide: Convert custom kernel_param_ops .get callbacks to seq_buf via cocci
In reply to Kees CookUsing the following Coccinelle script, convert struct kernel_param_ops .get callbacks from "char *" to "struct seq_buf *" when the only write to the buffer is via a final call of scnprintf(), snprintf(), sprintf(), or sysfs_emit().
Since seq_buf_printf() will return -1 on overflow, and struct kernel_param_ops .get callbacks are expected to truncate without error, we must ignore the return value from seq_buf_print() and always return 0 (as the length is calculated in the common dispatcher code).
@@
identifier FN, BUF, KP;
expression FMT;
expression list ARGS;
@@
int FN(
- char *BUF
+ struct seq_buf *BUF
, const struct kernel_param *KP)
{
... when any
(
- return scnprintf(BUF, PAGE_SIZE, FMT, ARGS);
|
- return snprintf(BUF, PAGE_SIZE, FMT, ARGS);
|
- return sprintf(BUF, FMT, ARGS);
|
- return sysfs_emit(BUF, FMT, ARGS);
)
+ seq_buf_printf(BUF, FMT, ARGS);
+ return 0;
}
No struct kernel_param_ops initializations need changing since DEFINE_KERNEL_PARAM_OPS already routes the pointer to .get or .get_str via _Generic based on the function signature, so converted callbacks are automatically moved from the .get_str to the .get callback.
--- arch/s390/kernel/perf_cpum_sf.c | 6 ++- arch/x86/kernel/msr.c | 5 +- arch/x86/kvm/vmx/vmx.c | 18 ++++--- arch/x86/platform/uv/uv_nmi.c | 12 +++-- drivers/acpi/ec.c | 14 ++++-- drivers/acpi/sysfs.c | 6 ++- drivers/block/ublk_drv.c | 5 +- drivers/char/ipmi/ipmi_msghandler.c | 6 ++- drivers/firmware/qcom/qcom_scm.c | 12 +++-- drivers/gpu/drm/drm_panic.c | 7 +-- drivers/infiniband/hw/hfi1/driver.c | 7 +-- drivers/infiniband/ulp/srpt/ib_srpt.c | 5 +- drivers/input/misc/ati_remote2.c | 10 ++-- drivers/input/mouse/psmouse-base.c | 9 ++-- drivers/md/md.c | 5 +- drivers/media/pci/tw686x/tw686x-core.c | 6 ++- drivers/nvme/host/multipath.c | 5 +- drivers/power/supply/test_power.c | 47 +++++++++++-------- drivers/target/target_core_user.c | 12 +++-- .../processor_thermal_soc_slider.c | 12 +++-- drivers/ufs/core/ufs-fault-injection.c | 7 +-- drivers/vhost/scsi.c | 5 +- fs/nfs/namespace.c | 6 ++- fs/ocfs2/dlmfs/dlmfs.c | 5 +- fs/overlayfs/copy_up.c | 5 +- kernel/locking/locktorture.c | 6 ++- kernel/rcu/tree.c | 6 ++- kernel/workqueue.c | 6 ++- lib/test_dynamic_debug.c | 6 ++- mm/damon/lru_sort.c | 14 +++--- mm/damon/reclaim.c | 14 +++--- mm/damon/stat.c | 10 ++-- mm/memory_hotplug.c | 18 ++++--- net/ceph/ceph_common.c | 5 +- net/sunrpc/auth.c | 6 ++- net/sunrpc/svc.c | 5 +- security/apparmor/lsm.c | 16 ++++--- 37 files changed, 218 insertions(+), 131 deletions(-)
arch/s390/kernel/perf_cpum_sf.c +4 -2
@@ -1991,11 +1991,13 @@ static int s390_pmu_sf_offline_cpu(unsigned int cpu)return cpusf_pmu_setup (cpu,PMC_RELEASE ); } -static int param_get_sfb_size (char *buffer,const struct kernel_param *kp) +static int param_get_sfb_size (struct seq_buf *buffer, +const struct kernel_param *kp) {if (!cpum_sf_avail ())return -ENODEV ; -return sprintf (buffer,"%lu,%lu" ,CPUM_SF_MIN_SDB ,CPUM_SF_MAX_SDB ); +seq_buf_printf (buffer,"%lu,%lu" ,CPUM_SF_MIN_SDB ,CPUM_SF_MAX_SDB ); +return 0 ; }static int param_set_sfb_size (const char *val,const struct kernel_param *kp)
arch/x86/kernel/msr.c +3 -2
@@ -309,7 +309,7 @@ static int set_allow_writes(const char *val, const struct kernel_param *cp)return 0 ; } -static int get_allow_writes (char *buf,const struct kernel_param *kp) +static int get_allow_writes (struct seq_buf *buf,const struct kernel_param *kp) {const char *res;
@@ -319,7 +319,8 @@ static int get_allow_writes(char *buf, const struct kernel_param *kp)default : res ="default" ;break ; } -return sprintf (buf,"%s\n" , res); +seq_buf_printf (buf,"%s\n" , res); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(allow_writes_ops, set_allow_writes,
arch/x86/kvm/vmx/vmx.c +12 -6
@@ -368,12 +368,16 @@ static int vmentry_l1d_flush_set(const char *s, const struct kernel_param *kp)return ret; } -static int vmentry_l1d_flush_get (char *s,const struct kernel_param *kp) +static int vmentry_l1d_flush_get (struct seq_buf *s, +const struct kernel_param *kp) { -if (WARN_ON_ONCE (l1tf_vmx_mitigation >=ARRAY_SIZE (vmentry_l1d_param))) -return sysfs_emit (s,"???\n" ); +if (WARN_ON_ONCE (l1tf_vmx_mitigation >=ARRAY_SIZE (vmentry_l1d_param))) { +seq_buf_printf (s,"???\n" ); +return 0 ; + } -return sysfs_emit (s,"%s\n" , vmentry_l1d_param[l1tf_vmx_mitigation].option); +seq_buf_printf (s,"%s\n" , vmentry_l1d_param[l1tf_vmx_mitigation].option); +return 0 ; }/*
@@ -459,9 +463,11 @@ static int vmentry_l1d_flush_set(const char *s, const struct kernel_param *kp)pr_warn_once ("Kernel compiled without mitigations, ignoring vmentry_l1d_flush\n" ); return 0; } -static int vmentry_l1d_flush_get (char *s,const struct kernel_param *kp) +static int vmentry_l1d_flush_get (struct seq_buf *s, +const struct kernel_param *kp) { -return sysfs_emit (s,"never\n" ); +seq_buf_printf (s,"never\n" ); +return 0 ; }#endif
arch/x86/platform/uv/uv_nmi.c +8 -4
@@ -111,9 +111,11 @@ module_param_named(dump_loglevel, uv_nmi_loglevel, int, 0644);* The following values show statistics on how perf events are affecting * this system. */ -static int param_get_local64 (char *buffer,const struct kernel_param *kp) +static int param_get_local64 (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%lu\n" ,local64_read ((local64_t *)kp->arg)); +seq_buf_printf (buffer,"%lu\n" ,local64_read ((local64_t *)kp->arg)); +return 0 ; }static int param_set_local64 (const char *val,const struct kernel_param *kp)
@@ -207,9 +209,11 @@ static const char * const actions_desc[nmi_act_max] = {static enum action_t uv_nmi_action = nmi_act_dump; -static int param_get_action (char *buffer,const struct kernel_param *kp) +static int param_get_action (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%s\n" , actions[uv_nmi_action]); +seq_buf_printf (buffer,"%s\n" , actions[uv_nmi_action]); +return 0 ; }static int param_set_action (const char *val,const struct kernel_param *kp)
drivers/acpi/ec.c +9 -5
@@ -2236,18 +2236,22 @@ static int param_set_event_clearing(const char *val,return result; } -static int param_get_event_clearing (char *buffer, +static int param_get_event_clearing (struct seq_buf *buffer,const struct kernel_param *kp) {switch (ec_event_clearing) {case ACPI_EC_EVT_TIMING_STATUS : -return sprintf (buffer,"status\n" ); +seq_buf_printf (buffer,"status\n" ); +return 0 ;case ACPI_EC_EVT_TIMING_QUERY : -return sprintf (buffer,"query\n" ); +seq_buf_printf (buffer,"query\n" ); +return 0 ;case ACPI_EC_EVT_TIMING_EVENT : -return sprintf (buffer,"event\n" ); +seq_buf_printf (buffer,"event\n" ); +return 0 ;default : -return sprintf (buffer,"invalid\n" ); +seq_buf_printf (buffer,"invalid\n" ); +return 0 ; }return 0 ; }
drivers/acpi/sysfs.c +4 -2
@@ -192,9 +192,11 @@ static int param_set_trace_method_name(const char *val,return 0 ; } -static int param_get_trace_method_name (char *buffer,const struct kernel_param *kp) +static int param_get_trace_method_name (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sysfs_emit (buffer,"%s\n" , acpi_gbl_trace_method_name); +seq_buf_printf (buffer,"%s\n" , acpi_gbl_trace_method_name); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(param_ops_trace_method,
drivers/block/ublk_drv.c +3 -2
@@ -5868,10 +5868,11 @@ static int ublk_set_max_unprivileged_ublks(const char *buf,return param_set_uint_minmax (buf, kp,0 ,UBLK_MAX_UBLKS ); } -static int ublk_get_max_unprivileged_ublks (char *buf, +static int ublk_get_max_unprivileged_ublks (struct seq_buf *buf,const struct kernel_param *kp) { -return sysfs_emit (buf,"%u\n" , unprivileged_ublks_max); +seq_buf_printf (buf,"%u\n" , unprivileged_ublks_max); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(ublk_max_unprivileged_ublks_ops,
drivers/char/ipmi/ipmi_msghandler.c +4 -2
@@ -90,7 +90,8 @@ static int panic_op_write_handler(const char *val,return 0 ; } -static int panic_op_read_handler (char *buffer,const struct kernel_param *kp) +static int panic_op_read_handler (struct seq_buf *buffer, +const struct kernel_param *kp) {const char *event_str;
@@ -99,7 +100,8 @@ static int panic_op_read_handler(char *buffer, const struct kernel_param *kp)else event_str = ipmi_panic_event_str[ipmi_send_panic_event]; -return sprintf (buffer,"%s\n" , event_str); +seq_buf_printf (buffer,"%s\n" , event_str); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(panic_op_ops, panic_op_write_handler,
drivers/firmware/qcom/qcom_scm.c +8 -4
@@ -2694,12 +2694,16 @@ static irqreturn_t qcom_scm_irq_handler(int irq, void *data)return IRQ_HANDLED ; } -static int get_download_mode (char *buffer,const struct kernel_param *kp) +static int get_download_mode (struct seq_buf *buffer, +const struct kernel_param *kp) { -if (download_mode >=ARRAY_SIZE (download_mode_name)) -return sysfs_emit (buffer,"unknown mode\n" ); +if (download_mode >=ARRAY_SIZE (download_mode_name)) { +seq_buf_printf (buffer,"unknown mode\n" ); +return 0 ; + } -return sysfs_emit (buffer,"%s\n" , download_mode_name[download_mode]); +seq_buf_printf (buffer,"%s\n" , download_mode_name[download_mode]); +return 0 ; }static int set_download_mode (const char *val,const struct kernel_param *kp)
drivers/gpu/drm/drm_panic.c +4 -3
@@ -841,10 +841,11 @@ static int drm_panic_type_set(const char *val, const struct kernel_param *kp)return -EINVAL ; } -static int drm_panic_type_get (char *buffer,const struct kernel_param *kp) +static int drm_panic_type_get (struct seq_buf *buffer, +const struct kernel_param *kp) { -return scnprintf (buffer,PAGE_SIZE ,"%s\n" , - drm_panic_type_map[drm_panic_type]); +seq_buf_printf (buffer,"%s\n" , drm_panic_type_map[drm_panic_type]); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(drm_panic_ops, drm_panic_type_set,
drivers/infiniband/hw/hfi1/driver.c +4 -3
@@ -41,7 +41,7 @@ MODULE_PARM_DESC(cu, "Credit return units");unsigned long hfi1_cap_mask =HFI1_CAP_MASK_DEFAULT ;static int hfi1_caps_set (const char *val,const struct kernel_param *kp); -static int hfi1_caps_get (char *buffer,const struct kernel_param *kp); +static int hfi1_caps_get (struct seq_buf *buffer,const struct kernel_param *kp); static DEFINE_KERNEL_PARAM_OPS(cap_ops, hfi1_caps_set, hfi1_caps_get);module_param_cb (cap_mask, &cap_ops, &hfi1_cap_mask,S_IWUSR |S_IRUGO );MODULE_PARM_DESC (cap_mask,"Bit mask of enabled/disabled HW features" );
@@ -101,14 +101,15 @@ static int hfi1_caps_set(const char *val, const struct kernel_param *kp)return ret; } -static int hfi1_caps_get (char *buffer,const struct kernel_param *kp) +static int hfi1_caps_get (struct seq_buf *buffer,const struct kernel_param *kp) {unsigned long cap_mask = *(unsigned long *)kp->arg; cap_mask &= ~HFI1_CAP_LOCKED_SMASK ; cap_mask |= ((cap_mask &HFI1_CAP_K2U ) <<HFI1_CAP_USER_SHIFT ); -return sysfs_emit (buffer,"0x%lx\n" , cap_mask); +seq_buf_printf (buffer,"0x%lx\n" , cap_mask); +return 0 ; }struct pci_dev *get_pci_dev (struct rvt_dev_info *rdi)
drivers/infiniband/ulp/srpt/ib_srpt.c +3 -2
@@ -86,9 +86,10 @@ static int srpt_set_u64_x(const char *buffer, const struct kernel_param *kp) {return kstrtou64 (buffer,16 , (u64 *)kp->arg); } -static int srpt_get_u64_x (char *buffer,const struct kernel_param *kp) +static int srpt_get_u64_x (struct seq_buf *buffer,const struct kernel_param *kp) { -return sprintf (buffer,"0x%016llx\n" , *(u64 *)kp->arg); +seq_buf_printf (buffer,"0x%016llx\n" , *(u64 *)kp->arg); +return 0 ; }module_param_call (srpt_service_guid, srpt_set_u64_x, srpt_get_u64_x, &srpt_service_guid,0444 );
drivers/input/misc/ati_remote2.c +6 -4
@@ -63,12 +63,13 @@ static int ati_remote2_set_channel_mask(const char *val,return ati_remote2_set_mask (val, kp,ATI_REMOTE2_MAX_CHANNEL_MASK ); } -static int ati_remote2_get_channel_mask (char *buffer, +static int ati_remote2_get_channel_mask (struct seq_buf *buffer,const struct kernel_param *kp) {pr_debug ("%s()\n" , __func__); -return sprintf (buffer,"0x%04x\n" , *(unsigned int *)kp->arg); +seq_buf_printf (buffer,"0x%04x\n" , *(unsigned int *)kp->arg); +return 0 ; } static int ati_remote2_set_mode_mask(const char *val,
@@ -79,12 +80,13 @@ static int ati_remote2_set_mode_mask(const char *val,return ati_remote2_set_mask (val, kp,ATI_REMOTE2_MAX_MODE_MASK ); } -static int ati_remote2_get_mode_mask (char *buffer, +static int ati_remote2_get_mode_mask (struct seq_buf *buffer,const struct kernel_param *kp) {pr_debug ("%s()\n" , __func__); -return sprintf (buffer,"0x%02x\n" , *(unsigned int *)kp->arg); +seq_buf_printf (buffer,"0x%02x\n" , *(unsigned int *)kp->arg); +return 0 ; }static unsigned int channel_mask =ATI_REMOTE2_MAX_CHANNEL_MASK ;
drivers/input/mouse/psmouse-base.c +6 -3
@@ -44,7 +44,8 @@ MODULE_LICENSE("GPL");static unsigned int psmouse_max_proto =PSMOUSE_AUTO ;static int psmouse_set_maxproto (const char *val,const struct kernel_param *); -static int psmouse_get_maxproto (char *buffer,const struct kernel_param *kp); +static int psmouse_get_maxproto (struct seq_buf *buffer, +const struct kernel_param *kp); static DEFINE_KERNEL_PARAM_OPS(param_ops_proto_abbrev, psmouse_set_maxproto, psmouse_get_maxproto);#define param_check_proto_abbrev (name, p) __param_check(name, p, unsigned int)
@@ -1994,11 +1995,13 @@ static int psmouse_set_maxproto(const char *val, const struct kernel_param *kp)return 0 ; } -static int psmouse_get_maxproto (char *buffer,const struct kernel_param *kp) +static int psmouse_get_maxproto (struct seq_buf *buffer, +const struct kernel_param *kp) {int type = *((unsigned int *)kp->arg); -return sprintf (buffer,"%s\n" ,psmouse_protocol_by_type (type)->name); +seq_buf_printf (buffer,"%s\n" ,psmouse_protocol_by_type (type)->name); +return 0 ; }static int __init psmouse_init (void )
drivers/md/md.c +3 -2
@@ -10989,9 +10989,10 @@ static __exit void md_exit(void)subsys_initcall (md_init);module_exit (md_exit) -static int get_ro(char *buffer, const struct kernel_param *kp) +static int get_ro(struct seq_buf *buffer, const struct kernel_param *kp) { -return sprintf (buffer,"%d\n" , start_readonly); +seq_buf_printf (buffer,"%d\n" , start_readonly); +return 0 ; }static int set_ro (const char *val,const struct kernel_param *kp) {
drivers/media/pci/tw686x/tw686x-core.c +4 -2
@@ -69,9 +69,11 @@ static const char *dma_mode_name(unsigned int mode) } } -static int tw686x_dma_mode_get (char *buffer,const struct kernel_param *kp) +static int tw686x_dma_mode_get (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%s" ,dma_mode_name (dma_mode)); +seq_buf_printf (buffer,"%s" ,dma_mode_name (dma_mode)); +return 0 ; }static int tw686x_dma_mode_set (const char *val,const struct kernel_param *kp)
drivers/nvme/host/multipath.c +3 -2
@@ -85,9 +85,10 @@ static int nvme_set_iopolicy(const char *val, const struct kernel_param *kp)return 0 ; } -static int nvme_get_iopolicy (char *buf,const struct kernel_param *kp) +static int nvme_get_iopolicy (struct seq_buf *buf,const struct kernel_param *kp) { -return sprintf (buf,"%s\n" , nvme_iopolicy_names[iopolicy]); +seq_buf_printf (buf,"%s\n" , nvme_iopolicy_names[iopolicy]); +return 0 ; } module_param_call(iopolicy, nvme_set_iopolicy, nvme_get_iopolicy,
drivers/power/supply/test_power.c +28 -19
91 lines not on this page · raw message
drivers/target/target_core_user.c +7 -5
@@ -249,10 +249,11 @@ static int tcmu_set_global_max_data_area(const char *str,return 0 ; } -static int tcmu_get_global_max_data_area (char *buffer, +static int tcmu_get_global_max_data_area (struct seq_buf *buffer,const struct kernel_param *kp) { -return sprintf (buffer,"%d\n" ,TCMU_PAGES_TO_MBS (tcmu_global_max_pages)); +seq_buf_printf (buffer,"%d\n" ,TCMU_PAGES_TO_MBS (tcmu_global_max_pages)); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(tcmu_global_max_data_area_op,
@@ -265,11 +266,12 @@ MODULE_PARM_DESC(global_max_data_area_mb,"Max MBs allowed to be allocated to all the tcmu device's " "data areas."); -static int tcmu_get_block_netlink (char *buffer, +static int tcmu_get_block_netlink (struct seq_buf *buffer,const struct kernel_param *kp) { -return sprintf (buffer,"%s\n" , tcmu_netlink_blocked ? -"blocked" :"unblocked" ); +seq_buf_printf (buffer,"%s\n" , + tcmu_netlink_blocked ?"blocked" :"unblocked" ); +return 0 ; } static int tcmu_set_block_netlink(const char *str,
drivers/thermal/intel/int340x_thermal/processor_thermal_soc_slider.c +8 -4
@@ -77,10 +77,12 @@ static int slider_def_balance_set(const char *arg, const struct kernel_param *kpreturn ret; } -static int slider_def_balance_get (char *buf,const struct kernel_param *kp) +static int slider_def_balance_get (struct seq_buf *buf, +const struct kernel_param *kp) {guard (mutex)(&slider_param_lock); -return sysfs_emit (buf,"%02x\n" , slider_values[SOC_POWER_SLIDER_BALANCE ]); +seq_buf_printf (buf,"%02x\n" , slider_values[SOC_POWER_SLIDER_BALANCE ]); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(slider_def_balance_ops, slider_def_balance_set,
@@ -109,10 +111,12 @@ static int slider_def_offset_set(const char *arg, const struct kernel_param *kp)return ret; } -static int slider_def_offset_get (char *buf,const struct kernel_param *kp) +static int slider_def_offset_get (struct seq_buf *buf, +const struct kernel_param *kp) {guard (mutex)(&slider_param_lock); -return sysfs_emit (buf,"%02x\n" , slider_offset); +seq_buf_printf (buf,"%02x\n" , slider_offset); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(slider_offset_ops, slider_def_offset_set,
drivers/ufs/core/ufs-fault-injection.c +4 -3
@@ -8,7 +8,7 @@#include <ufs/ufshcd.h> #include "ufs-fault-injection.h" -static int ufs_fault_get (char *buffer,const struct kernel_param *kp); +static int ufs_fault_get (struct seq_buf *buffer,const struct kernel_param *kp);static int ufs_fault_set (const char *val,const struct kernel_param *kp); static DEFINE_KERNEL_PARAM_OPS(ufs_fault_ops, ufs_fault_set, ufs_fault_get);
@@ -31,11 +31,12 @@ MODULE_PARM_DESC(timeout, "Fault injection. timeout=<interval>,<probability>,<space>,<times>");static DECLARE_FAULT_ATTR (ufs_timeout_attr); -static int ufs_fault_get (char *buffer,const struct kernel_param *kp) +static int ufs_fault_get (struct seq_buf *buffer,const struct kernel_param *kp) {const char *fault_str = kp->arg; -return sysfs_emit (buffer,"%s\n" , fault_str); +seq_buf_printf (buffer,"%s\n" , fault_str); +return 0 ; }static int ufs_fault_set (const char *val,const struct kernel_param *kp)
drivers/vhost/scsi.c +3 -2
@@ -81,10 +81,11 @@ static int vhost_scsi_set_inline_sg_cnt(const char *buf, }#endif -static int vhost_scsi_get_inline_sg_cnt (char *buf, +static int vhost_scsi_get_inline_sg_cnt (struct seq_buf *buf,const struct kernel_param *kp) { -return sprintf (buf,"%u\n" , vhost_scsi_inline_sg_cnt); +seq_buf_printf (buf,"%u\n" , vhost_scsi_inline_sg_cnt); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(vhost_scsi_inline_sg_cnt_op,
fs/nfs/namespace.c +4 -2
@@ -358,7 +358,8 @@ static int param_set_nfs_timeout(const char *val, const struct kernel_param *kp)return 0 ; } -static int param_get_nfs_timeout (char *buffer,const struct kernel_param *kp) +static int param_get_nfs_timeout (struct seq_buf *buffer, +const struct kernel_param *kp) {long num = *((int *)kp->arg);
@@ -369,7 +370,8 @@ static int param_get_nfs_timeout(char *buffer, const struct kernel_param *kp) num = (num + (HZ -1 )) /HZ ; }else num =-1 ; -return sysfs_emit (buffer,"%li\n" , num); +seq_buf_printf (buffer,"%li\n" , num); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(param_ops_nfs_timeout, param_set_nfs_timeout,
fs/ocfs2/dlmfs/dlmfs.c +3 -2
@@ -78,10 +78,11 @@ static int param_set_dlmfs_capabilities(const char *val,printk (KERN_ERR "%s: readonly parameter\n" , kp->name);return -EINVAL ; } -static int param_get_dlmfs_capabilities (char *buffer, +static int param_get_dlmfs_capabilities (struct seq_buf *buffer,const struct kernel_param *kp) { -return sysfs_emit (buffer,DLMFS_CAPABILITIES ); +seq_buf_printf (buffer,DLMFS_CAPABILITIES ); +return 0 ; }module_param_call (capabilities, param_set_dlmfs_capabilities, param_get_dlmfs_capabilities,NULL ,0444 );
fs/overlayfs/copy_up.c +3 -2
@@ -28,9 +28,10 @@ static int ovl_ccup_set(const char *buf, const struct kernel_param *param)return 0 ; } -static int ovl_ccup_get (char *buf,const struct kernel_param *param) +static int ovl_ccup_get (struct seq_buf *buf,const struct kernel_param *param) { -return sprintf (buf,"N\n" ); +seq_buf_printf (buf,"N\n" ); +return 0 ; }module_param_call (check_copy_up, ovl_ccup_set, ovl_ccup_get,NULL ,0644 );
kernel/locking/locktorture.c +4 -2
@@ -86,11 +86,13 @@ static int param_set_cpumask(const char *val, const struct kernel_param *kp) }// Output a cpumask kernel parameter. -static int param_get_cpumask (char *buffer,const struct kernel_param *kp) +static int param_get_cpumask (struct seq_buf *buffer, +const struct kernel_param *kp) {cpumask_var_t *cm_bind = kp->arg; -return sprintf (buffer,"%*pbl" ,cpumask_pr_args (*cm_bind)); +seq_buf_printf (buffer,"%*pbl" ,cpumask_pr_args (*cm_bind)); +return 0 ; }static bool cpumask_nonempty (cpumask_var_t mask)
kernel/rcu/tree.c +4 -2
@@ -3970,9 +3970,11 @@ static int param_set_do_rcu_barrier(const char *val, const struct kernel_param */* * Output the number of outstanding rcutree.do_rcu_barrier requests. */ -static int param_get_do_rcu_barrier (char *buffer,const struct kernel_param *kp) +static int param_get_do_rcu_barrier (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%d\n" ,atomic_read ((atomic_t *)kp->arg)); +seq_buf_printf (buffer,"%d\n" ,atomic_read ((atomic_t *)kp->arg)); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(do_rcu_barrier_ops, param_set_do_rcu_barrier,
kernel/workqueue.c +4 -2
@@ -7157,9 +7157,11 @@ static int wq_affn_dfl_set(const char *val, const struct kernel_param *kp)return 0 ; } -static int wq_affn_dfl_get (char *buffer,const struct kernel_param *kp) +static int wq_affn_dfl_get (struct seq_buf *buffer, +const struct kernel_param *kp) { -return scnprintf (buffer,PAGE_SIZE ,"%s\n" , wq_affn_names[wq_affn_dfl]); +seq_buf_printf (buffer,"%s\n" , wq_affn_names[wq_affn_dfl]); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(wq_affn_dfl_ops, wq_affn_dfl_set,
lib/test_dynamic_debug.c +4 -2
@@ -18,10 +18,12 @@ static int param_set_do_prints(const char *instr, const struct kernel_param *kp)do_prints ();return 0 ; } -static int param_get_do_prints (char *buffer,const struct kernel_param *kp) +static int param_get_do_prints (struct seq_buf *buffer, +const struct kernel_param *kp) {do_prints (); -return scnprintf (buffer,PAGE_SIZE ,"did do_prints\n" ); +seq_buf_printf (buffer,"did do_prints\n" ); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(param_ops_do_prints, param_set_do_prints, param_get_do_prints);
mm/damon/lru_sort.c +8 -6
@@ -438,10 +438,11 @@ static int damon_lru_sort_enabled_store(const char *val,return damon_lru_sort_turn (enabled); } -static int damon_lru_sort_enabled_load (char *buffer, -const struct kernel_param *kp) +static int damon_lru_sort_enabled_load (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%c\n" ,damon_lru_sort_enabled () ?'Y' :'N' ); +seq_buf_printf (buffer,"%c\n" ,damon_lru_sort_enabled () ?'Y' :'N' ); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, damon_lru_sort_enabled_store,
@@ -461,8 +462,8 @@ static int damon_lru_sort_kdamond_pid_store(const char *val,return 0 ; } -static int damon_lru_sort_kdamond_pid_load (char *buffer, -const struct kernel_param *kp) +static int damon_lru_sort_kdamond_pid_load (struct seq_buf *buffer, +const struct kernel_param *kp) {int kdamond_pid =-1 ;
@@ -471,7 +472,8 @@ static int damon_lru_sort_kdamond_pid_load(char *buffer,if (kdamond_pid <0 ) kdamond_pid =-1 ; } -return sprintf (buffer,"%d\n" , kdamond_pid); +seq_buf_printf (buffer,"%d\n" , kdamond_pid); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(kdamond_pid_param_ops,
mm/damon/reclaim.c +8 -6
@@ -340,10 +340,11 @@ static int damon_reclaim_enabled_store(const char *val,return damon_reclaim_turn (enabled); } -static int damon_reclaim_enabled_load (char *buffer, -const struct kernel_param *kp) +static int damon_reclaim_enabled_load (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%c\n" ,damon_reclaim_enabled () ?'Y' :'N' ); +seq_buf_printf (buffer,"%c\n" ,damon_reclaim_enabled () ?'Y' :'N' ); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, damon_reclaim_enabled_store,
@@ -363,8 +364,8 @@ static int damon_reclaim_kdamond_pid_store(const char *val,return 0 ; } -static int damon_reclaim_kdamond_pid_load (char *buffer, -const struct kernel_param *kp) +static int damon_reclaim_kdamond_pid_load (struct seq_buf *buffer, +const struct kernel_param *kp) {int kdamond_pid =-1 ;
@@ -373,7 +374,8 @@ static int damon_reclaim_kdamond_pid_load(char *buffer,if (kdamond_pid <0 ) kdamond_pid =-1 ; } -return sprintf (buffer,"%d\n" , kdamond_pid); +seq_buf_printf (buffer,"%d\n" , kdamond_pid); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(kdamond_pid_param_ops,
mm/damon/stat.c +6 -4
@@ -19,8 +19,8 @@static int damon_stat_enabled_store (const char *val,const struct kernel_param *kp); -static int damon_stat_enabled_load (char *buffer, -const struct kernel_param *kp); +static int damon_stat_enabled_load (struct seq_buf *buffer, +const struct kernel_param *kp); static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, damon_stat_enabled_store, damon_stat_enabled_load);
@@ -306,9 +306,11 @@ static int damon_stat_enabled_store(return 0 ; } -static int damon_stat_enabled_load (char *buffer,const struct kernel_param *kp) +static int damon_stat_enabled_load (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%c\n" ,damon_stat_enabled () ?'Y' :'N' ); +seq_buf_printf (buffer,"%c\n" ,damon_stat_enabled () ?'Y' :'N' ); +return 0 ; }static int __init damon_stat_init (void )
mm/memory_hotplug.c +12 -6
@@ -100,13 +100,17 @@ static int set_memmap_mode(const char *val, const struct kernel_param *kp)return 0 ; } -static int get_memmap_mode (char *buffer,const struct kernel_param *kp) +static int get_memmap_mode (struct seq_buf *buffer, +const struct kernel_param *kp) {int mode = *((int *)kp->arg); -if (mode ==MEMMAP_ON_MEMORY_FORCE ) -return sprintf (buffer,"force\n" ); -return sprintf (buffer,"%c\n" , mode ?'Y' :'N' ); +if (mode ==MEMMAP_ON_MEMORY_FORCE ) { +seq_buf_printf (buffer,"force\n" ); +return 0 ; + } +seq_buf_printf (buffer,"%c\n" , mode ?'Y' :'N' ); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(memmap_mode_ops, set_memmap_mode,
@@ -147,9 +151,11 @@ static int set_online_policy(const char *val, const struct kernel_param *kp)return 0 ; } -static int get_online_policy (char *buffer,const struct kernel_param *kp) +static int get_online_policy (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%s\n" , online_policy_to_str[*((int *)kp->arg)]); +seq_buf_printf (buffer,"%s\n" , online_policy_to_str[*((int *)kp->arg)]); +return 0 ; }/*
net/ceph/ceph_common.c +3 -2
@@ -47,10 +47,11 @@ bool libceph_compatible(void *data) }EXPORT_SYMBOL (libceph_compatible); -static int param_get_supported_features (char *buffer, +static int param_get_supported_features (struct seq_buf *buffer,const struct kernel_param *kp) { -return sprintf (buffer,"0x%llx" ,CEPH_FEATURES_SUPPORTED_DEFAULT ); +seq_buf_printf (buffer,"0x%llx" ,CEPH_FEATURES_SUPPORTED_DEFAULT ); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(param_ops_supported_features, NULL, param_get_supported_features);
net/sunrpc/auth.c +4 -2
@@ -73,12 +73,14 @@ static int param_set_hashtbl_sz(const char *val, const struct kernel_param *kp)return -EINVAL ; } -static int param_get_hashtbl_sz (char *buffer,const struct kernel_param *kp) +static int param_get_hashtbl_sz (struct seq_buf *buffer, +const struct kernel_param *kp) {unsigned int nbits; nbits = *(unsigned int *)kp->arg; -return sprintf (buffer,"%u\n" ,1U << nbits); +seq_buf_printf (buffer,"%u\n" ,1U << nbits); +return 0 ; }#define param_check_hashtbl_sz (name, p) __param_check(name, p, unsigned int);
net/sunrpc/svc.c +3 -2
@@ -148,7 +148,7 @@ sunrpc_get_pool_mode(char *buf, size_t size)EXPORT_SYMBOL (sunrpc_get_pool_mode);static int -param_get_pool_mode (char *buf,const struct kernel_param *kp) +param_get_pool_mode (struct seq_buf *buf,const struct kernel_param *kp) {char str[16 ];int len;
@@ -162,7 +162,8 @@ param_get_pool_mode(char *buf, const struct kernel_param *kp) str[len] ='\n' ; str[len +1 ] ='\0' ; -return sysfs_emit (buf,"%s" , str); +seq_buf_printf (buf,"%s" , str); +return 0 ; } module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode,
security/apparmor/lsm.c +10 -6
@@ -1797,10 +1797,11 @@ static int param_set_debug(const char *val, const struct kernel_param *kp);static int param_get_debug (struct seq_buf *buffer,const struct kernel_param *kp);static int param_set_audit (const char *val,const struct kernel_param *kp); -static int param_get_audit (char *buffer,const struct kernel_param *kp); +static int param_get_audit (struct seq_buf *buffer, +const struct kernel_param *kp);static int param_set_mode (const char *val,const struct kernel_param *kp); -static int param_get_mode (char *buffer,const struct kernel_param *kp); +static int param_get_mode (struct seq_buf *buffer,const struct kernel_param *kp);/* Flag values, also controllable via /sys/module/apparmor/parameters * We define special types as we want to do additional mediation.
@@ -2050,13 +2051,15 @@ static int param_set_debug(const char *val, const struct kernel_param *kp)return 0 ; } -static int param_get_audit (char *buffer,const struct kernel_param *kp) +static int param_get_audit (struct seq_buf *buffer, +const struct kernel_param *kp) {if (!apparmor_enabled)return -EINVAL ;if (apparmor_initialized && !aa_current_policy_view_capable (NULL ))return -EPERM ; -return sysfs_emit (buffer,"%s\n" , audit_mode_names[aa_g_audit]); +seq_buf_printf (buffer,"%s\n" , audit_mode_names[aa_g_audit]); +return 0 ; }static int param_set_audit (const char *val,const struct kernel_param *kp)
@@ -2078,13 +2081,14 @@ static int param_set_audit(const char *val, const struct kernel_param *kp)return 0 ; } -static int param_get_mode (char *buffer,const struct kernel_param *kp) +static int param_get_mode (struct seq_buf *buffer,const struct kernel_param *kp) {if (!apparmor_enabled)return -EINVAL ;if (apparmor_initialized && !aa_current_policy_view_capable (NULL ))return -EPERM ; -return sysfs_emit (buffer,"%s\n" , aa_profile_mode_names[aa_g_profile_mode]); +seq_buf_printf (buffer,"%s\n" , aa_profile_mode_names[aa_g_profile_mode]); +return 0 ; }static int param_set_mode (const char *val,const struct kernel_param *kp)
Signature · 1 line
2.34.1
Sean Christopherson
maintainerRe: [PATCH 09/11] treewide: Convert custom kernel_param_ops .get callbacks to seq_buf via cocci
Quoted 12 lines · Kees Cook
arch/x86/kvm/vmx/vmx.c +2
-1@@ -368,12 +368,16 @@ static int vmentry_l1d_flush_set(const char *s, const struct kernel_param *kp)return ret; } -static int vmentry_l1d_flush_get (char *s,const struct kernel_param *kp) +static int vmentry_l1d_flush_get (struct seq_buf *s, +const struct kernel_param *kp) {
arch/x86/kvm/vmx/vmx.c static int vmentry_l1d_flush_set(const char *s, const struct kernel_param *kp) · line 380
Quoted 10 lines
arch/x86/kvm/vmx/vmx.c +6
-3-if (WARN_ON_ONCE (l1tf_vmx_mitigation >=ARRAY_SIZE (vmentry_l1d_param))) -return sysfs_emit (s,"???\n" ); +if (WARN_ON_ONCE (l1tf_vmx_mitigation >=ARRAY_SIZE (vmentry_l1d_param))) { +seq_buf_printf (s,"???\n" ); +return 0 ; + } -return sysfs_emit (s,"%s\n" , vmentry_l1d_param[l1tf_vmx_mitigation].option); +seq_buf_printf (s,"%s\n" , vmentry_l1d_param[l1tf_vmx_mitigation].option); +return 0 ;
For this one, can you manually change it to this?
if (WARN_ON_ONCE(l1tf_vmx_mitigation >= ARRAY_SIZE(vmentry_l1d_param))) seq_buf_printf(s, "???\n"); else seq_buf_printf(s, "%s\n", vmentry_l1d_param[l1tf_vmx_mitigation].option); return 0;
Quoted 16 lines
arch/x86/kvm/vmx/vmx.c +4
-2}/* @@ -459,9 +463,11 @@ static int vmentry_l1d_flush_set(const char *s, const struct kernel_param *kp)pr_warn_once ("Kernel compiled without mitigations, ignoring vmentry_l1d_flush\n" ); return 0; } -static int vmentry_l1d_flush_get (char *s,const struct kernel_param *kp) +static int vmentry_l1d_flush_get (struct seq_buf *s, +const struct kernel_param *kp) { -return sysfs_emit (s,"never\n" ); +seq_buf_printf (s,"never\n" ); +return 0 ; }#endif
Re: [PATCH 09/11] treewide: Convert custom kernel_param_ops .get callbacks to seq_buf via cocci
In reply to Kees CookQuoted 35 lines · Kees Cook
Using the following Coccinelle script, convert struct
kernel_param_ops.get callbacks from "char *" to "structseq_buf*" when the only write to the buffer is via a final call ofscnprintf(),snprintf(),sprintf(), orsysfs_emit().Since
seq_buf_printf()will return -1 on overflow, and structkernel_param_ops.get callbacks are expected to truncate without error, we must ignore the return value fromseq_buf_print()and always return 0 (as the length is calculated in the common dispatcher code).@@
identifier FN, BUF, KP;
expression FMT;
expression list ARGS;
@@
int FN((quoted diff) +1
-1- char *BUF + struct seq_buf *BUF , const struct kernel_param *KP) { ... when any(
- returnscnprintf(BUF, PAGE_SIZE, FMT, ARGS);
|
- returnsnprintf(BUF, PAGE_SIZE, FMT, ARGS);
|
- returnsprintf(BUF, FMT, ARGS);
|
- returnsysfs_emit(BUF, FMT, ARGS);
)arch/s390/kernel/perf_cpum_sf.c +2
-0+seq_buf_printf (BUF ,FMT ,ARGS ); +return 0 ; }
Quoted 6 lines
No struct
kernel_param_opsinitializations need changing sinceDEFINE_KERNEL_PARAM_OPSalready routes the pointer to .get or .get_str via_Genericbased on the function signature, so converted callbacks are automatically moved from the .get_str to the .get callback.Signed-off-by Kees Cook <[email protected]>
For ACPI:
Quoted 1,072 lines
--- arch/s390/kernel/perf_cpum_sf.c | 6 ++- arch/x86/kernel/msr.c | 5 +- arch/x86/kvm/vmx/vmx.c | 18 ++++--- arch/x86/platform/uv/uv_nmi.c | 12 +++-- drivers/acpi/ec.c | 14 ++++-- drivers/acpi/sysfs.c | 6 ++- drivers/block/ublk_drv.c | 5 +- drivers/char/ipmi/ipmi_msghandler.c | 6 ++- drivers/firmware/qcom/qcom_scm.c | 12 +++-- drivers/gpu/drm/drm_panic.c | 7 +-- drivers/infiniband/hw/hfi1/driver.c | 7 +-- drivers/infiniband/ulp/srpt/ib_srpt.c | 5 +- drivers/input/misc/ati_remote2.c | 10 ++-- drivers/input/mouse/psmouse-base.c | 9 ++-- drivers/md/md.c | 5 +- drivers/media/pci/tw686x/tw686x-core.c | 6 ++- drivers/nvme/host/multipath.c | 5 +- drivers/power/supply/test_power.c | 47 +++++++++++-------- drivers/target/target_core_user.c | 12 +++-- .../processor_thermal_soc_slider.c | 12 +++-- drivers/ufs/core/ufs-fault-injection.c | 7 +-- drivers/vhost/scsi.c | 5 +- fs/nfs/namespace.c | 6 ++- fs/ocfs2/dlmfs/dlmfs.c | 5 +- fs/overlayfs/copy_up.c | 5 +- kernel/locking/locktorture.c | 6 ++- kernel/rcu/tree.c | 6 ++- kernel/workqueue.c | 6 ++- lib/test_dynamic_debug.c | 6 ++- mm/damon/lru_sort.c | 14 +++--- mm/damon/reclaim.c | 14 +++--- mm/damon/stat.c | 10 ++-- mm/memory_hotplug.c | 18 ++++--- net/ceph/ceph_common.c | 5 +- net/sunrpc/auth.c | 6 ++- net/sunrpc/svc.c | 5 +- security/apparmor/lsm.c | 16 ++++--- 37 files changed, 218 insertions(+), 131 deletions(-)arch/s390/kernel/perf_cpum_sf.c +4
-2@@ -1991,11 +1991,13 @@ static int s390_pmu_sf_offline_cpu(unsigned int cpu)return cpusf_pmu_setup (cpu,PMC_RELEASE ); } -static int param_get_sfb_size (char *buffer,const struct kernel_param *kp) +static int param_get_sfb_size (struct seq_buf *buffer, +const struct kernel_param *kp) {if (!cpum_sf_avail ())return -ENODEV ; -return sprintf (buffer,"%lu,%lu" ,CPUM_SF_MIN_SDB ,CPUM_SF_MAX_SDB ); +seq_buf_printf (buffer,"%lu,%lu" ,CPUM_SF_MIN_SDB ,CPUM_SF_MAX_SDB ); +return 0 ; }static int param_set_sfb_size (const char *val,const struct kernel_param *kp)arch/x86/kernel/msr.c +3
-2@@ -309,7 +309,7 @@ static int set_allow_writes(const char *val, const struct kernel_param *cp)return 0 ; } -static int get_allow_writes (char *buf,const struct kernel_param *kp) +static int get_allow_writes (struct seq_buf *buf,const struct kernel_param *kp) {const char *res;@@ -319,7 +319,8 @@ static int get_allow_writes(char *buf, const struct kernel_param *kp)default : res ="default" ;break ; } -return sprintf (buf,"%s\n" , res); +seq_buf_printf (buf,"%s\n" , res); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(allow_writes_ops, set_allow_writes,arch/x86/kvm/vmx/vmx.c +12
-6@@ -368,12 +368,16 @@ static int vmentry_l1d_flush_set(const char *s, const struct kernel_param *kp)return ret; } -static int vmentry_l1d_flush_get (char *s,const struct kernel_param *kp) +static int vmentry_l1d_flush_get (struct seq_buf *s, +const struct kernel_param *kp) { -if (WARN_ON_ONCE (l1tf_vmx_mitigation >=ARRAY_SIZE (vmentry_l1d_param))) -return sysfs_emit (s,"???\n" ); +if (WARN_ON_ONCE (l1tf_vmx_mitigation >=ARRAY_SIZE (vmentry_l1d_param))) { +seq_buf_printf (s,"???\n" ); +return 0 ; + } -return sysfs_emit (s,"%s\n" , vmentry_l1d_param[l1tf_vmx_mitigation].option); +seq_buf_printf (s,"%s\n" , vmentry_l1d_param[l1tf_vmx_mitigation].option); +return 0 ; }/* @@ -459,9 +463,11 @@ static int vmentry_l1d_flush_set(const char *s, const struct kernel_param *kp)pr_warn_once ("Kernel compiled without mitigations, ignoring vmentry_l1d_flush\n" ); return 0; } -static int vmentry_l1d_flush_get (char *s,const struct kernel_param *kp) +static int vmentry_l1d_flush_get (struct seq_buf *s, +const struct kernel_param *kp) { -return sysfs_emit (s,"never\n" ); +seq_buf_printf (s,"never\n" ); +return 0 ; }#endif arch/x86/platform/uv/uv_nmi.c +8
-4@@ -111,9 +111,11 @@ module_param_named(dump_loglevel, uv_nmi_loglevel, int, 0644);* The following values show statistics on how perf events are affecting * this system. */ -static int param_get_local64 (char *buffer,const struct kernel_param *kp) +static int param_get_local64 (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%lu\n" ,local64_read ((local64_t *)kp->arg)); +seq_buf_printf (buffer,"%lu\n" ,local64_read ((local64_t *)kp->arg)); +return 0 ; }static int param_set_local64 (const char *val,const struct kernel_param *kp)@@ -207,9 +209,11 @@ static const char * const actions_desc[nmi_act_max] = {static enum action_t uv_nmi_action = nmi_act_dump; -static int param_get_action (char *buffer,const struct kernel_param *kp) +static int param_get_action (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%s\n" , actions[uv_nmi_action]); +seq_buf_printf (buffer,"%s\n" , actions[uv_nmi_action]); +return 0 ; }static int param_set_action (const char *val,const struct kernel_param *kp)drivers/acpi/ec.c +9
-5@@ -2236,18 +2236,22 @@ static int param_set_event_clearing(const char *val,return result; } -static int param_get_event_clearing (char *buffer, +static int param_get_event_clearing (struct seq_buf *buffer,const struct kernel_param *kp) {switch (ec_event_clearing) {case ACPI_EC_EVT_TIMING_STATUS : -return sprintf (buffer,"status\n" ); +seq_buf_printf (buffer,"status\n" ); +return 0 ;case ACPI_EC_EVT_TIMING_QUERY : -return sprintf (buffer,"query\n" ); +seq_buf_printf (buffer,"query\n" ); +return 0 ;case ACPI_EC_EVT_TIMING_EVENT : -return sprintf (buffer,"event\n" ); +seq_buf_printf (buffer,"event\n" ); +return 0 ;default : -return sprintf (buffer,"invalid\n" ); +seq_buf_printf (buffer,"invalid\n" ); +return 0 ; }return 0 ; }drivers/acpi/sysfs.c +4
-2@@ -192,9 +192,11 @@ static int param_set_trace_method_name(const char *val,return 0 ; } -static int param_get_trace_method_name (char *buffer,const struct kernel_param *kp) +static int param_get_trace_method_name (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sysfs_emit (buffer,"%s\n" , acpi_gbl_trace_method_name); +seq_buf_printf (buffer,"%s\n" , acpi_gbl_trace_method_name); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(param_ops_trace_method,drivers/block/ublk_drv.c +3
-2@@ -5868,10 +5868,11 @@ static int ublk_set_max_unprivileged_ublks(const char *buf,return param_set_uint_minmax (buf, kp,0 ,UBLK_MAX_UBLKS ); } -static int ublk_get_max_unprivileged_ublks (char *buf, +static int ublk_get_max_unprivileged_ublks (struct seq_buf *buf,const struct kernel_param *kp) { -return sysfs_emit (buf,"%u\n" , unprivileged_ublks_max); +seq_buf_printf (buf,"%u\n" , unprivileged_ublks_max); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(ublk_max_unprivileged_ublks_ops,drivers/char/ipmi/ipmi_msghandler.c +4
-2@@ -90,7 +90,8 @@ static int panic_op_write_handler(const char *val,return 0 ; } -static int panic_op_read_handler (char *buffer,const struct kernel_param *kp) +static int panic_op_read_handler (struct seq_buf *buffer, +const struct kernel_param *kp) {const char *event_str;@@ -99,7 +100,8 @@ static int panic_op_read_handler(char *buffer, const struct kernel_param *kp)else event_str = ipmi_panic_event_str[ipmi_send_panic_event]; -return sprintf (buffer,"%s\n" , event_str); +seq_buf_printf (buffer,"%s\n" , event_str); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(panic_op_ops, panic_op_write_handler,drivers/firmware/qcom/qcom_scm.c +8
-4@@ -2694,12 +2694,16 @@ static irqreturn_t qcom_scm_irq_handler(int irq, void *data)return IRQ_HANDLED ; } -static int get_download_mode (char *buffer,const struct kernel_param *kp) +static int get_download_mode (struct seq_buf *buffer, +const struct kernel_param *kp) { -if (download_mode >=ARRAY_SIZE (download_mode_name)) -return sysfs_emit (buffer,"unknown mode\n" ); +if (download_mode >=ARRAY_SIZE (download_mode_name)) { +seq_buf_printf (buffer,"unknown mode\n" ); +return 0 ; + } -return sysfs_emit (buffer,"%s\n" , download_mode_name[download_mode]); +seq_buf_printf (buffer,"%s\n" , download_mode_name[download_mode]); +return 0 ; }static int set_download_mode (const char *val,const struct kernel_param *kp)drivers/gpu/drm/drm_panic.c +4
-3@@ -841,10 +841,11 @@ static int drm_panic_type_set(const char *val, const struct kernel_param *kp)return -EINVAL ; } -static int drm_panic_type_get (char *buffer,const struct kernel_param *kp) +static int drm_panic_type_get (struct seq_buf *buffer, +const struct kernel_param *kp) { -return scnprintf (buffer,PAGE_SIZE ,"%s\n" , - drm_panic_type_map[drm_panic_type]); +seq_buf_printf (buffer,"%s\n" , drm_panic_type_map[drm_panic_type]); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(drm_panic_ops, drm_panic_type_set,drivers/infiniband/hw/hfi1/driver.c +4
-3@@ -41,7 +41,7 @@ MODULE_PARM_DESC(cu, "Credit return units");unsigned long hfi1_cap_mask =HFI1_CAP_MASK_DEFAULT ;static int hfi1_caps_set (const char *val,const struct kernel_param *kp); -static int hfi1_caps_get (char *buffer,const struct kernel_param *kp); +static int hfi1_caps_get (struct seq_buf *buffer,const struct kernel_param *kp); static DEFINE_KERNEL_PARAM_OPS(cap_ops, hfi1_caps_set, hfi1_caps_get);module_param_cb (cap_mask, &cap_ops, &hfi1_cap_mask,S_IWUSR |S_IRUGO );MODULE_PARM_DESC (cap_mask,"Bit mask of enabled/disabled HW features" );@@ -101,14 +101,15 @@ static int hfi1_caps_set(const char *val, const struct kernel_param *kp)return ret; } -static int hfi1_caps_get (char *buffer,const struct kernel_param *kp) +static int hfi1_caps_get (struct seq_buf *buffer,const struct kernel_param *kp) {unsigned long cap_mask = *(unsigned long *)kp->arg; cap_mask &= ~HFI1_CAP_LOCKED_SMASK ; cap_mask |= ((cap_mask &HFI1_CAP_K2U ) <<HFI1_CAP_USER_SHIFT ); -return sysfs_emit (buffer,"0x%lx\n" , cap_mask); +seq_buf_printf (buffer,"0x%lx\n" , cap_mask); +return 0 ; }struct pci_dev *get_pci_dev (struct rvt_dev_info *rdi)drivers/infiniband/ulp/srpt/ib_srpt.c +3
-2@@ -86,9 +86,10 @@ static int srpt_set_u64_x(const char *buffer, const struct kernel_param *kp) {return kstrtou64 (buffer,16 , (u64 *)kp->arg); } -static int srpt_get_u64_x (char *buffer,const struct kernel_param *kp) +static int srpt_get_u64_x (struct seq_buf *buffer,const struct kernel_param *kp) { -return sprintf (buffer,"0x%016llx\n" , *(u64 *)kp->arg); +seq_buf_printf (buffer,"0x%016llx\n" , *(u64 *)kp->arg); +return 0 ; }module_param_call (srpt_service_guid, srpt_set_u64_x, srpt_get_u64_x, &srpt_service_guid,0444 );drivers/input/misc/ati_remote2.c +6
-4@@ -63,12 +63,13 @@ static int ati_remote2_set_channel_mask(const char *val,return ati_remote2_set_mask (val, kp,ATI_REMOTE2_MAX_CHANNEL_MASK ); } -static int ati_remote2_get_channel_mask (char *buffer, +static int ati_remote2_get_channel_mask (struct seq_buf *buffer,const struct kernel_param *kp) {pr_debug ("%s()\n" , __func__); -return sprintf (buffer,"0x%04x\n" , *(unsigned int *)kp->arg); +seq_buf_printf (buffer,"0x%04x\n" , *(unsigned int *)kp->arg); +return 0 ; } static int ati_remote2_set_mode_mask(const char *val,@@ -79,12 +80,13 @@ static int ati_remote2_set_mode_mask(const char *val,return ati_remote2_set_mask (val, kp,ATI_REMOTE2_MAX_MODE_MASK ); } -static int ati_remote2_get_mode_mask (char *buffer, +static int ati_remote2_get_mode_mask (struct seq_buf *buffer,const struct kernel_param *kp) {pr_debug ("%s()\n" , __func__); -return sprintf (buffer,"0x%02x\n" , *(unsigned int *)kp->arg); +seq_buf_printf (buffer,"0x%02x\n" , *(unsigned int *)kp->arg); +return 0 ; }static unsigned int channel_mask =ATI_REMOTE2_MAX_CHANNEL_MASK ;drivers/input/mouse/psmouse-base.c +6
-3@@ -44,7 +44,8 @@ MODULE_LICENSE("GPL");static unsigned int psmouse_max_proto =PSMOUSE_AUTO ;static int psmouse_set_maxproto (const char *val,const struct kernel_param *); -static int psmouse_get_maxproto (char *buffer,const struct kernel_param *kp); +static int psmouse_get_maxproto (struct seq_buf *buffer, +const struct kernel_param *kp); static DEFINE_KERNEL_PARAM_OPS(param_ops_proto_abbrev, psmouse_set_maxproto, psmouse_get_maxproto);#define param_check_proto_abbrev (name, p) __param_check(name, p, unsigned int)@@ -1994,11 +1995,13 @@ static int psmouse_set_maxproto(const char *val, const struct kernel_param *kp)return 0 ; } -static int psmouse_get_maxproto (char *buffer,const struct kernel_param *kp) +static int psmouse_get_maxproto (struct seq_buf *buffer, +const struct kernel_param *kp) {int type = *((unsigned int *)kp->arg); -return sprintf (buffer,"%s\n" ,psmouse_protocol_by_type (type)->name); +seq_buf_printf (buffer,"%s\n" ,psmouse_protocol_by_type (type)->name); +return 0 ; }static int __init psmouse_init (void )drivers/md/md.c +3
-2@@ -10989,9 +10989,10 @@ static __exit void md_exit(void)subsys_initcall (md_init);module_exit (md_exit) -static int get_ro(char *buffer, const struct kernel_param *kp) +static int get_ro(struct seq_buf *buffer, const struct kernel_param *kp) { -return sprintf (buffer,"%d\n" , start_readonly); +seq_buf_printf (buffer,"%d\n" , start_readonly); +return 0 ; }static int set_ro (const char *val,const struct kernel_param *kp) {drivers/media/pci/tw686x/tw686x-core.c +4
-2@@ -69,9 +69,11 @@ static const char *dma_mode_name(unsigned int mode) } } -static int tw686x_dma_mode_get (char *buffer,const struct kernel_param *kp) +static int tw686x_dma_mode_get (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%s" ,dma_mode_name (dma_mode)); +seq_buf_printf (buffer,"%s" ,dma_mode_name (dma_mode)); +return 0 ; }static int tw686x_dma_mode_set (const char *val,const struct kernel_param *kp)drivers/nvme/host/multipath.c +3
-2@@ -85,9 +85,10 @@ static int nvme_set_iopolicy(const char *val, const struct kernel_param *kp)return 0 ; } -static int nvme_get_iopolicy (char *buf,const struct kernel_param *kp) +static int nvme_get_iopolicy (struct seq_buf *buf,const struct kernel_param *kp) { -return sprintf (buf,"%s\n" , nvme_iopolicy_names[iopolicy]); +seq_buf_printf (buf,"%s\n" , nvme_iopolicy_names[iopolicy]); +return 0 ; } module_param_call(iopolicy, nvme_set_iopolicy, nvme_get_iopolicy,drivers/power/supply/test_power.c +28
-19@@ -490,10 +490,12 @@ static int param_set_ac_online(const char *key, const struct kernel_param *kp)return 0 ; } -static int param_get_ac_online (char *buffer,const struct kernel_param *kp) +static int param_get_ac_online (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%s\n" , -map_get_key (map_ac_online, ac_online,"unknown" )); +seq_buf_printf (buffer,"%s\n" , +map_get_key (map_ac_online, ac_online,"unknown" )); +return 0 ; }static int param_set_usb_online (const char *key,const struct kernel_param *kp)@@ -503,10 +505,12 @@ static int param_set_usb_online(const char *key, const struct kernel_param *kp)return 0 ; } -static int param_get_usb_online (char *buffer,const struct kernel_param *kp) +static int param_get_usb_online (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%s\n" , -map_get_key (map_ac_online, usb_online,"unknown" )); +seq_buf_printf (buffer,"%s\n" , +map_get_key (map_ac_online, usb_online,"unknown" )); +return 0 ; } static int param_set_battery_status(const char *key,@@ -517,10 +521,12 @@ static int param_set_battery_status(const char *key,return 0 ; } -static int param_get_battery_status (char *buffer,const struct kernel_param *kp) +static int param_get_battery_status (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%s\n" , -map_get_key (map_ac_online, battery_status,"unknown" )); +seq_buf_printf (buffer,"%s\n" , +map_get_key (map_ac_online, battery_status,"unknown" )); +return 0 ; } static int param_set_battery_health(const char *key,@@ -531,10 +537,12 @@ static int param_set_battery_health(const char *key,return 0 ; } -static int param_get_battery_health (char *buffer,const struct kernel_param *kp) +static int param_get_battery_health (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%s\n" , -map_get_key (map_ac_online, battery_health,"unknown" )); +seq_buf_printf (buffer,"%s\n" , +map_get_key (map_ac_online, battery_health,"unknown" )); +return 0 ; } static int param_set_battery_present(const char *key,@@ -545,11 +553,12 @@ static int param_set_battery_present(const char *key,return 0 ; } -static int param_get_battery_present (char *buffer, +static int param_get_battery_present (struct seq_buf *buffer,const struct kernel_param *kp) { -return sprintf (buffer,"%s\n" , -map_get_key (map_ac_online, battery_present,"unknown" )); +seq_buf_printf (buffer,"%s\n" , +map_get_key (map_ac_online, battery_present,"unknown" )); +return 0 ; } static int param_set_battery_technology(const char *key,@@ -561,12 +570,12 @@ static int param_set_battery_technology(const char *key,return 0 ; } -static int param_get_battery_technology (char *buffer, +static int param_get_battery_technology (struct seq_buf *buffer,const struct kernel_param *kp) { -return sprintf (buffer,"%s\n" , -map_get_key (map_ac_online, battery_technology, -"unknown" )); +seq_buf_printf (buffer,"%s\n" , +map_get_key (map_ac_online, battery_technology,"unknown" )); +return 0 ; } static int param_set_battery_capacity(const char *key,drivers/target/target_core_user.c +7
-5@@ -249,10 +249,11 @@ static int tcmu_set_global_max_data_area(const char *str,return 0 ; } -static int tcmu_get_global_max_data_area (char *buffer, +static int tcmu_get_global_max_data_area (struct seq_buf *buffer,const struct kernel_param *kp) { -return sprintf (buffer,"%d\n" ,TCMU_PAGES_TO_MBS (tcmu_global_max_pages)); +seq_buf_printf (buffer,"%d\n" ,TCMU_PAGES_TO_MBS (tcmu_global_max_pages)); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(tcmu_global_max_data_area_op,@@ -265,11 +266,12 @@ MODULE_PARM_DESC(global_max_data_area_mb,"Max MBs allowed to be allocated to all the tcmu device's " "data areas."); -static int tcmu_get_block_netlink (char *buffer, +static int tcmu_get_block_netlink (struct seq_buf *buffer,const struct kernel_param *kp) { -return sprintf (buffer,"%s\n" , tcmu_netlink_blocked ? -"blocked" :"unblocked" ); +seq_buf_printf (buffer,"%s\n" , + tcmu_netlink_blocked ?"blocked" :"unblocked" ); +return 0 ; } static int tcmu_set_block_netlink(const char *str,drivers/thermal/intel/int340x_thermal/processor_thermal_soc_slider.c +8
-4@@ -77,10 +77,12 @@ static int slider_def_balance_set(const char *arg, const struct kernel_param *kpreturn ret; } -static int slider_def_balance_get (char *buf,const struct kernel_param *kp) +static int slider_def_balance_get (struct seq_buf *buf, +const struct kernel_param *kp) {guard (mutex)(&slider_param_lock); -return sysfs_emit (buf,"%02x\n" , slider_values[SOC_POWER_SLIDER_BALANCE ]); +seq_buf_printf (buf,"%02x\n" , slider_values[SOC_POWER_SLIDER_BALANCE ]); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(slider_def_balance_ops, slider_def_balance_set,@@ -109,10 +111,12 @@ static int slider_def_offset_set(const char *arg, const struct kernel_param *kp)return ret; } -static int slider_def_offset_get (char *buf,const struct kernel_param *kp) +static int slider_def_offset_get (struct seq_buf *buf, +const struct kernel_param *kp) {guard (mutex)(&slider_param_lock); -return sysfs_emit (buf,"%02x\n" , slider_offset); +seq_buf_printf (buf,"%02x\n" , slider_offset); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(slider_offset_ops, slider_def_offset_set,drivers/ufs/core/ufs-fault-injection.c +4
-3@@ -8,7 +8,7 @@#include <ufs/ufshcd.h> #include "ufs-fault-injection.h" -static int ufs_fault_get (char *buffer,const struct kernel_param *kp); +static int ufs_fault_get (struct seq_buf *buffer,const struct kernel_param *kp);static int ufs_fault_set (const char *val,const struct kernel_param *kp); static DEFINE_KERNEL_PARAM_OPS(ufs_fault_ops, ufs_fault_set, ufs_fault_get);@@ -31,11 +31,12 @@ MODULE_PARM_DESC(timeout, "Fault injection. timeout=<interval>,<probability>,<space>,<times>");static DECLARE_FAULT_ATTR (ufs_timeout_attr); -static int ufs_fault_get (char *buffer,const struct kernel_param *kp) +static int ufs_fault_get (struct seq_buf *buffer,const struct kernel_param *kp) {const char *fault_str = kp->arg; -return sysfs_emit (buffer,"%s\n" , fault_str); +seq_buf_printf (buffer,"%s\n" , fault_str); +return 0 ; }static int ufs_fault_set (const char *val,const struct kernel_param *kp)drivers/vhost/scsi.c +3
-2@@ -81,10 +81,11 @@ static int vhost_scsi_set_inline_sg_cnt(const char *buf, }#endif -static int vhost_scsi_get_inline_sg_cnt (char *buf, +static int vhost_scsi_get_inline_sg_cnt (struct seq_buf *buf,const struct kernel_param *kp) { -return sprintf (buf,"%u\n" , vhost_scsi_inline_sg_cnt); +seq_buf_printf (buf,"%u\n" , vhost_scsi_inline_sg_cnt); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(vhost_scsi_inline_sg_cnt_op,fs/nfs/namespace.c +4
-2@@ -358,7 +358,8 @@ static int param_set_nfs_timeout(const char *val, const struct kernel_param *kp)return 0 ; } -static int param_get_nfs_timeout (char *buffer,const struct kernel_param *kp) +static int param_get_nfs_timeout (struct seq_buf *buffer, +const struct kernel_param *kp) {long num = *((int *)kp->arg);@@ -369,7 +370,8 @@ static int param_get_nfs_timeout(char *buffer, const struct kernel_param *kp) num = (num + (HZ -1 )) /HZ ; }else num =-1 ; -return sysfs_emit (buffer,"%li\n" , num); +seq_buf_printf (buffer,"%li\n" , num); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(param_ops_nfs_timeout, param_set_nfs_timeout,fs/ocfs2/dlmfs/dlmfs.c +3
-2@@ -78,10 +78,11 @@ static int param_set_dlmfs_capabilities(const char *val,printk (KERN_ERR "%s: readonly parameter\n" , kp->name);return -EINVAL ; } -static int param_get_dlmfs_capabilities (char *buffer, +static int param_get_dlmfs_capabilities (struct seq_buf *buffer,const struct kernel_param *kp) { -return sysfs_emit (buffer,DLMFS_CAPABILITIES ); +seq_buf_printf (buffer,DLMFS_CAPABILITIES ); +return 0 ; }module_param_call (capabilities, param_set_dlmfs_capabilities, param_get_dlmfs_capabilities,NULL ,0444 );fs/overlayfs/copy_up.c +3
-2@@ -28,9 +28,10 @@ static int ovl_ccup_set(const char *buf, const struct kernel_param *param)return 0 ; } -static int ovl_ccup_get (char *buf,const struct kernel_param *param) +static int ovl_ccup_get (struct seq_buf *buf,const struct kernel_param *param) { -return sprintf (buf,"N\n" ); +seq_buf_printf (buf,"N\n" ); +return 0 ; }module_param_call (check_copy_up, ovl_ccup_set, ovl_ccup_get,NULL ,0644 );kernel/locking/locktorture.c +4
-2@@ -86,11 +86,13 @@ static int param_set_cpumask(const char *val, const struct kernel_param *kp) }// Output a cpumask kernel parameter. -static int param_get_cpumask (char *buffer,const struct kernel_param *kp) +static int param_get_cpumask (struct seq_buf *buffer, +const struct kernel_param *kp) {cpumask_var_t *cm_bind = kp->arg; -return sprintf (buffer,"%*pbl" ,cpumask_pr_args (*cm_bind)); +seq_buf_printf (buffer,"%*pbl" ,cpumask_pr_args (*cm_bind)); +return 0 ; }static bool cpumask_nonempty (cpumask_var_t mask)kernel/rcu/tree.c +4
-2@@ -3970,9 +3970,11 @@ static int param_set_do_rcu_barrier(const char *val, const struct kernel_param */* * Output the number of outstanding rcutree.do_rcu_barrier requests. */ -static int param_get_do_rcu_barrier (char *buffer,const struct kernel_param *kp) +static int param_get_do_rcu_barrier (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%d\n" ,atomic_read ((atomic_t *)kp->arg)); +seq_buf_printf (buffer,"%d\n" ,atomic_read ((atomic_t *)kp->arg)); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(do_rcu_barrier_ops, param_set_do_rcu_barrier,kernel/workqueue.c +4
-2@@ -7157,9 +7157,11 @@ static int wq_affn_dfl_set(const char *val, const struct kernel_param *kp)return 0 ; } -static int wq_affn_dfl_get (char *buffer,const struct kernel_param *kp) +static int wq_affn_dfl_get (struct seq_buf *buffer, +const struct kernel_param *kp) { -return scnprintf (buffer,PAGE_SIZE ,"%s\n" , wq_affn_names[wq_affn_dfl]); +seq_buf_printf (buffer,"%s\n" , wq_affn_names[wq_affn_dfl]); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(wq_affn_dfl_ops, wq_affn_dfl_set,lib/test_dynamic_debug.c +4
-2@@ -18,10 +18,12 @@ static int param_set_do_prints(const char *instr, const struct kernel_param *kp)do_prints ();return 0 ; } -static int param_get_do_prints (char *buffer,const struct kernel_param *kp) +static int param_get_do_prints (struct seq_buf *buffer, +const struct kernel_param *kp) {do_prints (); -return scnprintf (buffer,PAGE_SIZE ,"did do_prints\n" ); +seq_buf_printf (buffer,"did do_prints\n" ); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(param_ops_do_prints, param_set_do_prints, param_get_do_prints);mm/damon/lru_sort.c +8
-6@@ -438,10 +438,11 @@ static int damon_lru_sort_enabled_store(const char *val,return damon_lru_sort_turn (enabled); } -static int damon_lru_sort_enabled_load (char *buffer, -const struct kernel_param *kp) +static int damon_lru_sort_enabled_load (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%c\n" ,damon_lru_sort_enabled () ?'Y' :'N' ); +seq_buf_printf (buffer,"%c\n" ,damon_lru_sort_enabled () ?'Y' :'N' ); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, damon_lru_sort_enabled_store,@@ -461,8 +462,8 @@ static int damon_lru_sort_kdamond_pid_store(const char *val,return 0 ; } -static int damon_lru_sort_kdamond_pid_load (char *buffer, -const struct kernel_param *kp) +static int damon_lru_sort_kdamond_pid_load (struct seq_buf *buffer, +const struct kernel_param *kp) {int kdamond_pid =-1 ;@@ -471,7 +472,8 @@ static int damon_lru_sort_kdamond_pid_load(char *buffer,if (kdamond_pid <0 ) kdamond_pid =-1 ; } -return sprintf (buffer,"%d\n" , kdamond_pid); +seq_buf_printf (buffer,"%d\n" , kdamond_pid); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(kdamond_pid_param_ops,mm/damon/reclaim.c +8
-6@@ -340,10 +340,11 @@ static int damon_reclaim_enabled_store(const char *val,return damon_reclaim_turn (enabled); } -static int damon_reclaim_enabled_load (char *buffer, -const struct kernel_param *kp) +static int damon_reclaim_enabled_load (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%c\n" ,damon_reclaim_enabled () ?'Y' :'N' ); +seq_buf_printf (buffer,"%c\n" ,damon_reclaim_enabled () ?'Y' :'N' ); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, damon_reclaim_enabled_store,@@ -363,8 +364,8 @@ static int damon_reclaim_kdamond_pid_store(const char *val,return 0 ; } -static int damon_reclaim_kdamond_pid_load (char *buffer, -const struct kernel_param *kp) +static int damon_reclaim_kdamond_pid_load (struct seq_buf *buffer, +const struct kernel_param *kp) {int kdamond_pid =-1 ;@@ -373,7 +374,8 @@ static int damon_reclaim_kdamond_pid_load(char *buffer,if (kdamond_pid <0 ) kdamond_pid =-1 ; } -return sprintf (buffer,"%d\n" , kdamond_pid); +seq_buf_printf (buffer,"%d\n" , kdamond_pid); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(kdamond_pid_param_ops,mm/damon/stat.c +6
-4@@ -19,8 +19,8 @@static int damon_stat_enabled_store (const char *val,const struct kernel_param *kp); -static int damon_stat_enabled_load (char *buffer, -const struct kernel_param *kp); +static int damon_stat_enabled_load (struct seq_buf *buffer, +const struct kernel_param *kp); static DEFINE_KERNEL_PARAM_OPS(enabled_param_ops, damon_stat_enabled_store, damon_stat_enabled_load);@@ -306,9 +306,11 @@ static int damon_stat_enabled_store(return 0 ; } -static int damon_stat_enabled_load (char *buffer,const struct kernel_param *kp) +static int damon_stat_enabled_load (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%c\n" ,damon_stat_enabled () ?'Y' :'N' ); +seq_buf_printf (buffer,"%c\n" ,damon_stat_enabled () ?'Y' :'N' ); +return 0 ; }static int __init damon_stat_init (void )mm/memory_hotplug.c +12
-6@@ -100,13 +100,17 @@ static int set_memmap_mode(const char *val, const struct kernel_param *kp)return 0 ; } -static int get_memmap_mode (char *buffer,const struct kernel_param *kp) +static int get_memmap_mode (struct seq_buf *buffer, +const struct kernel_param *kp) {int mode = *((int *)kp->arg); -if (mode ==MEMMAP_ON_MEMORY_FORCE ) -return sprintf (buffer,"force\n" ); -return sprintf (buffer,"%c\n" , mode ?'Y' :'N' ); +if (mode ==MEMMAP_ON_MEMORY_FORCE ) { +seq_buf_printf (buffer,"force\n" ); +return 0 ; + } +seq_buf_printf (buffer,"%c\n" , mode ?'Y' :'N' ); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(memmap_mode_ops, set_memmap_mode,@@ -147,9 +151,11 @@ static int set_online_policy(const char *val, const struct kernel_param *kp)return 0 ; } -static int get_online_policy (char *buffer,const struct kernel_param *kp) +static int get_online_policy (struct seq_buf *buffer, +const struct kernel_param *kp) { -return sprintf (buffer,"%s\n" , online_policy_to_str[*((int *)kp->arg)]); +seq_buf_printf (buffer,"%s\n" , online_policy_to_str[*((int *)kp->arg)]); +return 0 ; }/* net/ceph/ceph_common.c +3
-2@@ -47,10 +47,11 @@ bool libceph_compatible(void *data) }EXPORT_SYMBOL (libceph_compatible); -static int param_get_supported_features (char *buffer, +static int param_get_supported_features (struct seq_buf *buffer,const struct kernel_param *kp) { -return sprintf (buffer,"0x%llx" ,CEPH_FEATURES_SUPPORTED_DEFAULT ); +seq_buf_printf (buffer,"0x%llx" ,CEPH_FEATURES_SUPPORTED_DEFAULT ); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(param_ops_supported_features, NULL, param_get_supported_features);net/sunrpc/auth.c +4
-2@@ -73,12 +73,14 @@ static int param_set_hashtbl_sz(const char *val, const struct kernel_param *kp)return -EINVAL ; } -static int param_get_hashtbl_sz (char *buffer,const struct kernel_param *kp) +static int param_get_hashtbl_sz (struct seq_buf *buffer, +const struct kernel_param *kp) {unsigned int nbits; nbits = *(unsigned int *)kp->arg; -return sprintf (buffer,"%u\n" ,1U << nbits); +seq_buf_printf (buffer,"%u\n" ,1U << nbits); +return 0 ; }#define param_check_hashtbl_sz (name, p) __param_check(name, p, unsigned int);net/sunrpc/svc.c +3
-2@@ -148,7 +148,7 @@ sunrpc_get_pool_mode(char *buf, size_t size)EXPORT_SYMBOL (sunrpc_get_pool_mode);static int -param_get_pool_mode (char *buf,const struct kernel_param *kp) +param_get_pool_mode (struct seq_buf *buf,const struct kernel_param *kp) {char str[16 ];int len;@@ -162,7 +162,8 @@ param_get_pool_mode(char *buf, const struct kernel_param *kp) str[len] ='\n' ; str[len +1 ] ='\0' ; -return sysfs_emit (buf,"%s" , str); +seq_buf_printf (buf,"%s" , str); +return 0 ; } module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode,security/apparmor/lsm.c +10
-7@@ -1797,10 +1797,11 @@ static int param_set_debug(const char *val, const struct kernel_param *kp);static int param_get_debug (struct seq_buf *buffer,const struct kernel_param *kp);static int param_set_audit (const char *val,const struct kernel_param *kp); -static int param_get_audit (char *buffer,const struct kernel_param *kp); +static int param_get_audit (struct seq_buf *buffer, +const struct kernel_param *kp);static int param_set_mode (const char *val,const struct kernel_param *kp); -static int param_get_mode (char *buffer,const struct kernel_param *kp); +static int param_get_mode (struct seq_buf *buffer,const struct kernel_param *kp);/* Flag values, also controllable via /sys/module/apparmor/parameters * We define special types as we want to do additional mediation. @@ -2050,13 +2051,15 @@ static int param_set_debug(const char *val, const struct kernel_param *kp)return 0 ; } -static int param_get_audit (char *buffer,const struct kernel_param *kp) +static int param_get_audit (struct seq_buf *buffer, +const struct kernel_param *kp) {if (!apparmor_enabled)return -EINVAL ;if (apparmor_initialized && !aa_current_policy_view_capable (NULL ))return -EPERM ; -return sysfs_emit (buffer,"%s\n" , audit_mode_names[aa_g_audit]); +seq_buf_printf (buffer,"%s\n" , audit_mode_names[aa_g_audit]); +return 0 ; }static int param_set_audit (const char *val,const struct kernel_param *kp)@@ -2078,13 +2081,14 @@ static int param_set_audit(const char *val, const struct kernel_param *kp)return 0 ; } -static int param_get_mode (char *buffer,const struct kernel_param *kp) +static int param_get_mode (struct seq_buf *buffer,const struct kernel_param *kp) {if (!apparmor_enabled)return -EINVAL ;if (apparmor_initialized && !aa_current_policy_view_capable (NULL ))return -EPERM ; -return sysfs_emit (buffer,"%s\n" , aa_profile_mode_names[aa_g_profile_mode]); +seq_buf_printf (buffer,"%s\n" , aa_profile_mode_names[aa_g_profile_mode]); +return 0 ; }static int param_set_mode (const char *val,const struct kernel_param *kp) --2.34.1
Re: [PATCH 09/11] treewide: Convert custom kernel_param_ops .get callbacks to seq_buf via cocci
In reply to Kees CookQuoted 40 lines · On Thu, 21 May 2026 06:33:22 -0700 Kees Cook <[email protected]> wrote:
Using the following Coccinelle script, convert struct
kernel_param_ops.get callbacks from "char *" to "structseq_buf*" when the only write to the buffer is via a final call ofscnprintf(),snprintf(),sprintf(), orsysfs_emit().Since
seq_buf_printf()will return -1 on overflow, and structkernel_param_ops.get callbacks are expected to truncate without error, we must ignore the return value fromseq_buf_print()and always return 0 (as the length is calculated in the common dispatcher code).@@
identifier FN, BUF, KP;
expression FMT;
expression list ARGS;
@@
int FN((quoted diff) +1
-1- char *BUF + struct seq_buf *BUF , const struct kernel_param *KP) { ... when any(
- returnscnprintf(BUF, PAGE_SIZE, FMT, ARGS);
|
- returnsnprintf(BUF, PAGE_SIZE, FMT, ARGS);
|
- returnsprintf(BUF, FMT, ARGS);
|
- returnsysfs_emit(BUF, FMT, ARGS);
)arch/s390/kernel/perf_cpum_sf.c +2
-0+seq_buf_printf (BUF ,FMT ,ARGS ); +return 0 ; }No struct
kernel_param_opsinitializations need changing sinceDEFINE_KERNEL_PARAM_OPSalready routes the pointer to .get or .get_str via_Genericbased on the function signature, so converted callbacks are automatically moved from the .get_str to the .get callback.Signed-off-by Kees Cook <[email protected]>
[...]
Quoted 3 lines
mm/damon/lru_sort.c | 14 +++--- mm/damon/reclaim.c | 14 +++--- mm/damon/stat.c | 10 ++--
For the above DAMON changes,
Thanks,
SJ
[...]
Kees Cook
maintainerPATCH 10/11 treewide: Manually convert custom kernel_param_ops .get callbacks
In reply to Kees CookConvert struct kernel_param_ops .get callbacks from legacy "char *" to "struct seq_buf *".
Since seq_buf_printf() will return -1 on overflow, and struct kernel_param_ops .get callbacks are expected to truncate without error, we must ignore the return value from seq_buf_print() and always return 0 (as the length is calculated in the common dispatcher code).
No struct kernel_param_ops initializations need changing since DEFINE_KERNEL_PARAM_OPS already routes the pointer to .get or .get_str via _Generic based on the function signature, so converted callbacks are automatically moved from the .get_str to the .get callback.
--- include/linux/dynamic_debug.h | 8 ++- arch/um/drivers/vfio_kern.c | 3 +- arch/um/drivers/virtio_uml.c | 12 ++-- drivers/acpi/button.c | 19 ++++-- drivers/acpi/sysfs.c | 83 +++++++++++------------- drivers/char/ipmi/ipmi_watchdog.c | 33 ++++------ drivers/firmware/qemu_fw_cfg.c | 34 +++++----- drivers/gpu/drm/i915/i915_mitigations.c | 26 ++++---- drivers/infiniband/ulp/srp/ib_srp.c | 7 +- drivers/media/usb/uvc/uvc_driver.c | 8 ++- drivers/pci/pcie/aspm.c | 17 +++-- drivers/scsi/fcoe/fcoe_transport.c | 22 +++---- drivers/thermal/intel/intel_powerclamp.c | 14 ++-- drivers/tty/hvc/hvc_iucv.c | 18 ++--- drivers/usb/storage/usb.c | 20 +++--- drivers/virtio/virtio_mmio.c | 21 +++--- lib/dynamic_debug.c | 10 ++- 17 files changed, 178 insertions(+), 177 deletions(-)
include/linux/dynamic_debug.h +6 -2
@@ -334,8 +334,10 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,extern int ddebug_dyndbg_module_param_cb (char *param,char *val,const char *modname);struct kernel_param ; +struct seq_buf ;int param_set_dyndbg_classes (const char *instr,const struct kernel_param *kp); -int param_get_dyndbg_classes (char *buffer,const struct kernel_param *kp); +int param_get_dyndbg_classes (struct seq_buf *buffer, +const struct kernel_param *kp);#else
@@ -352,9 +354,11 @@ static inline int ddebug_dyndbg_module_param_cb(char *param, char *val, }struct kernel_param ; +struct seq_buf ;static inline int param_set_dyndbg_classes (const char *instr,const struct kernel_param *kp) {return 0 ; } -static inline int param_get_dyndbg_classes (char *buffer,const struct kernel_param *kp) +static inline int param_get_dyndbg_classes (struct seq_buf *buffer, +const struct kernel_param *kp) {return 0 ; }#endif
arch/um/drivers/vfio_kern.c +2 -1
@@ -623,7 +623,8 @@ static int uml_vfio_cmdline_set(const char *device, const struct kernel_param *kreturn 0 ; } -static int uml_vfio_cmdline_get (char *buffer,const struct kernel_param *kp) +static int uml_vfio_cmdline_get (struct seq_buf *buffer, +const struct kernel_param *kp) {return 0 ; }
arch/um/drivers/virtio_uml.c +5 -7
@@ -1379,23 +1379,21 @@ static int vu_cmdline_get_device(struct device *dev, void *data) {struct platform_device *pdev =to_platform_device (dev);struct virtio_uml_platform_data *pdata = pdev->dev.platform_data; -char *buffer = data; -unsigned int len =strlen (buffer); +struct seq_buf *s = data; -snprintf (buffer + len,PAGE_SIZE - len,"%s:%d:%d\n" , - pdata->socket_path, pdata->virtio_device_id, pdev->id); +seq_buf_printf (s,"%s:%d:%d\n" , + pdata->socket_path, pdata->virtio_device_id, pdev->id);return 0 ; } -static int vu_cmdline_get (char *buffer,const struct kernel_param *kp) +static int vu_cmdline_get (struct seq_buf *buffer,const struct kernel_param *kp) {guard (mutex)(&vu_cmdline_lock); - buffer[0 ] ='\0' ;if (vu_cmdline_parent_registered)device_for_each_child (&vu_cmdline_parent, buffer, vu_cmdline_get_device); -return strlen (buffer) +1 ; +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(vu_cmdline_param_ops, vu_cmdline_set,
drivers/acpi/button.c +12 -7
@@ -715,19 +715,24 @@ static int param_set_lid_init_state(const char *val,return 0 ; } -static int param_get_lid_init_state (char *buf,const struct kernel_param *kp) +static int param_get_lid_init_state (struct seq_buf *buf, +const struct kernel_param *kp) { -int i, c =0 ; +int i; -for (i =0 ; i <ARRAY_SIZE (lid_init_state_str); i++) +for (i =0 ; i <ARRAY_SIZE (lid_init_state_str); i++) {if (i == lid_init_state) - c +=sprintf (buf + c,"[%s] " , lid_init_state_str[i]); +seq_buf_printf (buf,"[%s] " , lid_init_state_str[i]);else - c +=sprintf (buf + c,"%s " , lid_init_state_str[i]); +seq_buf_printf (buf,"%s " , lid_init_state_str[i]); + } - buf[c -1 ] ='\n' ;/* Replace the final space with a newline */ +/* Replace the final space with a newline. */ +if (!seq_buf_has_overflowed (buf) && buf->len >0 && + buf->buffer[buf->len -1 ] ==' ' ) + buf->buffer[buf->len -1 ] ='\n' ; -return c; +return 0 ; } module_param_call(lid_init_state,
drivers/acpi/sysfs.c +39 -44
122 lines not on this page · raw message
drivers/char/ipmi/ipmi_watchdog.c +12 -21
@@ -197,11 +197,11 @@ static DEFINE_KERNEL_PARAM_OPS(param_ops_timeout, set_param_timeout, param_get_int);#define param_check_timeout param_check_int -typedef int (*action_fn )(const char *intval,char *outval); +typedef int (*action_fn )(const char *intval,struct seq_buf *outval); -static int action_op (const char *inval,char *outval); -static int preaction_op (const char *inval,char *outval); -static int preop_op (const char *inval,char *outval); +static int action_op (const char *inval,struct seq_buf *outval); +static int preaction_op (const char *inval,struct seq_buf *outval); +static int preop_op (const char *inval,struct seq_buf *outval);static void check_parms (void );static int set_param_str (const char *val,const struct kernel_param *kp)
@@ -227,20 +227,11 @@ static int set_param_str(const char *val, const struct kernel_param *kp)return rv; } -static int get_param_str (char *buffer,const struct kernel_param *kp) +static int get_param_str (struct seq_buf *buffer,const struct kernel_param *kp) {action_fn fn = (action_fn ) kp->arg; -int rv, len; - rv =fn (NULL , buffer); -if (rv) -return rv; - - len =strlen (buffer); - buffer[len++] ='\n' ; - buffer[len] =0 ; - -return len; +return fn (NULL , buffer); }
@@ -1154,12 +1145,12 @@ static int action_op_set_val(const char *inval)return 0 ; } -static int action_op (const char *inval,char *outval) +static int action_op (const char *inval,struct seq_buf *outval) {int rv;if (outval) -strcpy (outval, action); +seq_buf_printf (outval,"%s\n" , action);if (!inval)return 0 ;
@@ -1186,12 +1177,12 @@ static int preaction_op_set_val(const char *inval)return 0 ; } -static int preaction_op (const char *inval,char *outval) +static int preaction_op (const char *inval,struct seq_buf *outval) {int rv;if (outval) -strcpy (outval, preaction); +seq_buf_printf (outval,"%s\n" , preaction);if (!inval)return 0 ;
@@ -1214,12 +1205,12 @@ static int preop_op_set_val(const char *inval)return 0 ; } -static int preop_op (const char *inval,char *outval) +static int preop_op (const char *inval,struct seq_buf *outval) {int rv;if (outval) -strcpy (outval, preop); +seq_buf_printf (outval,"%s\n" , preop);if (!inval)return 0 ;
drivers/firmware/qemu_fw_cfg.c +19 -15
@@ -860,7 +860,8 @@ static int fw_cfg_cmdline_set(const char *arg, const struct kernel_param *kp)return PTR_ERR_OR_ZERO (fw_cfg_cmdline_dev); } -static int fw_cfg_cmdline_get (char *buf,const struct kernel_param *kp) +static int fw_cfg_cmdline_get (struct seq_buf *buf, +const struct kernel_param *kp) {/* stay silent if device was not configured via the command * line, or if the parameter name (ioport/mmio) doesn't match
@@ -873,22 +874,25 @@ static int fw_cfg_cmdline_get(char *buf, const struct kernel_param *kp)switch (fw_cfg_cmdline_dev->num_resources) {case 1 : -return snprintf (buf,PAGE_SIZE ,PH_ADDR_PR_1_FMT , -resource_size (&fw_cfg_cmdline_dev->resource[0 ]), - fw_cfg_cmdline_dev->resource[0 ].start); +seq_buf_printf (buf,PH_ADDR_PR_1_FMT , +resource_size (&fw_cfg_cmdline_dev->resource[0 ]), + fw_cfg_cmdline_dev->resource[0 ].start); +return 0 ;case 3 : -return snprintf (buf,PAGE_SIZE ,PH_ADDR_PR_3_FMT , -resource_size (&fw_cfg_cmdline_dev->resource[0 ]), - fw_cfg_cmdline_dev->resource[0 ].start, - fw_cfg_cmdline_dev->resource[1 ].start, - fw_cfg_cmdline_dev->resource[2 ].start); +seq_buf_printf (buf,PH_ADDR_PR_3_FMT , +resource_size (&fw_cfg_cmdline_dev->resource[0 ]), + fw_cfg_cmdline_dev->resource[0 ].start, + fw_cfg_cmdline_dev->resource[1 ].start, + fw_cfg_cmdline_dev->resource[2 ].start); +return 0 ;case 4 : -return snprintf (buf,PAGE_SIZE ,PH_ADDR_PR_4_FMT , -resource_size (&fw_cfg_cmdline_dev->resource[0 ]), - fw_cfg_cmdline_dev->resource[0 ].start, - fw_cfg_cmdline_dev->resource[1 ].start, - fw_cfg_cmdline_dev->resource[2 ].start, - fw_cfg_cmdline_dev->resource[3 ].start); +seq_buf_printf (buf,PH_ADDR_PR_4_FMT , +resource_size (&fw_cfg_cmdline_dev->resource[0 ]), + fw_cfg_cmdline_dev->resource[0 ].start, + fw_cfg_cmdline_dev->resource[1 ].start, + fw_cfg_cmdline_dev->resource[2 ].start, + fw_cfg_cmdline_dev->resource[3 ].start); +return 0 ; }/* Should never get here */
drivers/gpu/drm/i915/i915_mitigations.c +15 -11
@@ -95,33 +95,37 @@ static int mitigations_set(const char *val, const struct kernel_param *kp)return 0 ; } -static int mitigations_get (char *buffer,const struct kernel_param *kp) +static int mitigations_get (struct seq_buf *buffer, +const struct kernel_param *kp) {unsigned long local =READ_ONCE (mitigations); -int count, i;bool enable; +int i; -if (!local) -return scnprintf (buffer,PAGE_SIZE ,"%s\n" ,"off" ); +if (!local) { +seq_buf_printf (buffer,"%s\n" ,"off" ); +return 0 ; + }if (local &BIT (BITS_PER_LONG -1 )) { - count =scnprintf (buffer,PAGE_SIZE ,"%s," ,"auto" ); +seq_buf_printf (buffer,"%s," ,"auto" ); enable = false; }else { enable = true; - count =0 ; }for (i =0 ; i <ARRAY_SIZE (names); i++) {if ((local &BIT (i)) != enable)continue ; - - count +=scnprintf (buffer + count,PAGE_SIZE - count, -"%s%s," , enable ?"" :"!" , names[i]); +seq_buf_printf (buffer,"%s%s," , enable ?"" :"!" , names[i]); } - buffer[count -1 ] ='\n' ; -return count; +/* Replace the trailing comma with a newline. */ +if (!seq_buf_has_overflowed (buffer) && buffer->len >0 && + buffer->buffer[buffer->len -1 ] ==',' ) + buffer->buffer[buffer->len -1 ] ='\n' ; + +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(ops, mitigations_set, mitigations_get);
drivers/infiniband/ulp/srp/ib_srp.c +4 -3
@@ -161,14 +161,15 @@ static struct ib_client srp_client = {static struct ib_sa_client srp_sa_client; -static int srp_tmo_get (char *buffer,const struct kernel_param *kp) +static int srp_tmo_get (struct seq_buf *buffer,const struct kernel_param *kp) {int tmo = *(int *)kp->arg;if (tmo >=0 ) -return sysfs_emit (buffer,"%d\n" , tmo); +seq_buf_printf (buffer,"%d\n" , tmo);else -return sysfs_emit (buffer,"off\n" ); +seq_buf_printf (buffer,"off\n" ); +return 0 ; }static int srp_tmo_set (const char *val,const struct kernel_param *kp)
drivers/media/usb/uvc/uvc_driver.c +5 -3
@@ -2451,12 +2451,14 @@ static int uvc_reset_resume(struct usb_interface *intf)* Module parameters */ -static int uvc_clock_param_get (char *buffer,const struct kernel_param *kp) +static int uvc_clock_param_get (struct seq_buf *buffer, +const struct kernel_param *kp) {if (uvc_clock_param ==CLOCK_MONOTONIC ) -return sprintf (buffer,"CLOCK_MONOTONIC" ); +seq_buf_printf (buffer,"CLOCK_MONOTONIC" );else -return sprintf (buffer,"CLOCK_REALTIME" ); +seq_buf_printf (buffer,"CLOCK_REALTIME" ); +return 0 ; }static int uvc_clock_param_set (const char *val,const struct kernel_param *kp)
drivers/pci/pcie/aspm.c +10 -7
@@ -1572,16 +1572,19 @@ static int pcie_aspm_set_policy(const char *val,return 0 ; } -static int pcie_aspm_get_policy (char *buffer,const struct kernel_param *kp) +static int pcie_aspm_get_policy (struct seq_buf *buffer, +const struct kernel_param *kp) { -int i, cnt =0 ; -for (i =0 ; i <ARRAY_SIZE (policy_str); i++) +int i; + +for (i =0 ; i <ARRAY_SIZE (policy_str); i++) {if (i == aspm_policy) - cnt +=sprintf (buffer + cnt,"[%s] " , policy_str[i]); +seq_buf_printf (buffer,"[%s] " , policy_str[i]);else - cnt +=sprintf (buffer + cnt,"%s " , policy_str[i]); - cnt +=sprintf (buffer + cnt,"\n" ); -return cnt; +seq_buf_printf (buffer,"%s " , policy_str[i]); + } +seq_buf_putc (buffer,'\n' ); +return 0 ; } module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy,
drivers/scsi/fcoe/fcoe_transport.c +11 -11
@@ -23,7 +23,8 @@ MODULE_LICENSE("GPL v2");static int fcoe_transport_create (const char *,const struct kernel_param *);static int fcoe_transport_destroy (const char *,const struct kernel_param *); -static int fcoe_transport_show (char *buffer,const struct kernel_param *kp); +static int fcoe_transport_show (struct seq_buf *buffer, +const struct kernel_param *kp);static struct fcoe_transport *fcoe_transport_lookup (struct net_device *device);static struct fcoe_transport *fcoe_netdev_map_lookup (struct net_device *device);static int fcoe_transport_enable (const char *,const struct kernel_param *);
@@ -595,22 +596,21 @@ int fcoe_transport_detach(struct fcoe_transport *ft) }EXPORT_SYMBOL (fcoe_transport_detach); -static int fcoe_transport_show (char *buffer,const struct kernel_param *kp) +static int fcoe_transport_show (struct seq_buf *buffer, +const struct kernel_param *kp) { -int i, j;struct fcoe_transport *ft =NULL ; - i = j =sprintf (buffer,"Attached FCoE transports:" ); +seq_buf_printf (buffer,"Attached FCoE transports:" );mutex_lock (&ft_mutex); -list_for_each_entry (ft, &fcoe_transports, list) { -if (i >=PAGE_SIZE -IFNAMSIZ ) -break ; - i +=snprintf (&buffer[i],IFNAMSIZ ,"%s " , ft->name); +if (list_empty (&fcoe_transports)) { +seq_buf_printf (buffer,"none" ); + }else { +list_for_each_entry (ft, &fcoe_transports, list) +seq_buf_printf (buffer,"%s " , ft->name); }mutex_unlock (&ft_mutex); -if (i == j) - i +=snprintf (&buffer[i],IFNAMSIZ ,"none" ); -return i; +return 0 ; }static int __init fcoe_transport_init (void )
drivers/thermal/intel/intel_powerclamp.c +7 -7
@@ -101,15 +101,13 @@ static int duration_set(const char *arg, const struct kernel_param *kp)return ret; } -static int duration_get (char *buf,const struct kernel_param *kp) +static int duration_get (struct seq_buf *buf,const struct kernel_param *kp) { -int ret; -mutex_lock (&powerclamp_lock); - ret =sysfs_emit (buf,"%d\n" , duration /1000 ); +seq_buf_printf (buf,"%d\n" , duration /1000 );mutex_unlock (&powerclamp_lock); -return ret; +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(duration_ops, duration_set, duration_get);
@@ -192,12 +190,14 @@ static int cpumask_set(const char *arg, const struct kernel_param *kp)return ret; } -static int cpumask_get (char *buf,const struct kernel_param *kp) +static int cpumask_get (struct seq_buf *buf,const struct kernel_param *kp) {if (!cpumask_available (idle_injection_cpu_mask))return -ENODEV ; -return cpumap_print_to_pagebuf (false, buf, idle_injection_cpu_mask); +seq_buf_printf (buf,"%*pb\n" , nr_cpu_ids, +cpumask_bits (idle_injection_cpu_mask)); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(cpumask_ops, cpumask_set, cpumask_get);
drivers/tty/hvc/hvc_iucv.c +7 -11
@@ -1256,36 +1256,32 @@ static int param_set_vmidfilter(const char *val, const struct kernel_param *kp)/** * param_get_vmidfilter() - Get z/VM user ID filter -* @buffer: Buffer to store z/VM user ID filter, -* (buffer size assumption PAGE_SIZE) +* @buffer: seq_buf to store z/VM user ID filter * @kp: Kernel parameter pointing to the hvc_iucv_filter array * * The function stores the filter as a comma-separated list of z/VM user IDs * in @buffer. Typically, sysfs routines call this function for attr show. */ -static int param_get_vmidfilter (char *buffer,const struct kernel_param *kp) +static int param_get_vmidfilter (struct seq_buf *buffer, +const struct kernel_param *kp) { -int rc;size_t index, len;void *start, *end;if (!machine_is_vm () || !hvc_iucv_devices)return -ENODEV ; - rc =0 ;read_lock_bh (&hvc_iucv_filter_lock);for (index =0 ; index < hvc_iucv_filter_size; index++) { start = hvc_iucv_filter + (8 * index); end =memchr (start,' ' ,8 ); len = (end) ? end - start :8 ; -memcpy (buffer + rc, start, len); - rc += len; - buffer[rc++] =',' ; +if (index) +seq_buf_putc (buffer,',' ); +seq_buf_printf (buffer,"%.*s" , (int )len, (char *)start); }read_unlock_bh (&hvc_iucv_filter_lock); -if (rc) - buffer[--rc] ='\0' ;/* replace last comma and update rc */ -return rc; +return 0 ; }#define param_check_vmidfilter (name, p) __param_check(name, p, void)
drivers/usb/storage/usb.c +8 -12
@@ -115,27 +115,22 @@ static int parse_delay_str(const char *str, int ndecimals, const char *suffix,* @val: The integer value to format, scaled by 10^(@ndecimals). * @ndecimals: Number of decimal to scale down. * @suffix: Suffix string to format. -* @str: Where to store the formatted string. -* @size: The size of buffer for @str. +* @s: Where to store the formatted string. * * Format an integer value in @val scale down by 10^(@ndecimals) without @suffix * if @val is divisible by 10^(@ndecimals). * Otherwise format a value in @val just as it is with @suffix -* -* Returns the number of characters written into @str. */ -static int format_delay_ms (unsigned int val,int ndecimals,const char *suffix, -char *str,int size) +static void format_delay_ms (unsigned int val,int ndecimals,const char *suffix, +struct seq_buf *s) {u64 delay_ms = val;unsigned int rem =do_div (delay_ms,int_pow (10 , ndecimals)); -int ret;if (rem) - ret =scnprintf (str, size,"%u%s\n" , val, suffix); +seq_buf_printf (s,"%u%s\n" , val, suffix);else - ret =scnprintf (str, size,"%u\n" , (unsigned int )delay_ms); -return ret; +seq_buf_printf (s,"%u\n" , (unsigned int )delay_ms); }static int delay_use_set (const char *s,const struct kernel_param *kp)
@@ -151,11 +146,12 @@ static int delay_use_set(const char *s, const struct kernel_param *kp)return 0 ; } -static int delay_use_get (char *s,const struct kernel_param *kp) +static int delay_use_get (struct seq_buf *s,const struct kernel_param *kp) {unsigned int delay_ms = *((unsigned int *)kp->arg); -return format_delay_ms (delay_ms,3 ,"ms" , s,PAGE_SIZE ); +format_delay_ms (delay_ms,3 ,"ms" , s); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(delay_use_ops, delay_use_set, delay_use_get);
drivers/virtio/virtio_mmio.c +9 -12
@@ -728,24 +728,21 @@ static int vm_cmdline_set(const char *device,static int vm_cmdline_get_device (struct device *dev,void *data) { -char *buffer = data; -unsigned int len =strlen (buffer); +struct seq_buf *s = data;struct platform_device *pdev =to_platform_device (dev); -snprintf (buffer + len,PAGE_SIZE - len,"0x%llx@0x%llx:%llu:%d\n" , - pdev->resource[0 ].end - pdev->resource[0 ].start +1ULL , - (unsigned long long )pdev->resource[0 ].start, - (unsigned long long )pdev->resource[1 ].start, - pdev->id); +seq_buf_printf (s,"0x%llx@0x%llx:%llu:%d\n" , + pdev->resource[0 ].end - pdev->resource[0 ].start +1ULL , + (unsigned long long )pdev->resource[0 ].start, + (unsigned long long )pdev->resource[1 ].start, + pdev->id);return 0 ; } -static int vm_cmdline_get (char *buffer,const struct kernel_param *kp) +static int vm_cmdline_get (struct seq_buf *s,const struct kernel_param *kp) { - buffer[0 ] ='\0' ; -device_for_each_child (&vm_cmdline_parent, buffer, - vm_cmdline_get_device); -return strlen (buffer) +1 ; +device_for_each_child (&vm_cmdline_parent, s, vm_cmdline_get_device); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(vm_cmdline_param_ops, vm_cmdline_set,
lib/dynamic_debug.c +7 -3
@@ -17,6 +17,7 @@#include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kallsyms.h> +#include <linux/seq_buf.h> #include <linux/types.h> #include <linux/mutex.h> #include <linux/proc_fs.h>
@@ -787,7 +788,8 @@ EXPORT_SYMBOL(param_set_dyndbg_classes);* altered by direct >control. Displays 0x for DISJOINT, 0-N for * LEVEL Returns: #chars written or <0 on error */ -int param_get_dyndbg_classes (char *buffer,const struct kernel_param *kp) +int param_get_dyndbg_classes (struct seq_buf *buffer, +const struct kernel_param *kp) {const struct ddebug_class_param *dcp = kp->arg;const struct ddebug_class_map *map = dcp->map;
@@ -796,11 +798,13 @@ int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp)case DD_CLASS_TYPE_DISJOINT_NAMES :case DD_CLASS_TYPE_DISJOINT_BITS : -return scnprintf (buffer,PAGE_SIZE ,"0x%lx\n" , *dcp->bits); +seq_buf_printf (buffer,"0x%lx\n" , *dcp->bits); +return 0 ;case DD_CLASS_TYPE_LEVEL_NAMES :case DD_CLASS_TYPE_LEVEL_NUM : -return scnprintf (buffer,PAGE_SIZE ,"%d\n" , *dcp->lvl); +seq_buf_printf (buffer,"%d\n" , *dcp->lvl); +return 0 ;default :return -1 ; }
Signature · 1 line
2.34.1
Jani Nikula
maintainerRe: [PATCH 10/11] treewide: Manually convert custom kernel_param_ops .get callbacks
Quoted 6 lines · Kees Cook
drivers/gpu/drm/i915/i915_mitigations.c +0
-0@@ -95,33 +95,37 @@ static int mitigations_set(const char *val, const struct kernel_param *kp)return 0 ;
drivers/gpu/drm/i915/i915_mitigations.c static int mitigations_set(const char *val, const struct kernel_param *kp) · line 103
Quoted 10 lines
drivers/gpu/drm/i915/i915_mitigations.c +3
-2} -static int mitigations_get (char *buffer,const struct kernel_param *kp) +static int mitigations_get (struct seq_buf *buffer, +const struct kernel_param *kp) {unsigned long local =READ_ONCE (mitigations); -int count, i;bool enable; +int i;
I'm fine with what you have, and I can do these as a follow-up later if it's too much trouble, but I suggest something like this:
const char *sep = "";
drivers/gpu/drm/i915/i915_mitigations.c static int mitigations_set(const char *val, const struct kernel_param *kp) · line 111
Quoted 11 lines
drivers/gpu/drm/i915/i915_mitigations.c +5
-3-if (!local) -return scnprintf (buffer,PAGE_SIZE ,"%s\n" ,"off" ); +if (!local) { +seq_buf_printf (buffer,"%s\n" ,"off" ); +return 0 ; + }if (local &BIT (BITS_PER_LONG -1 )) { - count =scnprintf (buffer,PAGE_SIZE ,"%s," ,"auto" ); +seq_buf_printf (buffer,"%s," ,"auto" );
seq_buf_printf(buffer, "%s%s", sep, "auto"); sep = ",";
(In the printf the sep is just for future expansion, though I don't expect one.)
drivers/gpu/drm/i915/i915_mitigations.c static int mitigations_set(const char *val, const struct kernel_param *kp) · line 120
Quoted 13 lines
drivers/gpu/drm/i915/i915_mitigations.c +1
-4enable = false; }else { enable = true; - count =0 ; }for (i =0 ; i <ARRAY_SIZE (names); i++) {if ((local &BIT (i)) != enable)continue ; - - count +=scnprintf (buffer + count,PAGE_SIZE - count, -"%s%s," , enable ?"" :"!" , names[i]); +seq_buf_printf (buffer,"%s%s," , enable ?"" :"!" , names[i]);
seq_buf_printf(buffer, "%s%s%s", sep, enable ? "" : "!", names[i]); sep = ",";
drivers/gpu/drm/i915/i915_mitigations.c static int mitigations_set(const char *val, const struct kernel_param *kp) · line 120
Quoted 1 line
drivers/gpu/drm/i915/i915_mitigations.c +0
-0}
seq_buf_puts(buffer, "\n");
drivers/gpu/drm/i915/i915_mitigations.c static int mitigations_set(const char *val, const struct kernel_param *kp) · line 126
Quoted 7 lines
drivers/gpu/drm/i915/i915_mitigations.c +4
-2- buffer[count -1 ] ='\n' ; -return count; +/* Replace the trailing comma with a newline. */ +if (!seq_buf_has_overflowed (buffer) && buffer->len >0 && + buffer->buffer[buffer->len -1 ] ==',' ) + buffer->buffer[buffer->len -1 ] ='\n' ;
Drop the above.
I.e. keep track of sep while printing to avoid removing it later.
BR,
Jani.
Quoted 5 lines
drivers/gpu/drm/i915/i915_mitigations.c +2
-0+ +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(ops, mitigations_set, mitigations_get);
Signature · 1 line
Jani Nikula, Intel
Re: [PATCH 10/11] treewide: Manually convert custom kernel_param_ops .get callbacks
In reply to Kees CookQuoted 9 lines · Kees Cook
Convert struct
kernel_param_ops.get callbacks from legacy "char *" to "structseq_buf*".Since
seq_buf_printf()will return -1 on overflow, and structkernel_param_ops.get callbacks are expected to truncate without error, we must ignore the return value fromseq_buf_print()and always return 0 (as the length is calculated in the common dispatcher code).
Quoted 6 lines
No struct
kernel_param_opsinitializations need changing sinceDEFINE_KERNEL_PARAM_OPSalready routes the pointer to .get or .get_str via_Genericbased on the function signature, so converted callbacks are automatically moved from the .get_str to the .get callback.Signed-off-by Kees Cook <[email protected]>
For ACPI:
Quoted 797 lines
--- include/linux/dynamic_debug.h | 8 ++- arch/um/drivers/vfio_kern.c | 3 +- arch/um/drivers/virtio_uml.c | 12 ++-- drivers/acpi/button.c | 19 ++++-- drivers/acpi/sysfs.c | 83 +++++++++++------------- drivers/char/ipmi/ipmi_watchdog.c | 33 ++++------ drivers/firmware/qemu_fw_cfg.c | 34 +++++----- drivers/gpu/drm/i915/i915_mitigations.c | 26 ++++---- drivers/infiniband/ulp/srp/ib_srp.c | 7 +- drivers/media/usb/uvc/uvc_driver.c | 8 ++- drivers/pci/pcie/aspm.c | 17 +++-- drivers/scsi/fcoe/fcoe_transport.c | 22 +++---- drivers/thermal/intel/intel_powerclamp.c | 14 ++-- drivers/tty/hvc/hvc_iucv.c | 18 ++--- drivers/usb/storage/usb.c | 20 +++--- drivers/virtio/virtio_mmio.c | 21 +++--- lib/dynamic_debug.c | 10 ++- 17 files changed, 178 insertions(+), 177 deletions(-)include/linux/dynamic_debug.h +6
-2@@ -334,8 +334,10 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,extern int ddebug_dyndbg_module_param_cb (char *param,char *val,const char *modname);struct kernel_param ; +struct seq_buf ;int param_set_dyndbg_classes (const char *instr,const struct kernel_param *kp); -int param_get_dyndbg_classes (char *buffer,const struct kernel_param *kp); +int param_get_dyndbg_classes (struct seq_buf *buffer, +const struct kernel_param *kp);#else @@ -352,9 +354,11 @@ static inline int ddebug_dyndbg_module_param_cb(char *param, char *val, }struct kernel_param ; +struct seq_buf ;static inline int param_set_dyndbg_classes (const char *instr,const struct kernel_param *kp) {return 0 ; } -static inline int param_get_dyndbg_classes (char *buffer,const struct kernel_param *kp) +static inline int param_get_dyndbg_classes (struct seq_buf *buffer, +const struct kernel_param *kp) {return 0 ; }#endif arch/um/drivers/vfio_kern.c +2
-1@@ -623,7 +623,8 @@ static int uml_vfio_cmdline_set(const char *device, const struct kernel_param *kreturn 0 ; } -static int uml_vfio_cmdline_get (char *buffer,const struct kernel_param *kp) +static int uml_vfio_cmdline_get (struct seq_buf *buffer, +const struct kernel_param *kp) {return 0 ; }arch/um/drivers/virtio_uml.c +5
-7@@ -1379,23 +1379,21 @@ static int vu_cmdline_get_device(struct device *dev, void *data) {struct platform_device *pdev =to_platform_device (dev);struct virtio_uml_platform_data *pdata = pdev->dev.platform_data; -char *buffer = data; -unsigned int len =strlen (buffer); +struct seq_buf *s = data; -snprintf (buffer + len,PAGE_SIZE - len,"%s:%d:%d\n" , - pdata->socket_path, pdata->virtio_device_id, pdev->id); +seq_buf_printf (s,"%s:%d:%d\n" , + pdata->socket_path, pdata->virtio_device_id, pdev->id);return 0 ; } -static int vu_cmdline_get (char *buffer,const struct kernel_param *kp) +static int vu_cmdline_get (struct seq_buf *buffer,const struct kernel_param *kp) {guard (mutex)(&vu_cmdline_lock); - buffer[0 ] ='\0' ;if (vu_cmdline_parent_registered)device_for_each_child (&vu_cmdline_parent, buffer, vu_cmdline_get_device); -return strlen (buffer) +1 ; +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(vu_cmdline_param_ops, vu_cmdline_set,drivers/acpi/button.c +12
-7@@ -715,19 +715,24 @@ static int param_set_lid_init_state(const char *val,return 0 ; } -static int param_get_lid_init_state (char *buf,const struct kernel_param *kp) +static int param_get_lid_init_state (struct seq_buf *buf, +const struct kernel_param *kp) { -int i, c =0 ; +int i; -for (i =0 ; i <ARRAY_SIZE (lid_init_state_str); i++) +for (i =0 ; i <ARRAY_SIZE (lid_init_state_str); i++) {if (i == lid_init_state) - c +=sprintf (buf + c,"[%s] " , lid_init_state_str[i]); +seq_buf_printf (buf,"[%s] " , lid_init_state_str[i]);else - c +=sprintf (buf + c,"%s " , lid_init_state_str[i]); +seq_buf_printf (buf,"%s " , lid_init_state_str[i]); + } - buf[c -1 ] ='\n' ;/* Replace the final space with a newline */ +/* Replace the final space with a newline. */ +if (!seq_buf_has_overflowed (buf) && buf->len >0 && + buf->buffer[buf->len -1 ] ==' ' ) + buf->buffer[buf->len -1 ] ='\n' ; -return c; +return 0 ; } module_param_call(lid_init_state,drivers/acpi/sysfs.c +39
-44@@ -89,53 +89,49 @@ static const struct acpi_dlevel acpi_debug_levels[] = { ACPI_DEBUG_INIT(ACPI_LV_EVENTS), }; -static int param_get_debug_layer (char *buffer,const struct kernel_param *kp) +static int param_get_debug_layer (struct seq_buf *buffer, +const struct kernel_param *kp) { -int result =0 ;int i; - result =sprintf (buffer,"%-25s\tHex SET\n" ,"Description" ); +seq_buf_printf (buffer,"%-25s\tHex SET\n" ,"Description" );for (i =0 ; i <ARRAY_SIZE (acpi_debug_layers); i++) { - result +=sprintf (buffer + result,"%-25s\t0x%08lX [%c]\n" , - acpi_debug_layers[i].name, - acpi_debug_layers[i].value, - (acpi_dbg_layer & acpi_debug_layers[i].value) - ?'*' :' ' ); +seq_buf_printf (buffer,"%-25s\t0x%08lX [%c]\n" , + acpi_debug_layers[i].name, + acpi_debug_layers[i].value, + (acpi_dbg_layer & acpi_debug_layers[i].value) + ?'*' :' ' ); } - result += -sprintf (buffer + result,"%-25s\t0x%08X [%c]\n" ,"ACPI_ALL_DRIVERS" , -ACPI_ALL_DRIVERS , - (acpi_dbg_layer &ACPI_ALL_DRIVERS ) == -ACPI_ALL_DRIVERS ?'*' : (acpi_dbg_layer &ACPI_ALL_DRIVERS ) - ==0 ?' ' :'-' ); - result += -sprintf (buffer + result, -"--\ndebug_layer = 0x%08X ( * = enabled)\n" , - acpi_dbg_layer); +seq_buf_printf (buffer,"%-25s\t0x%08X [%c]\n" ,"ACPI_ALL_DRIVERS" , +ACPI_ALL_DRIVERS , + (acpi_dbg_layer &ACPI_ALL_DRIVERS ) ==ACPI_ALL_DRIVERS + ?'*' : (acpi_dbg_layer &ACPI_ALL_DRIVERS ) ==0 + ?' ' :'-' ); +seq_buf_printf (buffer,"--\ndebug_layer = 0x%08X ( * = enabled)\n" , + acpi_dbg_layer); -return result; +return 0 ; } -static int param_get_debug_level (char *buffer,const struct kernel_param *kp) +static int param_get_debug_level (struct seq_buf *buffer, +const struct kernel_param *kp) { -int result =0 ;int i; - result =sprintf (buffer,"%-25s\tHex SET\n" ,"Description" ); +seq_buf_printf (buffer,"%-25s\tHex SET\n" ,"Description" );for (i =0 ; i <ARRAY_SIZE (acpi_debug_levels); i++) { - result +=sprintf (buffer + result,"%-25s\t0x%08lX [%c]\n" , - acpi_debug_levels[i].name, - acpi_debug_levels[i].value, - (acpi_dbg_level & acpi_debug_levels[i].value) - ?'*' :' ' ); +seq_buf_printf (buffer,"%-25s\t0x%08lX [%c]\n" , + acpi_debug_levels[i].name, + acpi_debug_levels[i].value, + (acpi_dbg_level & acpi_debug_levels[i].value) + ?'*' :' ' ); } - result += -sprintf (buffer + result,"--\ndebug_level = 0x%08X (* = enabled)\n" , - acpi_dbg_level); +seq_buf_printf (buffer,"--\ndebug_level = 0x%08X (* = enabled)\n" , + acpi_dbg_level); -return result; +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(param_ops_debug_layer, param_set_uint,@@ -247,16 +243,18 @@ static int param_set_trace_state(const char *val,return 0 ; } -static int param_get_trace_state (char *buffer,const struct kernel_param *kp) +static int param_get_trace_state (struct seq_buf *buffer, +const struct kernel_param *kp) {if (!(acpi_gbl_trace_flags &ACPI_TRACE_ENABLED )) -return sprintf (buffer,"disable\n" ); -if (!acpi_gbl_trace_method_name) -return sprintf (buffer,"enable\n" ); -if (acpi_gbl_trace_flags &ACPI_TRACE_ONESHOT ) -return sprintf (buffer,"method-once\n" ); +seq_buf_printf (buffer,"disable\n" ); +else if (!acpi_gbl_trace_method_name) +seq_buf_printf (buffer,"enable\n" ); +else if (acpi_gbl_trace_flags &ACPI_TRACE_ONESHOT ) +seq_buf_printf (buffer,"method-once\n" );else -return sprintf (buffer,"method\n" ); +seq_buf_printf (buffer,"method\n" ); +return 0 ; } module_param_call(trace_state, param_set_trace_state, param_get_trace_state,@@ -272,14 +270,11 @@ MODULE_PARM_DESC(aml_debug_output, "To enable/disable the ACPI Debug Object output.");/* /sys/module/acpi/parameters/acpica_version */ -static int param_get_acpica_version (char *buffer, +static int param_get_acpica_version (struct seq_buf *buffer,const struct kernel_param *kp) { -int result; - - result =sprintf (buffer,"%x\n" ,ACPI_CA_VERSION ); - -return result; +seq_buf_printf (buffer,"%x\n" ,ACPI_CA_VERSION ); +return 0 ; }module_param_call (acpica_version,NULL , param_get_acpica_version,NULL ,0444 );drivers/char/ipmi/ipmi_watchdog.c +12
-21@@ -197,11 +197,11 @@ static DEFINE_KERNEL_PARAM_OPS(param_ops_timeout, set_param_timeout, param_get_int);#define param_check_timeout param_check_int -typedef int (*action_fn )(const char *intval,char *outval); +typedef int (*action_fn )(const char *intval,struct seq_buf *outval); -static int action_op (const char *inval,char *outval); -static int preaction_op (const char *inval,char *outval); -static int preop_op (const char *inval,char *outval); +static int action_op (const char *inval,struct seq_buf *outval); +static int preaction_op (const char *inval,struct seq_buf *outval); +static int preop_op (const char *inval,struct seq_buf *outval);static void check_parms (void );static int set_param_str (const char *val,const struct kernel_param *kp)@@ -227,20 +227,11 @@ static int set_param_str(const char *val, const struct kernel_param *kp)return rv; } -static int get_param_str (char *buffer,const struct kernel_param *kp) +static int get_param_str (struct seq_buf *buffer,const struct kernel_param *kp) {action_fn fn = (action_fn ) kp->arg; -int rv, len; - rv =fn (NULL , buffer); -if (rv) -return rv; - - len =strlen (buffer); - buffer[len++] ='\n' ; - buffer[len] =0 ; - -return len; +return fn (NULL , buffer); }@@ -1154,12 +1145,12 @@ static int action_op_set_val(const char *inval)return 0 ; } -static int action_op (const char *inval,char *outval) +static int action_op (const char *inval,struct seq_buf *outval) {int rv;if (outval) -strcpy (outval, action); +seq_buf_printf (outval,"%s\n" , action);if (!inval)return 0 ;@@ -1186,12 +1177,12 @@ static int preaction_op_set_val(const char *inval)return 0 ; } -static int preaction_op (const char *inval,char *outval) +static int preaction_op (const char *inval,struct seq_buf *outval) {int rv;if (outval) -strcpy (outval, preaction); +seq_buf_printf (outval,"%s\n" , preaction);if (!inval)return 0 ;@@ -1214,12 +1205,12 @@ static int preop_op_set_val(const char *inval)return 0 ; } -static int preop_op (const char *inval,char *outval) +static int preop_op (const char *inval,struct seq_buf *outval) {int rv;if (outval) -strcpy (outval, preop); +seq_buf_printf (outval,"%s\n" , preop);if (!inval)return 0 ;drivers/firmware/qemu_fw_cfg.c +19
-15@@ -860,7 +860,8 @@ static int fw_cfg_cmdline_set(const char *arg, const struct kernel_param *kp)return PTR_ERR_OR_ZERO (fw_cfg_cmdline_dev); } -static int fw_cfg_cmdline_get (char *buf,const struct kernel_param *kp) +static int fw_cfg_cmdline_get (struct seq_buf *buf, +const struct kernel_param *kp) {/* stay silent if device was not configured via the command * line, or if the parameter name (ioport/mmio) doesn't match @@ -873,22 +874,25 @@ static int fw_cfg_cmdline_get(char *buf, const struct kernel_param *kp)switch (fw_cfg_cmdline_dev->num_resources) {case 1 : -return snprintf (buf,PAGE_SIZE ,PH_ADDR_PR_1_FMT , -resource_size (&fw_cfg_cmdline_dev->resource[0 ]), - fw_cfg_cmdline_dev->resource[0 ].start); +seq_buf_printf (buf,PH_ADDR_PR_1_FMT , +resource_size (&fw_cfg_cmdline_dev->resource[0 ]), + fw_cfg_cmdline_dev->resource[0 ].start); +return 0 ;case 3 : -return snprintf (buf,PAGE_SIZE ,PH_ADDR_PR_3_FMT , -resource_size (&fw_cfg_cmdline_dev->resource[0 ]), - fw_cfg_cmdline_dev->resource[0 ].start, - fw_cfg_cmdline_dev->resource[1 ].start, - fw_cfg_cmdline_dev->resource[2 ].start); +seq_buf_printf (buf,PH_ADDR_PR_3_FMT , +resource_size (&fw_cfg_cmdline_dev->resource[0 ]), + fw_cfg_cmdline_dev->resource[0 ].start, + fw_cfg_cmdline_dev->resource[1 ].start, + fw_cfg_cmdline_dev->resource[2 ].start); +return 0 ;case 4 : -return snprintf (buf,PAGE_SIZE ,PH_ADDR_PR_4_FMT , -resource_size (&fw_cfg_cmdline_dev->resource[0 ]), - fw_cfg_cmdline_dev->resource[0 ].start, - fw_cfg_cmdline_dev->resource[1 ].start, - fw_cfg_cmdline_dev->resource[2 ].start, - fw_cfg_cmdline_dev->resource[3 ].start); +seq_buf_printf (buf,PH_ADDR_PR_4_FMT , +resource_size (&fw_cfg_cmdline_dev->resource[0 ]), + fw_cfg_cmdline_dev->resource[0 ].start, + fw_cfg_cmdline_dev->resource[1 ].start, + fw_cfg_cmdline_dev->resource[2 ].start, + fw_cfg_cmdline_dev->resource[3 ].start); +return 0 ; }/* Should never get here */ drivers/gpu/drm/i915/i915_mitigations.c +15
-11@@ -95,33 +95,37 @@ static int mitigations_set(const char *val, const struct kernel_param *kp)return 0 ; } -static int mitigations_get (char *buffer,const struct kernel_param *kp) +static int mitigations_get (struct seq_buf *buffer, +const struct kernel_param *kp) {unsigned long local =READ_ONCE (mitigations); -int count, i;bool enable; +int i; -if (!local) -return scnprintf (buffer,PAGE_SIZE ,"%s\n" ,"off" ); +if (!local) { +seq_buf_printf (buffer,"%s\n" ,"off" ); +return 0 ; + }if (local &BIT (BITS_PER_LONG -1 )) { - count =scnprintf (buffer,PAGE_SIZE ,"%s," ,"auto" ); +seq_buf_printf (buffer,"%s," ,"auto" ); enable = false; }else { enable = true; - count =0 ; }for (i =0 ; i <ARRAY_SIZE (names); i++) {if ((local &BIT (i)) != enable)continue ; - - count +=scnprintf (buffer + count,PAGE_SIZE - count, -"%s%s," , enable ?"" :"!" , names[i]); +seq_buf_printf (buffer,"%s%s," , enable ?"" :"!" , names[i]); } - buffer[count -1 ] ='\n' ; -return count; +/* Replace the trailing comma with a newline. */ +if (!seq_buf_has_overflowed (buffer) && buffer->len >0 && + buffer->buffer[buffer->len -1 ] ==',' ) + buffer->buffer[buffer->len -1 ] ='\n' ; + +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(ops, mitigations_set, mitigations_get);drivers/infiniband/ulp/srp/ib_srp.c +4
-3@@ -161,14 +161,15 @@ static struct ib_client srp_client = {static struct ib_sa_client srp_sa_client; -static int srp_tmo_get (char *buffer,const struct kernel_param *kp) +static int srp_tmo_get (struct seq_buf *buffer,const struct kernel_param *kp) {int tmo = *(int *)kp->arg;if (tmo >=0 ) -return sysfs_emit (buffer,"%d\n" , tmo); +seq_buf_printf (buffer,"%d\n" , tmo);else -return sysfs_emit (buffer,"off\n" ); +seq_buf_printf (buffer,"off\n" ); +return 0 ; }static int srp_tmo_set (const char *val,const struct kernel_param *kp)drivers/media/usb/uvc/uvc_driver.c +5
-3@@ -2451,12 +2451,14 @@ static int uvc_reset_resume(struct usb_interface *intf)* Module parameters */ -static int uvc_clock_param_get (char *buffer,const struct kernel_param *kp) +static int uvc_clock_param_get (struct seq_buf *buffer, +const struct kernel_param *kp) {if (uvc_clock_param ==CLOCK_MONOTONIC ) -return sprintf (buffer,"CLOCK_MONOTONIC" ); +seq_buf_printf (buffer,"CLOCK_MONOTONIC" );else -return sprintf (buffer,"CLOCK_REALTIME" ); +seq_buf_printf (buffer,"CLOCK_REALTIME" ); +return 0 ; }static int uvc_clock_param_set (const char *val,const struct kernel_param *kp)drivers/pci/pcie/aspm.c +10
-7@@ -1572,16 +1572,19 @@ static int pcie_aspm_set_policy(const char *val,return 0 ; } -static int pcie_aspm_get_policy (char *buffer,const struct kernel_param *kp) +static int pcie_aspm_get_policy (struct seq_buf *buffer, +const struct kernel_param *kp) { -int i, cnt =0 ; -for (i =0 ; i <ARRAY_SIZE (policy_str); i++) +int i; + +for (i =0 ; i <ARRAY_SIZE (policy_str); i++) {if (i == aspm_policy) - cnt +=sprintf (buffer + cnt,"[%s] " , policy_str[i]); +seq_buf_printf (buffer,"[%s] " , policy_str[i]);else - cnt +=sprintf (buffer + cnt,"%s " , policy_str[i]); - cnt +=sprintf (buffer + cnt,"\n" ); -return cnt; +seq_buf_printf (buffer,"%s " , policy_str[i]); + } +seq_buf_putc (buffer,'\n' ); +return 0 ; } module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy,drivers/scsi/fcoe/fcoe_transport.c +11
-11@@ -23,7 +23,8 @@ MODULE_LICENSE("GPL v2");static int fcoe_transport_create (const char *,const struct kernel_param *);static int fcoe_transport_destroy (const char *,const struct kernel_param *); -static int fcoe_transport_show (char *buffer,const struct kernel_param *kp); +static int fcoe_transport_show (struct seq_buf *buffer, +const struct kernel_param *kp);static struct fcoe_transport *fcoe_transport_lookup (struct net_device *device);static struct fcoe_transport *fcoe_netdev_map_lookup (struct net_device *device);static int fcoe_transport_enable (const char *,const struct kernel_param *);@@ -595,22 +596,21 @@ int fcoe_transport_detach(struct fcoe_transport *ft) }EXPORT_SYMBOL (fcoe_transport_detach); -static int fcoe_transport_show (char *buffer,const struct kernel_param *kp) +static int fcoe_transport_show (struct seq_buf *buffer, +const struct kernel_param *kp) { -int i, j;struct fcoe_transport *ft =NULL ; - i = j =sprintf (buffer,"Attached FCoE transports:" ); +seq_buf_printf (buffer,"Attached FCoE transports:" );mutex_lock (&ft_mutex); -list_for_each_entry (ft, &fcoe_transports, list) { -if (i >=PAGE_SIZE -IFNAMSIZ ) -break ; - i +=snprintf (&buffer[i],IFNAMSIZ ,"%s " , ft->name); +if (list_empty (&fcoe_transports)) { +seq_buf_printf (buffer,"none" ); + }else { +list_for_each_entry (ft, &fcoe_transports, list) +seq_buf_printf (buffer,"%s " , ft->name); }mutex_unlock (&ft_mutex); -if (i == j) - i +=snprintf (&buffer[i],IFNAMSIZ ,"none" ); -return i; +return 0 ; }static int __init fcoe_transport_init (void )drivers/thermal/intel/intel_powerclamp.c +7
-7@@ -101,15 +101,13 @@ static int duration_set(const char *arg, const struct kernel_param *kp)return ret; } -static int duration_get (char *buf,const struct kernel_param *kp) +static int duration_get (struct seq_buf *buf,const struct kernel_param *kp) { -int ret; -mutex_lock (&powerclamp_lock); - ret =sysfs_emit (buf,"%d\n" , duration /1000 ); +seq_buf_printf (buf,"%d\n" , duration /1000 );mutex_unlock (&powerclamp_lock); -return ret; +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(duration_ops, duration_set, duration_get);@@ -192,12 +190,14 @@ static int cpumask_set(const char *arg, const struct kernel_param *kp)return ret; } -static int cpumask_get (char *buf,const struct kernel_param *kp) +static int cpumask_get (struct seq_buf *buf,const struct kernel_param *kp) {if (!cpumask_available (idle_injection_cpu_mask))return -ENODEV ; -return cpumap_print_to_pagebuf (false, buf, idle_injection_cpu_mask); +seq_buf_printf (buf,"%*pb\n" , nr_cpu_ids, +cpumask_bits (idle_injection_cpu_mask)); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(cpumask_ops, cpumask_set, cpumask_get);drivers/tty/hvc/hvc_iucv.c +7
-11@@ -1256,36 +1256,32 @@ static int param_set_vmidfilter(const char *val, const struct kernel_param *kp)/** * param_get_vmidfilter() - Get z/VM user ID filter -* @buffer: Buffer to store z/VM user ID filter, -* (buffer size assumption PAGE_SIZE) +* @buffer: seq_buf to store z/VM user ID filter * @kp: Kernel parameter pointing to the hvc_iucv_filter array * * The function stores the filter as a comma-separated list of z/VM user IDs * in @buffer. Typically, sysfs routines call this function for attr show. */ -static int param_get_vmidfilter (char *buffer,const struct kernel_param *kp) +static int param_get_vmidfilter (struct seq_buf *buffer, +const struct kernel_param *kp) { -int rc;size_t index, len;void *start, *end;if (!machine_is_vm () || !hvc_iucv_devices)return -ENODEV ; - rc =0 ;read_lock_bh (&hvc_iucv_filter_lock);for (index =0 ; index < hvc_iucv_filter_size; index++) { start = hvc_iucv_filter + (8 * index); end =memchr (start,' ' ,8 ); len = (end) ? end - start :8 ; -memcpy (buffer + rc, start, len); - rc += len; - buffer[rc++] =',' ; +if (index) +seq_buf_putc (buffer,',' ); +seq_buf_printf (buffer,"%.*s" , (int )len, (char *)start); }read_unlock_bh (&hvc_iucv_filter_lock); -if (rc) - buffer[--rc] ='\0' ;/* replace last comma and update rc */ -return rc; +return 0 ; }#define param_check_vmidfilter (name, p) __param_check(name, p, void)drivers/usb/storage/usb.c +8
-12@@ -115,27 +115,22 @@ static int parse_delay_str(const char *str, int ndecimals, const char *suffix,* @val: The integer value to format, scaled by 10^(@ndecimals). * @ndecimals: Number of decimal to scale down. * @suffix: Suffix string to format. -* @str: Where to store the formatted string. -* @size: The size of buffer for @str. +* @s: Where to store the formatted string. * * Format an integer value in @val scale down by 10^(@ndecimals) without @suffix * if @val is divisible by 10^(@ndecimals). * Otherwise format a value in @val just as it is with @suffix -* -* Returns the number of characters written into @str. */ -static int format_delay_ms (unsigned int val,int ndecimals,const char *suffix, -char *str,int size) +static void format_delay_ms (unsigned int val,int ndecimals,const char *suffix, +struct seq_buf *s) {u64 delay_ms = val;unsigned int rem =do_div (delay_ms,int_pow (10 , ndecimals)); -int ret;if (rem) - ret =scnprintf (str, size,"%u%s\n" , val, suffix); +seq_buf_printf (s,"%u%s\n" , val, suffix);else - ret =scnprintf (str, size,"%u\n" , (unsigned int )delay_ms); -return ret; +seq_buf_printf (s,"%u\n" , (unsigned int )delay_ms); }static int delay_use_set (const char *s,const struct kernel_param *kp)@@ -151,11 +146,12 @@ static int delay_use_set(const char *s, const struct kernel_param *kp)return 0 ; } -static int delay_use_get (char *s,const struct kernel_param *kp) +static int delay_use_get (struct seq_buf *s,const struct kernel_param *kp) {unsigned int delay_ms = *((unsigned int *)kp->arg); -return format_delay_ms (delay_ms,3 ,"ms" , s,PAGE_SIZE ); +format_delay_ms (delay_ms,3 ,"ms" , s); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(delay_use_ops, delay_use_set, delay_use_get);drivers/virtio/virtio_mmio.c +9
-12@@ -728,24 +728,21 @@ static int vm_cmdline_set(const char *device,static int vm_cmdline_get_device (struct device *dev,void *data) { -char *buffer = data; -unsigned int len =strlen (buffer); +struct seq_buf *s = data;struct platform_device *pdev =to_platform_device (dev); -snprintf (buffer + len,PAGE_SIZE - len,"0x%llx@0x%llx:%llu:%d\n" , - pdev->resource[0 ].end - pdev->resource[0 ].start +1ULL , - (unsigned long long )pdev->resource[0 ].start, - (unsigned long long )pdev->resource[1 ].start, - pdev->id); +seq_buf_printf (s,"0x%llx@0x%llx:%llu:%d\n" , + pdev->resource[0 ].end - pdev->resource[0 ].start +1ULL , + (unsigned long long )pdev->resource[0 ].start, + (unsigned long long )pdev->resource[1 ].start, + pdev->id);return 0 ; } -static int vm_cmdline_get (char *buffer,const struct kernel_param *kp) +static int vm_cmdline_get (struct seq_buf *s,const struct kernel_param *kp) { - buffer[0 ] ='\0' ; -device_for_each_child (&vm_cmdline_parent, buffer, - vm_cmdline_get_device); -return strlen (buffer) +1 ; +device_for_each_child (&vm_cmdline_parent, s, vm_cmdline_get_device); +return 0 ; } static DEFINE_KERNEL_PARAM_OPS(vm_cmdline_param_ops, vm_cmdline_set,lib/dynamic_debug.c +7
-4@@ -17,6 +17,7 @@#include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kallsyms.h> +#include <linux/seq_buf.h> #include <linux/types.h> #include <linux/mutex.h> #include <linux/proc_fs.h> @@ -787,7 +788,8 @@ EXPORT_SYMBOL(param_set_dyndbg_classes);* altered by direct >control. Displays 0x for DISJOINT, 0-N for * LEVEL Returns: #chars written or <0 on error */ -int param_get_dyndbg_classes (char *buffer,const struct kernel_param *kp) +int param_get_dyndbg_classes (struct seq_buf *buffer, +const struct kernel_param *kp) {const struct ddebug_class_param *dcp = kp->arg;const struct ddebug_class_map *map = dcp->map;@@ -796,11 +798,13 @@ int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp)case DD_CLASS_TYPE_DISJOINT_NAMES :case DD_CLASS_TYPE_DISJOINT_BITS : -return scnprintf (buffer,PAGE_SIZE ,"0x%lx\n" , *dcp->bits); +seq_buf_printf (buffer,"0x%lx\n" , *dcp->bits); +return 0 ;case DD_CLASS_TYPE_LEVEL_NAMES :case DD_CLASS_TYPE_LEVEL_NUM : -return scnprintf (buffer,PAGE_SIZE ,"%d\n" , *dcp->lvl); +seq_buf_printf (buffer,"%d\n" , *dcp->lvl); +return 0 ;default :return -1 ; } --2.34.1
Kees Cook
maintainerPATCH 11/11 moduleparam: Drop legacy kernel_param_ops .get_str field and dispatch logic
In reply to Kees CookAll struct kernel_param_ops .get callbacks have been migrated to using struct seq_buf. Drop the migration scaffolding.
--- include/linux/moduleparam.h | 37 ++-------------------- kernel/params.c | 62 ++++++++++--------------------------- 2 files changed, 20 insertions(+), 79 deletions(-)
include/linux/moduleparam.h +3 -34
@@ -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), \ }
kernel/params.c +17 -45
90 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH 11/11] moduleparam: Drop legacy kernel_param_ops .get_str field and dispatch logic
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unconditional call to arr->ops->get() without a NULL check can cause a kernel panic if the array parameter element lacks a .get callback. --
commit a252ae87a187a5b644d160fded352c545493a611
Author: Kees Cook <[email protected]>
moduleparam: Drop legacy kernel_param_ops .get_str field and dispatch logic
All struct kernel_param_ops .get callbacks have been migrated to using struct seq_buf. Drop the migration scaffolding.
Quoted 4 lines
kernel/params.c +0
-0
[ ... ]
Quoted 9 lines
kernel/params.c +0
-5@@ -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 {
[ ... ]
kernel/params.c
Quoted 2 lines
kernel/params.c +1
-1- } + ret = arr->ops->get (s, &p);
[Severity: High]
This isn't a bug introduced by this patch, but does this unconditional call to arr->ops->get() need a NULL check to avoid a kernel panic?
If a module defines a write-only array parameter where the element's kernel_param_ops struct lacks a .get callback, and assigns it write-only sysfs permissions, root can still attempt to read the file. When this happens, sysfs invokes param_attr_show().
For normal parameters, param_attr_show() has a safety check that rejects the read if ops->get is NULL. However, for array parameters, ops resolves to param_array_ops which has a valid .get callback, bypassing the safeguard.
Could this result in a NULL pointer dereference when arr->ops->get(s, &p) is executed? Before this patch, the code fell back to calling .get_str(), which would also be NULL for a write-only type, resulting in the same kernel panic.
Quoted 5 lines
kernel/params.c +2
-0+if (ret <0 ) +return ret;/* Nothing got written (e.g. overflow) — stop. */ if (s->len == before)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Patchwork
CI✗ Fi.CI.BUILD: failure for Convert moduleparams to seq_buf
In reply to Kees Cook== Series Details ==
== Series Details ==
Series: Convert moduleparams to seq_buf
URL : https://patchwork.freedesktop.org/series/167021/
State : failure
== Summary ==
Error: patch https://patchwork.freedesktop.org/api/1.0/series/167021/revisions/1/mbox/ not applied
Applying: params: bound array element output to the caller's page buffer
Applying: panic: Replace panic_print_get() with generic helper
Applying: moduleparam: Add DEFINE_KERNEL_PARAM_OPS macro family
Applying: treewide: Convert struct kernel_param_ops initializers to DEFINE_KERNEL_PARAM_OPS
error: sha1 information is lacking or useless (kernel/panic.c).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0004 treewide: Convert struct kernel_param_ops initializers to DEFINE_KERNEL_PARAM_OPS When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Build failed, no error log produced
Petr Pavlu
maintainerQuoted 15 lines · Kees Cook
Hi,
I tried to trim the CC list here, but it's still pretty huge...
We've had a long-standing issue with "write to a string pointer" callbacks that don't bounds check the destination (and for which the bounds is also not part of the callback prototype, even if it is "known" to be
PAGE_SIZE, whichsysfs_emit()depends on). Both moduleparams and sysfs use this pattern. As a first step, and to test the migration method, migrate moduleparams first.There are 2 "mechanical" treewide patches that are handled by Coccinelle:
- treewide: Convert structkernel_param_opsinitializers toDEFINE_KERNEL_PARAM_OPS
- treewide: Convert customkernel_param_ops.get callbacks toseq_bufvia cocci
Quoted 8 lines
The last treewide patch is manual, and may need to be broken up into per-subsystem patches, though I'd prefer to avoid this, as it would extend the migration from 1 relase to at least 2 releases. (1 to release the migration infrastructure, then 1 release to collect all the subsystem changes, and possibly 1 more release to remove the migration infrastructure.)
Thoughts, questions?
This looks reasonable to me. I added a few minor comments on the patches but they already look solid.
Signature · 2 lines
Thanks, Petr
Kees Cook
maintainerQuoted 23 lines · Petr Pavlu
Quoted 22 lines · Kees Cook
Hi,
I tried to trim the CC list here, but it's still pretty huge...
We've had a long-standing issue with "write to a string pointer" callbacks that don't bounds check the destination (and for which the bounds is also not part of the callback prototype, even if it is "known" to be
PAGE_SIZE, whichsysfs_emit()depends on). Both moduleparams and sysfs use this pattern. As a first step, and to test the migration method, migrate moduleparams first.There are 2 "mechanical" treewide patches that are handled by Coccinelle:
- treewide: Convert structkernel_param_opsinitializers toDEFINE_KERNEL_PARAM_OPS
- treewide: Convert customkernel_param_ops.get callbacks toseq_bufvia cocciThe last treewide patch is manual, and may need to be broken up into per-subsystem patches, though I'd prefer to avoid this, as it would extend the migration from 1 relase to at least 2 releases. (1 to release the migration infrastructure, then 1 release to collect all the subsystem changes, and possibly 1 more release to remove the migration infrastructure.)
Quoted 4 lines
Quoted 1 line
Thoughts, questions?
This looks reasonable to me. I added a few minor comments on the patches but they already look solid.
Thanks for the review! I'll get a v2 prepared with your notes addressed. :)
-Kees
Signature · 1 line
Kees Cook