module params: few simplifications
Subsystems (32)
v2 cover module params: few simplifications
From: "Luis R. Rodriguez" <[email protected]>
This v2 splits out the #ifdef'ery eyesores out into separate patches to make it clear this is a separate atomic operation which requires review in and of itself. It also makes some clarifications about how the module_param_config_*() can help with eyesores, and also documents our paranoia over avoiding bool_enable_only for now on CONFIG_MODULE_SIG_FORCE kernels.
It could be that we are comfortable with bool_enable_only's implementation even for CONFIG_MODULE_SIG_FORCE kernels -- but I'd rather let someone dealing with policy decide that.
Luis R. Rodriguez (8):
kernel/params: constify struct kernel_param_ops uses kernel/module.c: use generic module param operaters for sig_enforce kernel/params.c: generalize bool_enable_only moduleparam.h: add module_param_config_*() helpers kernel/workqueue.c: remove ifdefs over wq_power_efficient kernel/workqueue.c: use module_param_config_on_off() for
power_efficient
kernel/module.c: avoid ifdefs for sig_enforce declaration kernel/module.c: use module_param_config_on() for sig_enforce
arch/s390/kernel/perf_cpum_sf.c | 2 +- arch/x86/kvm/mmu_audit.c | 2 +- arch/x86/platform/uv/uv_nmi.c | 2 +- drivers/block/null_blk.c | 4 +- drivers/char/ipmi/ipmi_watchdog.c | 6 +-- drivers/dma/dmatest.c | 4 +- drivers/ide/ide.c | 2 +- drivers/infiniband/ulp/srp/ib_srp.c | 4 +- drivers/input/misc/ati_remote2.c | 4 +- drivers/input/mouse/psmouse-base.c | 2 +- drivers/misc/lis3lv02d/lis3lv02d.c | 2 +- drivers/mtd/ubi/block.c | 2 +- drivers/net/wireless/ath/wil6210/main.c | 4 +- drivers/power/test_power.c | 16 ++++---- drivers/thermal/intel_powerclamp.c | 4 +- drivers/tty/hvc/hvc_iucv.c | 2 +- drivers/tty/sysrq.c | 2 +- drivers/video/fbdev/uvesafb.c | 2 +- drivers/virtio/virtio_mmio.c | 2 +- fs/nfs/super.c | 2 +- include/linux/moduleparam.h | 73 ++++++++++++++++++++++++++------- kernel/module.c | 40 ++---------------- kernel/params.c | 44 ++++++++++++++++---- kernel/workqueue.c | 8 +--- net/sunrpc/auth.c | 2 +- net/sunrpc/xprtsock.c | 6 +-- security/apparmor/lsm.c | 6 +-- security/integrity/ima/ima_crypto.c | 2 +- sound/pci/hda/hda_intel.c | 2 +- 29 files changed, 143 insertions(+), 110 deletions(-)
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v2 1/8 kernel/params: constify struct kernel_param_ops uses
From: "Luis R. Rodriguez" <[email protected]>
Most code already uses consts for the struct kernel_param_ops, sweep the kernel for the last offending stragglers. Other than include/linux/moduleparam.h and kernel/params.c all other changes were generated with the following Coccinelle SmPL patch. Merge conflicts between trees can be handled with Coccinelle.
In the future git could get Coccinelle merge support to deal with patch --> fail --> grammar --> Coccinelle --> new patch conflicts automatically for us on patches where the grammar is available and the patch is of high confidence. Consider this a feature request.
Test compiled on x86_64 against:
* allnoconfig
* allmodconfig
* allyesconfig
@ const_found @
identifier ops;
@@
const struct kernel_param_ops ops = {
};
@ const_not_found depends on !const_found @
identifier ops;
@@
-struct kernel_param_ops ops = {
+const struct kernel_param_ops ops = {
};
--- arch/s390/kernel/perf_cpum_sf.c | 2 +- arch/x86/kvm/mmu_audit.c | 2 +- arch/x86/platform/uv/uv_nmi.c | 2 +- drivers/block/null_blk.c | 4 ++-- drivers/char/ipmi/ipmi_watchdog.c | 6 +++--- drivers/dma/dmatest.c | 4 ++-- drivers/ide/ide.c | 2 +- drivers/infiniband/ulp/srp/ib_srp.c | 4 ++-- drivers/input/misc/ati_remote2.c | 4 ++-- drivers/input/mouse/psmouse-base.c | 2 +- drivers/misc/lis3lv02d/lis3lv02d.c | 2 +- drivers/mtd/ubi/block.c | 2 +- drivers/net/wireless/ath/wil6210/main.c | 4 ++-- drivers/power/test_power.c | 16 ++++++++-------- drivers/thermal/intel_powerclamp.c | 4 ++-- drivers/tty/hvc/hvc_iucv.c | 2 +- drivers/tty/sysrq.c | 2 +- drivers/video/fbdev/uvesafb.c | 2 +- drivers/virtio/virtio_mmio.c | 2 +- fs/nfs/super.c | 2 +- include/linux/moduleparam.h | 30 +++++++++++++++--------------- kernel/params.c | 14 +++++++------- net/sunrpc/auth.c | 2 +- net/sunrpc/xprtsock.c | 6 +++--- security/apparmor/lsm.c | 6 +++--- security/integrity/ima/ima_crypto.c | 2 +- sound/pci/hda/hda_intel.c | 2 +- 27 files changed, 66 insertions(+), 66 deletions(-)
arch/s390/kernel/perf_cpum_sf.c +1 -1
@@ -1572,7 +1572,7 @@ 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 struct kernel_param_ops param_ops_sfb_size = { +static const struct kernel_param_ops param_ops_sfb_size = { .set = param_set_sfb_size, .get = param_get_sfb_size, };
arch/x86/kvm/mmu_audit.c +1 -1
@@ -291,7 +291,7 @@ static int mmu_audit_set(const char *val, const struct kernel_param *kp)return 0 ; } -static struct kernel_param_ops audit_param_ops = { +static const struct kernel_param_ops audit_param_ops = { .set = mmu_audit_set, .get = param_get_bool, };
arch/x86/platform/uv/uv_nmi.c +1 -1
@@ -104,7 +104,7 @@ static int param_set_local64(const char *val, const struct kernel_param *kp)return 0 ; } -static struct kernel_param_ops param_ops_local64 = { +static const struct kernel_param_ops param_ops_local64 = { .get = param_get_local64, .set = param_set_local64, };
drivers/block/null_blk.c +2 -2
@@ -99,7 +99,7 @@ static int null_set_queue_mode(const char *str, const struct kernel_param *kp)return null_param_store_val (str, &queue_mode,NULL_Q_BIO ,NULL_Q_MQ ); } -static struct kernel_param_ops null_queue_mode_param_ops = { +static const struct kernel_param_ops null_queue_mode_param_ops = { .set = null_set_queue_mode, .get = param_get_int, };
@@ -127,7 +127,7 @@ static int null_set_irqmode(const char *str, const struct kernel_param *kp) NULL_IRQ_TIMER); } -static struct kernel_param_ops null_irqmode_param_ops = { +static const struct kernel_param_ops null_irqmode_param_ops = { .set = null_set_irqmode, .get = param_get_int, };
drivers/char/ipmi/ipmi_watchdog.c +3 -3
@@ -208,7 +208,7 @@ static int set_param_timeout(const char *val, const struct kernel_param *kp)return rv; } -static struct kernel_param_ops param_ops_timeout = { +static const struct kernel_param_ops param_ops_timeout = { .set = set_param_timeout, .get = param_get_int, };
@@ -270,14 +270,14 @@ static int set_param_wdog_ifnum(const char *val, const struct kernel_param *kp)return 0 ; } -static struct kernel_param_ops param_ops_wdog_ifnum = { +static const struct kernel_param_ops param_ops_wdog_ifnum = { .set = set_param_wdog_ifnum, .get = param_get_int, };#define param_check_wdog_ifnum param_check_int -static struct kernel_param_ops param_ops_str = { +static const struct kernel_param_ops param_ops_str = { .set = set_param_str, .get = get_param_str, };
drivers/dma/dmatest.c +2 -2
@@ -120,7 +120,7 @@ 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 struct kernel_param_ops run_ops = { +static const struct kernel_param_ops run_ops = { .set = dmatest_run_set, .get = dmatest_run_get, };
@@ -195,7 +195,7 @@ static int dmatest_wait_get(char *val, const struct kernel_param *kp)return param_get_bool (val, kp); } -static struct kernel_param_ops wait_ops = { +static const struct kernel_param_ops wait_ops = { .get = dmatest_wait_get, .set = param_set_bool, };
drivers/ide/ide.c +1 -1
@@ -199,7 +199,7 @@ static int ide_set_dev_param_mask(const char *s, const struct kernel_param *kp)return 0 ; } -static struct kernel_param_ops param_ops_ide_dev_mask = { +static const struct kernel_param_ops param_ops_ide_dev_mask = { .set = ide_set_dev_param_mask };
drivers/infiniband/ulp/srp/ib_srp.c +2 -2
@@ -98,7 +98,7 @@ module_param(register_always, bool, 0444);MODULE_PARM_DESC (register_always,"Use memory registration even for contiguous memory regions" ); -static struct kernel_param_ops srp_tmo_ops; +static const struct kernel_param_ops srp_tmo_ops;static int srp_reconnect_delay =10 ; module_param_cb(reconnect_delay, &srp_tmo_ops, &srp_reconnect_delay,
@@ -183,7 +183,7 @@ out:return res; } -static struct kernel_param_ops srp_tmo_ops = { +static const struct kernel_param_ops srp_tmo_ops = { .get = srp_tmo_get, .set = srp_tmo_set, };
drivers/input/misc/ati_remote2.c +2 -2
@@ -94,7 +94,7 @@ 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 struct kernel_param_ops param_ops_channel_mask = { +static const struct kernel_param_ops param_ops_channel_mask = { .set = ati_remote2_set_channel_mask, .get = ati_remote2_get_channel_mask, };
@@ -103,7 +103,7 @@ MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<static unsigned int mode_mask =ATI_REMOTE2_MAX_MODE_MASK ;#define param_check_mode_mask (name, p) __param_check(name, p, unsigned int) -static struct kernel_param_ops param_ops_mode_mask = { +static const struct kernel_param_ops param_ops_mode_mask = { .set = ati_remote2_set_mode_mask, .get = ati_remote2_get_mode_mask, };
drivers/input/mouse/psmouse-base.c +1 -1
@@ -47,7 +47,7 @@ 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 struct kernel_param_ops param_ops_proto_abbrev = { +static const struct kernel_param_ops param_ops_proto_abbrev = { .set = psmouse_set_maxproto, .get = psmouse_get_maxproto, };
drivers/misc/lis3lv02d/lis3lv02d.c +1 -1
@@ -115,7 +115,7 @@ static int param_set_axis(const char *val, const struct kernel_param *kp)return ret; } -static struct kernel_param_ops param_ops_axis = { +static const struct kernel_param_ops param_ops_axis = { .set = param_set_axis, .get = param_get_int, };
drivers/mtd/ubi/block.c +1 -1
@@ -161,7 +161,7 @@ static int __init ubiblock_set_param(const char *val,return 0 ; } -static struct kernel_param_ops ubiblock_param_ops = { +static const struct kernel_param_ops ubiblock_param_ops = { .set = ubiblock_set_param, };module_param_cb (block, &ubiblock_param_ops,NULL ,0 );
drivers/net/wireless/ath/wil6210/main.c +2 -2
@@ -58,7 +58,7 @@ static int mtu_max_set(const char *val, const struct kernel_param *kp)return ret; } -static struct kernel_param_ops mtu_max_ops = { +static const struct kernel_param_ops mtu_max_ops = { .set = mtu_max_set, .get = param_get_uint, };
@@ -87,7 +87,7 @@ static int ring_order_set(const char *val, const struct kernel_param *kp)return 0 ; } -static struct kernel_param_ops ring_order_ops = { +static const struct kernel_param_ops ring_order_ops = { .set = ring_order_set, .get = param_get_uint, };
drivers/power/test_power.c +8 -8
@@ -448,42 +448,42 @@ static int param_set_battery_voltage(const char *key,#define param_get_battery_voltage param_get_int -static struct kernel_param_ops param_ops_ac_online = { +static const struct kernel_param_ops param_ops_ac_online = { .set = param_set_ac_online, .get = param_get_ac_online, }; -static struct kernel_param_ops param_ops_usb_online = { +static const struct kernel_param_ops param_ops_usb_online = { .set = param_set_usb_online, .get = param_get_usb_online, }; -static struct kernel_param_ops param_ops_battery_status = { +static const struct kernel_param_ops param_ops_battery_status = { .set = param_set_battery_status, .get = param_get_battery_status, }; -static struct kernel_param_ops param_ops_battery_present = { +static const struct kernel_param_ops param_ops_battery_present = { .set = param_set_battery_present, .get = param_get_battery_present, }; -static struct kernel_param_ops param_ops_battery_technology = { +static const struct kernel_param_ops param_ops_battery_technology = { .set = param_set_battery_technology, .get = param_get_battery_technology, }; -static struct kernel_param_ops param_ops_battery_health = { +static const struct kernel_param_ops param_ops_battery_health = { .set = param_set_battery_health, .get = param_get_battery_health, }; -static struct kernel_param_ops param_ops_battery_capacity = { +static const struct kernel_param_ops param_ops_battery_capacity = { .set = param_set_battery_capacity, .get = param_get_battery_capacity, }; -static struct kernel_param_ops param_ops_battery_voltage = { +static const struct kernel_param_ops param_ops_battery_voltage = { .set = param_set_battery_voltage, .get = param_get_battery_voltage, };
drivers/thermal/intel_powerclamp.c +2 -2
@@ -119,7 +119,7 @@ exit:return ret; } -static struct kernel_param_ops duration_ops = { +static const struct kernel_param_ops duration_ops = { .set = duration_set, .get = param_get_int, };
@@ -167,7 +167,7 @@ exit_win:return ret; } -static struct kernel_param_ops window_size_ops = { +static const struct kernel_param_ops window_size_ops = { .set = window_size_set, .get = param_get_int, };
drivers/tty/hvc/hvc_iucv.c +1 -1
@@ -1345,7 +1345,7 @@ static int param_get_vmidfilter(char *buffer, const struct kernel_param *kp)#define param_check_vmidfilter (name, p) __param_check(name, p, void) -static struct kernel_param_ops param_ops_vmidfilter = { +static const struct kernel_param_ops param_ops_vmidfilter = { .set = param_set_vmidfilter, .get = param_get_vmidfilter, };
drivers/tty/sysrq.c +1 -1
@@ -1002,7 +1002,7 @@ static int sysrq_reset_seq_param_set(const char *buffer,return 0 ; } -static struct kernel_param_ops param_ops_sysrq_reset_seq = { +static const struct kernel_param_ops param_ops_sysrq_reset_seq = { .get = param_get_ushort, .set = sysrq_reset_seq_param_set, };
drivers/video/fbdev/uvesafb.c +1 -1
@@ -1977,7 +1977,7 @@ static int param_set_scroll(const char *val, const struct kernel_param *kp)return 0 ; } -static struct kernel_param_ops param_ops_scroll = { +static const struct kernel_param_ops param_ops_scroll = { .set = param_set_scroll, };#define param_check_scroll (name, p) __param_check(name, p, void)
drivers/virtio/virtio_mmio.c +1 -1
@@ -691,7 +691,7 @@ static int vm_cmdline_get(char *buffer, const struct kernel_param *kp)return strlen (buffer) +1 ; } -static struct kernel_param_ops vm_cmdline_param_ops = { +static const struct kernel_param_ops vm_cmdline_param_ops = { .set = vm_cmdline_set, .get = vm_cmdline_get, };
fs/nfs/super.c +1 -1
@@ -2849,7 +2849,7 @@ static int param_set_portnr(const char *val, const struct kernel_param *kp) *((unsigned int *)kp->arg) = num;return 0 ; } -static struct kernel_param_ops param_ops_portnr = { +static const struct kernel_param_ops param_ops_portnr = { .set = param_set_portnr, .get = param_get_uint, };
include/linux/moduleparam.h +15 -15
@@ -225,7 +225,7 @@ struct kparam_array/* Obsolete - use module_param_cb() */ #define module_param_call (name, set, get, arg, perm) \ - static struct kernel_param_ops __param_ops_##name = \ + static const struct kernel_param_ops __param_ops_##name = \ { .flags = 0, (void *)set, (void *)get }; \ __module_param_call(MODULE_PARAM_PREFIX, \ name, &__param_ops_##name, arg, \
@@ -376,64 +376,64 @@ static inline void destroy_params(const struct kernel_param *params,#define __param_check (name, p, type) \ static inline type __always_unused *__check_##name(void) { return(p); } -extern struct kernel_param_ops param_ops_byte; +extern const struct kernel_param_ops param_ops_byte;extern int param_set_byte (const char *val,const struct kernel_param *kp);extern int param_get_byte (char *buffer,const struct kernel_param *kp);#define param_check_byte (name, p) __param_check(name, p, unsigned char) -extern struct kernel_param_ops param_ops_short; +extern const struct kernel_param_ops param_ops_short;extern int param_set_short (const char *val,const struct kernel_param *kp);extern int param_get_short (char *buffer,const struct kernel_param *kp);#define param_check_short (name, p) __param_check(name, p, short) -extern struct kernel_param_ops param_ops_ushort; +extern const struct kernel_param_ops param_ops_ushort;extern int param_set_ushort (const char *val,const struct kernel_param *kp);extern int param_get_ushort (char *buffer,const struct kernel_param *kp);#define param_check_ushort (name, p) __param_check(name, p, unsigned short) -extern struct kernel_param_ops param_ops_int; +extern const struct kernel_param_ops param_ops_int;extern int param_set_int (const char *val,const struct kernel_param *kp);extern int param_get_int (char *buffer,const struct kernel_param *kp);#define param_check_int (name, p) __param_check(name, p, int) -extern struct kernel_param_ops param_ops_uint; +extern const struct kernel_param_ops param_ops_uint;extern int param_set_uint (const char *val,const struct kernel_param *kp);extern int param_get_uint (char *buffer,const struct kernel_param *kp);#define param_check_uint (name, p) __param_check(name, p, unsigned int) -extern struct kernel_param_ops param_ops_long; +extern const struct kernel_param_ops param_ops_long;extern int param_set_long (const char *val,const struct kernel_param *kp);extern int param_get_long (char *buffer,const struct kernel_param *kp);#define param_check_long (name, p) __param_check(name, p, long) -extern struct kernel_param_ops param_ops_ulong; +extern const struct kernel_param_ops param_ops_ulong;extern int param_set_ulong (const char *val,const struct kernel_param *kp);extern int param_get_ulong (char *buffer,const struct kernel_param *kp);#define param_check_ulong (name, p) __param_check(name, p, unsigned long) -extern struct kernel_param_ops param_ops_ullong; +extern const struct kernel_param_ops param_ops_ullong;extern int param_set_ullong (const char *val,const struct kernel_param *kp);extern int param_get_ullong (char *buffer,const struct kernel_param *kp);#define param_check_ullong (name, p) __param_check(name, p, unsigned long long) -extern struct kernel_param_ops param_ops_charp; +extern const struct kernel_param_ops param_ops_charp;extern int param_set_charp (const char *val,const struct kernel_param *kp);extern int param_get_charp (char *buffer,const struct kernel_param *kp);#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 struct kernel_param_ops param_ops_bool; +extern const struct kernel_param_ops param_ops_bool;extern int param_set_bool (const char *val,const struct kernel_param *kp);extern int param_get_bool (char *buffer,const struct kernel_param *kp);#define param_check_bool (name, p) __param_check(name, p, bool) -extern struct kernel_param_ops param_ops_invbool; +extern const struct kernel_param_ops param_ops_invbool;extern int param_set_invbool (const char *val,const struct kernel_param *kp);extern int param_get_invbool (char *buffer,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). */ -extern struct kernel_param_ops param_ops_bint; +extern const struct kernel_param_ops param_ops_bint;extern int param_set_bint (const char *val,const struct kernel_param *kp);#define param_get_bint param_get_int#define param_check_bint param_check_int
@@ -477,9 +477,9 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp); perm, -1, 0); \ __MODULE_PARM_TYPE(name, "array of " #type) -extern struct kernel_param_ops param_array_ops; +extern const struct kernel_param_ops param_array_ops; -extern struct kernel_param_ops param_ops_string; +extern const struct kernel_param_ops param_ops_string;extern int param_set_copystring (const char *val,const struct kernel_param *);extern int param_get_string (char *buffer,const struct kernel_param *kp);
kernel/params.c +7 -7
@@ -251,7 +251,7 @@ char *parse_args(const char *doing,return scnprintf (buffer,PAGE_SIZE , format, \ *((type *)kp->arg)); \ } \ - struct kernel_param_ops param_ops_##name = { \ + const struct kernel_param_ops param_ops_##name = { \ .set = param_set_##name, \ .get = param_get_##name, \ }; \
@@ -303,7 +303,7 @@ static void param_free_charp(void *arg)maybe_kfree_parameter (*((char **)arg)); } -struct kernel_param_ops param_ops_charp = { +const struct kernel_param_ops param_ops_charp = { .set = param_set_charp, .get = param_get_charp, .free = param_free_charp,
@@ -328,7 +328,7 @@ int param_get_bool(char *buffer, const struct kernel_param *kp) }EXPORT_SYMBOL (param_get_bool); -struct kernel_param_ops param_ops_bool = { +const struct kernel_param_ops param_ops_bool = { .flags =KERNEL_PARAM_OPS_FL_NOARG , .set = param_set_bool, .get = param_get_bool,
@@ -356,7 +356,7 @@ int param_get_invbool(char *buffer, const struct kernel_param *kp) }EXPORT_SYMBOL (param_get_invbool); -struct kernel_param_ops param_ops_invbool = { +const struct kernel_param_ops param_ops_invbool = { .set = param_set_invbool, .get = param_get_invbool, };
@@ -379,7 +379,7 @@ int param_set_bint(const char *val, const struct kernel_param *kp) }EXPORT_SYMBOL (param_set_bint); -struct kernel_param_ops param_ops_bint = { +const struct kernel_param_ops param_ops_bint = { .flags =KERNEL_PARAM_OPS_FL_NOARG , .set = param_set_bint, .get = param_get_int,
@@ -476,7 +476,7 @@ static void param_array_free(void *arg) arr->ops->free (arr->elem + arr->elemsize * i); } -struct kernel_param_ops param_array_ops = { +const struct kernel_param_ops param_array_ops = { .set = param_array_set, .get = param_array_get, .free = param_array_free,
@@ -504,7 +504,7 @@ int param_get_string(char *buffer, const struct kernel_param *kp) }EXPORT_SYMBOL (param_get_string); -struct kernel_param_ops param_ops_string = { +const struct kernel_param_ops param_ops_string = { .set = param_set_copystring, .get = param_get_string, };
net/sunrpc/auth.c +1 -1
@@ -72,7 +72,7 @@ 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 struct kernel_param_ops param_ops_hashtbl_sz = { +static const struct kernel_param_ops param_ops_hashtbl_sz = { .set = param_set_hashtbl_sz, .get = param_get_hashtbl_sz, };
net/sunrpc/xprtsock.c +3 -3
@@ -2982,7 +2982,7 @@ static int param_set_portnr(const char *val, const struct kernel_param *kp) RPC_MAX_RESVPORT); } -static struct kernel_param_ops param_ops_portnr = { +static const struct kernel_param_ops param_ops_portnr = { .set = param_set_portnr, .get = param_get_uint, };
@@ -3001,7 +3001,7 @@ static int param_set_slot_table_size(const char *val, RPC_MAX_SLOT_TABLE); } -static struct kernel_param_ops param_ops_slot_table_size = { +static const struct kernel_param_ops param_ops_slot_table_size = { .set = param_set_slot_table_size, .get = param_get_uint, };
@@ -3017,7 +3017,7 @@ static int param_set_max_slot_table_size(const char *val, RPC_MAX_SLOT_TABLE_LIMIT); } -static struct kernel_param_ops param_ops_max_slot_table_size = { +static const struct kernel_param_ops param_ops_max_slot_table_size = { .set = param_set_max_slot_table_size, .get = param_get_uint, };
security/apparmor/lsm.c +3 -3
@@ -667,7 +667,7 @@ static struct security_operations apparmor_ops = {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 struct kernel_param_ops param_ops_aabool = { +static const struct kernel_param_ops param_ops_aabool = { .flags =KERNEL_PARAM_OPS_FL_NOARG , .set = param_set_aabool, .get = param_get_aabool
@@ -676,7 +676,7 @@ static struct kernel_param_ops param_ops_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 struct kernel_param_ops param_ops_aauint = { +static const struct kernel_param_ops param_ops_aauint = { .set = param_set_aauint, .get = param_get_aauint };
@@ -684,7 +684,7 @@ static struct kernel_param_ops param_ops_aauint = {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 struct kernel_param_ops param_ops_aalockpolicy = { +static const struct kernel_param_ops param_ops_aalockpolicy = { .flags =KERNEL_PARAM_OPS_FL_NOARG , .set = param_set_aalockpolicy, .get = param_get_aalockpolicy
security/integrity/ima/ima_crypto.c +1 -1
@@ -55,7 +55,7 @@ static int param_set_bufsize(const char *val, const struct kernel_param *kp)return 0 ; } -static struct kernel_param_ops param_ops_bufsize = { +static const struct kernel_param_ops param_ops_bufsize = { .set = param_set_bufsize, .get = param_get_uint, };
sound/pci/hda/hda_intel.c +1 -1
@@ -166,7 +166,7 @@ MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode "#ifdef CONFIG_PM static int param_set_xint (const char *val,const struct kernel_param *kp); -static struct kernel_param_ops param_ops_xint = { +static const struct kernel_param_ops param_ops_xint = { .set = param_set_xint, .get = param_get_int, };
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v2 2/8 kernel/module.c: use generic module param operaters for sig_enforce
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
We're directly checking and modifying sig_enforce when needed instead of using the generic helpers. This prevents us from generalizing this helper so that others can use it. Use indirect helpers to allow us to generalize this code a bit and to make it a bit more clear what this is doing.
--- kernel/module.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
kernel/module.c +9 -7
@@ -114,23 +114,25 @@ static bool sig_enforce = false;static int param_set_bool_enable_only (const char *val,const struct kernel_param *kp) { -int err; -bool test; +int err =0 ; +bool new_value; +bool orig_value = *(bool *)kp->arg;struct kernel_param dummy_kp = *kp; - dummy_kp.arg = &test; + dummy_kp.arg = &new_value; err =param_set_bool (val, &dummy_kp);if (err)return err;/* Don't let them unset it once it's set! */ -if (!test && sig_enforce) +if (!new_value && orig_value)return -EROFS ; -if (test) - sig_enforce = true; -return 0 ; +if (new_value) + err =param_set_bool (val, kp); + +return err; }static const struct kernel_param_ops param_ops_bool_enable_only = {
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v2 3/8 kernel/params.c: generalize bool_enable_only
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This takes out the bool_enable_only implementation from the module loading code and generalizes it so that others can make use of it.
--- include/linux/moduleparam.h | 6 ++++++ kernel/module.c | 31 ------------------------------- kernel/params.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 31 deletions(-)
include/linux/moduleparam.h +6 -0
@@ -427,6 +427,12 @@ extern int param_set_bool(const char *val, const struct kernel_param *kp);extern int param_get_bool (char *buffer,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; +extern int param_set_bool_enable_only (const char *val, +const struct kernel_param *kp); +/* getter is the same as for the regular bool */ +#define param_check_bool_enable_only param_check_bool +extern const struct kernel_param_ops param_ops_invbool;extern int param_set_invbool (const char *val,const struct kernel_param *kp);extern int param_get_invbool (char *buffer,const struct kernel_param *kp);
kernel/module.c +0 -31
@@ -111,37 +111,6 @@ static bool sig_enforce = true;#else static bool sig_enforce = false; -static int param_set_bool_enable_only (const char *val, -const struct kernel_param *kp) -{ -int err =0 ; -bool new_value; -bool orig_value = *(bool *)kp->arg; -struct kernel_param dummy_kp = *kp; - - dummy_kp.arg = &new_value; - - err =param_set_bool (val, &dummy_kp); -if (err) -return err; - -/* Don't let them unset it once it's set! */ -if (!new_value && orig_value) -return -EROFS ; - -if (new_value) - err =param_set_bool (val, kp); - -return err; -} - -static 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 param_check_bool_enable_only param_check_bool -module_param (sig_enforce, bool_enable_only,0644 );#endif /* !CONFIG_MODULE_SIG_FORCE */ #endif /* CONFIG_MODULE_SIG */
kernel/params.c +30 -0
@@ -335,6 +335,36 @@ const struct kernel_param_ops param_ops_bool = { };EXPORT_SYMBOL (param_ops_bool); +int param_set_bool_enable_only (const char *val,const struct kernel_param *kp) +{ +int err =0 ; +bool new_value; +bool orig_value = *(bool *)kp->arg; +struct kernel_param dummy_kp = *kp; + + dummy_kp.arg = &new_value; + + err =param_set_bool (val, &dummy_kp); +if (err) +return err; + +/* Don't let them unset it once it's set! */ +if (!new_value && orig_value) +return -EROFS ; + +if (new_value) + err =param_set_bool (val, kp); + +return err; +} +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, +}; +/* This one must be bool. */ int param_set_invbool (const char *val,const struct kernel_param *kp) {
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v2 4/8 moduleparam.h: add module_param_config_*() helpers
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This adds a couple of bool module_param_config_*() helpers which are designed to let us easily associate a boolean module parameter with an associated kernel configuration option. Folks can use this to avoid what typically would be #ifdef eyesores around module parameter declarations.
--- include/linux/moduleparam.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
include/linux/moduleparam.h +37 -0
@@ -155,6 +155,43 @@ struct kparam_array __MODULE_PARM_TYPE(name, #type)/** +* module_param_config_on_off - bool parameter with run time override +* @name: a valid C identifier which is the parameter name. +* @value: the actual lvalue to alter. +* @perm: visibility in sysfs. +* @config: kernel parameter which will enable this option if this +* kernel configuration option has been enabled. +* +* This lets you define a bool module parameter which by default will be +* set to true if the config option has been set on your kernel's +* configuration, otherwise it is set to false. +*/ +#define module_param_config_on_off (name, var, perm, config) \ + static bool var = IS_ENABLED(config); \ + module_param_named(name, var, bool, perm); + +/** +* module_param_config_on - bool parameter with run time enablement override +* @name: a valid C identifier which is the parameter name. +* @value: the actual lvalue to alter. +* @perm: visibility in sysfs. +* @config: kernel parameter which will enable this option if this +* kernel configuration option has been enabled. +* +* This lets you define a bool module parameter which by default will be +* set to true if the config option has been set on your kernel's +* configuration, otherwise it is set to false. This particular helper +* will ensure that if the kernel configuration has been set you will not +* be able to disable this kernel parameter. You can only use this to let +* the an option that was disabled on your kernel configuration be enabled +* at run time. +*/ +#define module_param_config_on (name, var, perm, config) \ + static bool var = IS_ENABLED(config); \ + module_param_named(name, var, bool_enable_only, perm); + + +/** * module_param_cb - general callback for a module/cmdline parameter * @name: a valid C identifier which is the parameter name. * @ops: the set & get operations for this parameter.
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v2 5/8 kernel/workqueue.c: remove ifdefs over wq_power_efficient
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
We can avoid an ifdef over wq_power_efficient's declaration by just using IS_ENABLED().
--- kernel/workqueue.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
kernel/workqueue.c +1 -6
@@ -280,12 +280,7 @@ static bool wq_disable_numa;module_param_named (disable_numa, wq_disable_numa, bool,0444 );/* see the comment above the definition of WQ_POWER_EFFICIENT */ -#ifdef CONFIG_WQ_POWER_EFFICIENT_DEFAULT -static bool wq_power_efficient = true; -#else -static bool wq_power_efficient; -#endif - +static bool wq_power_efficient =IS_ENABLED (CONFIG_WQ_POWER_EFFICIENT_DEFAULT );module_param_named (power_efficient, wq_power_efficient, bool,0444 );static bool wq_numa_enabled;/* unbound NUMA affinity enabled */
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v2 6/8 kernel/workqueue.c: use module_param_config_on_off() for power_efficient
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
Use the new module_param_config_on_off() for setting / disabling of CONFIG_WQ_POWER_EFFICIENT_DEFAULT.
--- kernel/workqueue.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/workqueue.c +1 -2
@@ -280,8 +280,7 @@ static bool wq_disable_numa;module_param_named (disable_numa, wq_disable_numa, bool,0444 );/* see the comment above the definition of WQ_POWER_EFFICIENT */ -static bool wq_power_efficient =IS_ENABLED (CONFIG_WQ_POWER_EFFICIENT_DEFAULT ); -module_param_named (power_efficient, wq_power_efficient, bool,0444 ); +module_param_config_on_off (power_efficient, wq_power_efficient,0444 ,CONFIG_WQ_POWER_EFFICIENT_DEFAULT );static bool wq_numa_enabled;/* unbound NUMA affinity enabled */
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v2 7/8 kernel/module.c: avoid ifdefs for sig_enforce declaration
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
There's no need to require an ifdef over the declaration of sig_enforce as IS_ENABLED() can be used. While at it, there's no harm in exposing this kernel parameter outside of CONFIG_MODULE_SIG as it'd be a no-op on non module sig kernels.
Now, technically we should in theory be able to remove the #ifdef'ery over the declaration of the module parameter as we are also trusting the bool_enable_only code for CONFIG_MODULE_SIG kernels but for now remain paranoid and keep it.
With time if no one can put a bullet through bool_enable_only and if there are no technical requirements over not exposing CONFIG_MODULE_SIG_FORCE with the measures in place by bool_enable_only we could remove this last ifdef.
--- kernel/module.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
kernel/module.c +2 -7
@@ -105,15 +105,10 @@ static LIST_HEAD(modules);struct list_head *kdb_modules = &modules;/* kdb needs the list of modules */ #endif /* CONFIG_KGDB_KDB */ -#ifdef CONFIG_MODULE_SIG -#ifdef CONFIG_MODULE_SIG_FORCE -static bool sig_enforce = true; -#else -static bool sig_enforce = false; - +static bool sig_enforce =IS_ENABLED (CONFIG_MODULE_SIG_FORCE ); +#ifndef CONFIG_MODULE_SIG_FORCE module_param (sig_enforce, bool_enable_only,0644 );#endif /* !CONFIG_MODULE_SIG_FORCE */ -#endif /* CONFIG_MODULE_SIG */ /* Block module loading/unloading? */ int modules_disabled =0 ;
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v2 8/8 kernel/module.c: use module_param_config_on() for sig_enforce
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
--- kernel/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/module.c +1 -1
@@ -107,7 +107,7 @@ struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */static bool sig_enforce =IS_ENABLED (CONFIG_MODULE_SIG_FORCE );#ifndef CONFIG_MODULE_SIG_FORCE -module_param (sig_enforce, bool_enable_only,0644 ); +module_param_config_on (sig_enforce, sig_enforce,0644 ,CONFIG_MODULE_SIG_FORCE );#endif /* !CONFIG_MODULE_SIG_FORCE */ /* Block module loading/unloading? */
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Re: [PATCH v2 4/8] moduleparam.h: add module_param_config_*() helpers
In reply to Luis R. RodriguezQuoted 6 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This adds a couple of bool module_param_config_*() helpers which are designed to let us easily associate a boolean module parameter with an associated kernel configuration option.
OK.
Quoted 2 lines
Folks can use this to avoid what typically would be #ifdef eyesores around module parameter declarations.
Really? So you use this in two patches:
/* see the comment above the definition of WQ_POWER_EFFICIENT */
-static bool wq_power_efficient = IS_ENABLED(CONFIG_WQ_POWER_EFFICIENT_DEFAULT); -module_param_named(power_efficient, wq_power_efficient, bool, 0444); +module_param_config_on_off(power_efficient, wq_power_efficient, 0444, CONFIG_WQ_POWER_EFFICIENT_DEFAULT);
And:
static bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE); #ifndef CONFIG_MODULE_SIG_FORCE
-module_param(sig_enforce, bool_enable_only, 0644); +module_param_config_on(sig_enforce, sig_enforce, 0644, CONFIG_MODULE_SIG_FORCE);
#endif /* !CONFIG_MODULE_SIG_FORCE */
But neither actually, y'know, cleans up any #ifdefs.
Simplicity is a major virtue. Readability is a major virtue. Brevity is only a minor virtue.
So I have applied the following patches:
[PATCH v2 1/8] kernel/params: constify struct kernel_param_ops uses [PATCH v2 2/8] kernel/module.c: use generic module param operaters for sig_enforce [PATCH v2 3/8] kernel/params.c: generalize bool_enable_only
[PATCH v2 5/8] kernel/workqueue.c: remove ifdefs over wq_power_efficient [PATCH v2 7/8] kernel/module.c: avoid ifdefs for sig_enforce declaration
Thanks,
Rusty.
Tejun Heo
maintainerRe: [PATCH v2 3/8] kernel/params.c: generalize bool_enable_only
In reply to Luis R. RodriguezHello,
Quoted 6 lines · Luis R. Rodriguez
kernel/params.c +6
-0+int param_set_bool_enable_only (const char *val,const struct kernel_param *kp) +{ +int err =0 ; +bool new_value; +bool orig_value = *(bool *)kp->arg; +struct kernel_param dummy_kp = *kp;
kernel/params.c const struct kernel_param_ops param_ops_bool = { · line 353
Quoted 10 lines
kernel/params.c +10
-0+ + dummy_kp.arg = &new_value; + + err =param_set_bool (val, &dummy_kp); +if (err) +return err; + +/* Don't let them unset it once it's set! */ +if (!new_value && orig_value) +return -EROFS ;
I know that this was moved from another place but as we're making it generic now I'm a bit curious about -EROFS. Wouldn't -EINVAL be a more conventional choice here?
Thanks.
Signature · 1 line
tejun
Re: [PATCH v2 3/8] kernel/params.c: generalize bool_enable_only
Quoted 15 lines · Tejun Heo
Hello,
Quoted 12 lines · Luis R. Rodriguez
kernel/params.c +12
-0+int param_set_bool_enable_only (const char *val,const struct kernel_param *kp) +{ +int err =0 ; +bool new_value; +bool orig_value = *(bool *)kp->arg; +struct kernel_param dummy_kp = *kp; + + dummy_kp.arg = &new_value; + + err =param_set_bool (val, &dummy_kp); +if (err) +return err;
Quoted 8 lines
kernel/params.c const struct kernel_param_ops param_ops_bool = { · line 353
Quoted 4 lines
kernel/params.c +4
-0+ +/* Don't let them unset it once it's set! */ +if (!new_value && orig_value) +return -EROFS ;I know that this was moved from another place but as we're making it generic now I'm a bit curious about
-EROFS. Wouldn't-EINVALbe a more conventional choice here?
Let's see, I tested to see what errors we get:
Userspace:
-EROFS:
mcgrof@ergon ~/devel/test-sig-force-general $ sudo insmod ./hello.ko test_sig_enforce=1
insmod: ERROR: could not insert module ./hello.ko: Read-only file system
-EINVAL:
mcgrof@ergon ~/devel/test-sig-force-general $ sudo insmod ./hello.ko test_sig_enforce=1
insmod: ERROR: could not insert module ./hello.ko: Invalid parameters
Kernel space:
Both of these returns yield this on the kernel ring buffer:
mcgrof@ergon ~/devel/test-sig-force-general $ sudo dmesg -c
[124677.202875] hello: `1' invalid for parameter `test_sig_enforce'
Alternative candidates:
#define EBADRQC 56 /* Invalid request code */ #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
Perhaps EOPNOTSUPP is best?
Luis
Re: [PATCH v2 4/8] moduleparam.h: add module_param_config_*() helpers
In reply to Rusty RussellQuoted 9 lines · Rusty Russell
Quoted 6 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This adds a couple of bool module_param_config_*() helpers which are designed to let us easily associate a boolean module parameter with an associated kernel configuration option.
OK.
So this is really the main gain.
Quoted 12 lines
Quoted 2 lines
Folks can use this to avoid what typically would be #ifdef eyesores around module parameter declarations.
Really? So you use this in two patches:
/* see the comment above the definition of
WQ_POWER_EFFICIENT*/
-static boolwq_power_efficient=IS_ENABLED(CONFIG_WQ_POWER_EFFICIENT_DEFAULT); -module_param_named(power_efficient,wq_power_efficient, bool, 0444); +module_param_config_on_off(power_efficient,wq_power_efficient, 0444,CONFIG_WQ_POWER_EFFICIENT_DEFAULT);And:
Quoted 7 lines
static bool
sig_enforce=IS_ENABLED(CONFIG_MODULE_SIG_FORCE); #ifndefCONFIG_MODULE_SIG_FORCE
-module_param(sig_enforce,bool_enable_only, 0644); +module_param_config_on(sig_enforce,sig_enforce, 0644,CONFIG_MODULE_SIG_FORCE);
#endif /* !CONFIG_MODULE_SIG_FORCE */But neither actually, y'know, cleans up any #ifdefs.
OK, sure, its the use of IS_ENABLED() that does that as a first step.
Quoted 2 lines
Simplicity is a major virtue. Readability is a major virtue. Brevity is only a minor virtue.
I was not shooting for brevity but instead aiming at the possible grammatical gain of direct and immediate association between a bool, behaviour (on_off, or just on), and a config. I don't have a need for the grammatical association now so will drop this.
Luis