Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

module_param: avoid bool abuse, add bint for special cases.

For historical reasons, we allow module_param(bool) to take an int (or
an unsigned int). That's going away.

A few drivers really want an int: they set it to -1 and a parameter
will set it to 0 or 1. This sucks: reading them from sysfs will give
'Y' for both -1 and 1, but if we change it to an int, then the users
might be broken (if they did "param" instead of "param=1").

Use a new 'bint' parser for them.

(ntfs has a different problem: it needs an int for debug_msgs because
it's also exposed via sysctl.)

Cc: Steve Glendinning <steve.glendinning@smsc.com>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: Guenter Roeck <guenter.roeck@ericsson.com>
Cc: Hoang-Nam Nguyen <hnguyen@de.ibm.com>
Cc: Christoph Raisch <raisch@de.ibm.com>
Cc: Roland Dreier <roland@kernel.org>
Cc: Sean Hefty <sean.hefty@intel.com>
Cc: Hal Rosenstock <hal.rosenstock@gmail.com>
Cc: linux390@de.ibm.com
Cc: Anton Altaparmakov <anton@tuxera.com>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: lm-sensors@lm-sensors.org
Cc: linux-rdma@vger.kernel.org
Cc: linux-s390@vger.kernel.org
Cc: linux-ntfs-dev@lists.sourceforge.net
Cc: alsa-devel@alsa-project.org
Acked-by: Takashi Iwai <tiwai@suse.de> (For the sound part)
Acked-by: Guenter Roeck <guenter.roeck@ericsson.com> (For the hwmon driver)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

+36 -6
+1 -1
drivers/hwmon/emc2103.c
··· 55 55 * it. Default is to leave the device in the state it's already in (-1). 56 56 * This parameter allows APD mode to be optionally forced on or off */ 57 57 static int apd = -1; 58 - module_param(apd, bool, 0); 58 + module_param(apd, bint, 0); 59 59 MODULE_PARM_DESC(init, "Set to zero to disable anti-parallel diode mode"); 60 60 61 61 struct temperature {
+1 -1
drivers/infiniband/hw/ehca/ehca_main.c
··· 82 82 module_param_named(poll_all_eqs, ehca_poll_all_eqs, bool, S_IRUGO); 83 83 module_param_named(static_rate, ehca_static_rate, int, S_IRUGO); 84 84 module_param_named(scaling_code, ehca_scaling_code, bool, S_IRUGO); 85 - module_param_named(lock_hcalls, ehca_lock_hcalls, bool, S_IRUGO); 85 + module_param_named(lock_hcalls, ehca_lock_hcalls, bint, S_IRUGO); 86 86 module_param_named(number_of_cqs, ehca_max_cq, int, S_IRUGO); 87 87 module_param_named(number_of_qps, ehca_max_qp, int, S_IRUGO); 88 88
+1 -1
drivers/s390/cio/cmf.c
··· 98 98 * enum cmb_format. 99 99 */ 100 100 static int format = CMF_AUTODETECT; 101 - module_param(format, bool, 0444); 101 + module_param(format, bint, 0444); 102 102 103 103 /** 104 104 * struct cmb_operations - functions to use depending on cmb_format
+1 -1
fs/ntfs/super.c
··· 3198 3198 MODULE_VERSION(NTFS_VERSION); 3199 3199 MODULE_LICENSE("GPL"); 3200 3200 #ifdef DEBUG 3201 - module_param(debug_msgs, bool, 0); 3201 + module_param(debug_msgs, bint, 0); 3202 3202 MODULE_PARM_DESC(debug_msgs, "Enable debug messages."); 3203 3203 #endif 3204 3204
+6
include/linux/moduleparam.h
··· 367 367 extern int param_get_invbool(char *buffer, const struct kernel_param *kp); 368 368 #define param_check_invbool(name, p) __param_check(name, p, bool) 369 369 370 + /* An int, which can only be set like a bool (though it shows as an int). */ 371 + extern struct kernel_param_ops param_ops_bint; 372 + extern int param_set_bint(const char *val, const struct kernel_param *kp); 373 + #define param_get_bint param_get_int 374 + #define param_check_bint param_check_int 375 + 370 376 /** 371 377 * module_param_array - a parameter which is an array of some type 372 378 * @name: the name of the array variable
+24
kernel/params.c
··· 363 363 }; 364 364 EXPORT_SYMBOL(param_ops_invbool); 365 365 366 + int param_set_bint(const char *val, const struct kernel_param *kp) 367 + { 368 + struct kernel_param boolkp; 369 + bool v; 370 + int ret; 371 + 372 + /* Match bool exactly, by re-using it. */ 373 + boolkp = *kp; 374 + boolkp.arg = &v; 375 + boolkp.flags |= KPARAM_ISBOOL; 376 + 377 + ret = param_set_bool(val, &boolkp); 378 + if (ret == 0) 379 + *(int *)kp->arg = v; 380 + return ret; 381 + } 382 + EXPORT_SYMBOL(param_set_bint); 383 + 384 + struct kernel_param_ops param_ops_bint = { 385 + .set = param_set_bint, 386 + .get = param_get_int, 387 + }; 388 + EXPORT_SYMBOL(param_ops_bint); 389 + 366 390 /* We break the rule and mangle the string. */ 367 391 static int param_array(const char *name, 368 392 const char *val,
+2 -2
sound/pci/intel8x0.c
··· 95 95 MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); 96 96 module_param(buggy_semaphore, bool, 0444); 97 97 MODULE_PARM_DESC(buggy_semaphore, "Enable workaround for hardwares with problematic codec semaphores."); 98 - module_param(buggy_irq, bool, 0444); 98 + module_param(buggy_irq, bint, 0444); 99 99 MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards."); 100 100 module_param(xbox, bool, 0444); 101 101 MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection."); 102 102 module_param(spdif_aclink, int, 0444); 103 103 MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link."); 104 - module_param(inside_vm, bool, 0444); 104 + module_param(inside_vm, bint, 0444); 105 105 MODULE_PARM_DESC(inside_vm, "KVM/Parallels optimization."); 106 106 107 107 /* just for backward compatibility */