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

Merge branch 'params' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus

* 'params' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus: (22 commits)
param: don't deref arg in __same_type() checks
param: update drivers/acpi/debug.c to new scheme
param: use module_param in drivers/message/fusion/mptbase.c
ide: use module_param_named rather than module_param_call
param: update drivers/char/ipmi/ipmi_watchdog.c to new scheme
param: lock if_sdio's lbs_helper_name and lbs_fw_name against sysfs changes.
param: lock myri10ge_fw_name against sysfs changes.
param: simple locking for sysfs-writable charp parameters
param: remove unnecessary writable charp
param: add kerneldoc to moduleparam.h
param: locking for kernel parameters
param: make param sections const.
param: use free hook for charp (fix leak of charp parameters)
param: add a free hook to kernel_param_ops.
param: silence .init.text references from param ops
Add param ops struct for hvc_iucv driver.
nfs: update for module_param_named API change
AppArmor: update for module_param_named API change
param: use ops in struct kernel_param, rather than get and set fns directly
param: move the EXPORT_SYMBOL to after the definitions.
...

+658 -253
+1 -1
Documentation/cpu-hotplug.txt
··· 2 2 3 3 Maintainers: 4 4 CPU Hotplug Core: 5 - Rusty Russell <rusty@rustycorp.com.au> 5 + Rusty Russell <rusty@rustcorp.com.au> 6 6 Srivatsa Vaddagiri <vatsa@in.ibm.com> 7 7 i386: 8 8 Zwane Mwaikambo <zwane@arm.linux.org.uk>
+10
arch/um/drivers/hostaudio_kern.c
··· 187 187 int ret; 188 188 189 189 #ifdef DEBUG 190 + kparam_block_sysfs_write(dsp); 190 191 printk(KERN_DEBUG "hostaudio: open called (host: %s)\n", dsp); 192 + kparam_unblock_sysfs_write(dsp); 191 193 #endif 192 194 193 195 state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL); ··· 201 199 if (file->f_mode & FMODE_WRITE) 202 200 w = 1; 203 201 202 + kparam_block_sysfs_write(dsp); 204 203 lock_kernel(); 205 204 ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0); 206 205 unlock_kernel(); 206 + kparam_unblock_sysfs_write(dsp); 207 207 208 208 if (ret < 0) { 209 209 kfree(state); ··· 262 258 if (file->f_mode & FMODE_WRITE) 263 259 w = 1; 264 260 261 + kparam_block_sysfs_write(mixer); 265 262 lock_kernel(); 266 263 ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0); 267 264 unlock_kernel(); 265 + kparam_unblock_sysfs_write(mixer); 268 266 269 267 if (ret < 0) { 268 + kparam_block_sysfs_write(dsp); 270 269 printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', " 271 270 "err = %d\n", dsp, -ret); 271 + kparam_unblock_sysfs_write(dsp); 272 272 kfree(state); 273 273 return ret; 274 274 } ··· 328 320 329 321 static int __init hostaudio_init_module(void) 330 322 { 323 + __kernel_param_lock(); 331 324 printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n", 332 325 dsp, mixer); 326 + __kernel_param_unlock(); 333 327 334 328 module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1); 335 329 if (module_data.dev_audio < 0) {
+24 -8
drivers/acpi/debug.c
··· 96 96 /* -------------------------------------------------------------------------- 97 97 FS Interface (/sys) 98 98 -------------------------------------------------------------------------- */ 99 - static int param_get_debug_layer(char *buffer, struct kernel_param *kp) { 99 + static int param_get_debug_layer(char *buffer, const struct kernel_param *kp) 100 + { 100 101 int result = 0; 101 102 int i; 102 103 ··· 119 118 return result; 120 119 } 121 120 122 - static int param_get_debug_level(char *buffer, struct kernel_param *kp) { 121 + static int param_get_debug_level(char *buffer, const struct kernel_param *kp) 122 + { 123 123 int result = 0; 124 124 int i; 125 125 ··· 139 137 return result; 140 138 } 141 139 142 - module_param_call(debug_layer, param_set_uint, param_get_debug_layer, &acpi_dbg_layer, 0644); 143 - module_param_call(debug_level, param_set_uint, param_get_debug_level, &acpi_dbg_level, 0644); 140 + static struct kernel_param_ops acpi_debug_layer_ops = { 141 + .set = param_set_uint, 142 + .get = param_get_debug_layer, 143 + }; 144 + 145 + static struct kernel_param_ops acpi_debug_level_ops = { 146 + .set = param_set_uint, 147 + .get = param_get_debug_level, 148 + }; 149 + 150 + module_param_cb(debug_layer, &acpi_debug_layer_ops, &acpi_dbg_layer, 0644); 151 + module_param_cb(debug_level, &acpi_debug_level_ops, &acpi_dbg_level, 0644); 144 152 145 153 static char trace_method_name[6]; 146 154 module_param_string(trace_method_name, trace_method_name, 6, 0644); ··· 159 147 static unsigned int trace_debug_level; 160 148 module_param(trace_debug_level, uint, 0644); 161 149 162 - static int param_set_trace_state(const char *val, struct kernel_param *kp) 150 + static int param_set_trace_state(const char *val, const struct kernel_param *kp) 163 151 { 164 152 int result = 0; 165 153 ··· 193 181 return result; 194 182 } 195 183 196 - static int param_get_trace_state(char *buffer, struct kernel_param *kp) 184 + static int param_get_trace_state(char *buffer, const struct kernel_param *kp) 197 185 { 198 186 if (!acpi_gbl_trace_method_name) 199 187 return sprintf(buffer, "disable"); ··· 206 194 return 0; 207 195 } 208 196 209 - module_param_call(trace_state, param_set_trace_state, param_get_trace_state, 210 - NULL, 0644); 197 + static struct kernel_param_ops param_ops_trace_state = { 198 + .set = param_set_trace_state, 199 + .get = param_get_trace_state, 200 + }; 201 + 202 + module_param_cb(trace_state, &param_ops_trace_state, NULL, 0644); 211 203 212 204 /* -------------------------------------------------------------------------- 213 205 DebugFS Interface
+7 -2
drivers/char/hvc_iucv.c
··· 1149 1149 * Note: If it is called early in the boot process, @val is stored and 1150 1150 * parsed later in hvc_iucv_init(). 1151 1151 */ 1152 - static int param_set_vmidfilter(const char *val, struct kernel_param *kp) 1152 + static int param_set_vmidfilter(const char *val, const struct kernel_param *kp) 1153 1153 { 1154 1154 int rc; 1155 1155 ··· 1176 1176 * The function stores the filter as a comma-separated list of z/VM user IDs 1177 1177 * in @buffer. Typically, sysfs routines call this function for attr show. 1178 1178 */ 1179 - static int param_get_vmidfilter(char *buffer, struct kernel_param *kp) 1179 + static int param_get_vmidfilter(char *buffer, const struct kernel_param *kp) 1180 1180 { 1181 1181 int rc; 1182 1182 size_t index, len; ··· 1202 1202 } 1203 1203 1204 1204 #define param_check_vmidfilter(name, p) __param_check(name, p, void) 1205 + 1206 + static struct kernel_param_ops param_ops_vmidfilter = { 1207 + .set = param_set_vmidfilter, 1208 + .get = param_get_vmidfilter, 1209 + }; 1205 1210 1206 1211 /** 1207 1212 * hvc_iucv_init() - z/VM IUCV HVC device driver initialization
+27 -15
drivers/char/ipmi/ipmi_watchdog.c
··· 196 196 */ 197 197 static int start_now; 198 198 199 - static int set_param_int(const char *val, struct kernel_param *kp) 199 + static int set_param_timeout(const char *val, const struct kernel_param *kp) 200 200 { 201 201 char *endp; 202 202 int l; ··· 215 215 return rv; 216 216 } 217 217 218 - static int get_param_int(char *buffer, struct kernel_param *kp) 219 - { 220 - return sprintf(buffer, "%i", *((int *)kp->arg)); 221 - } 218 + static struct kernel_param_ops param_ops_timeout = { 219 + .set = set_param_timeout, 220 + .get = param_get_int, 221 + }; 222 + #define param_check_timeout param_check_int 222 223 223 224 typedef int (*action_fn)(const char *intval, char *outval); 224 225 ··· 228 227 static int preop_op(const char *inval, char *outval); 229 228 static void check_parms(void); 230 229 231 - static int set_param_str(const char *val, struct kernel_param *kp) 230 + static int set_param_str(const char *val, const struct kernel_param *kp) 232 231 { 233 232 action_fn fn = (action_fn) kp->arg; 234 233 int rv = 0; ··· 252 251 return rv; 253 252 } 254 253 255 - static int get_param_str(char *buffer, struct kernel_param *kp) 254 + static int get_param_str(char *buffer, const struct kernel_param *kp) 256 255 { 257 256 action_fn fn = (action_fn) kp->arg; 258 257 int rv; ··· 264 263 } 265 264 266 265 267 - static int set_param_wdog_ifnum(const char *val, struct kernel_param *kp) 266 + static int set_param_wdog_ifnum(const char *val, const struct kernel_param *kp) 268 267 { 269 268 int rv = param_set_int(val, kp); 270 269 if (rv) ··· 277 276 return 0; 278 277 } 279 278 280 - module_param_call(ifnum_to_use, set_param_wdog_ifnum, get_param_int, 281 - &ifnum_to_use, 0644); 279 + static struct kernel_param_ops param_ops_wdog_ifnum = { 280 + .set = set_param_wdog_ifnum, 281 + .get = param_get_int, 282 + }; 283 + 284 + #define param_check_wdog_ifnum param_check_int 285 + 286 + static struct kernel_param_ops param_ops_str = { 287 + .set = set_param_str, 288 + .get = get_param_str, 289 + }; 290 + 291 + module_param(ifnum_to_use, wdog_ifnum, 0644); 282 292 MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog " 283 293 "timer. Setting to -1 defaults to the first registered " 284 294 "interface"); 285 295 286 - module_param_call(timeout, set_param_int, get_param_int, &timeout, 0644); 296 + module_param(timeout, timeout, 0644); 287 297 MODULE_PARM_DESC(timeout, "Timeout value in seconds."); 288 298 289 - module_param_call(pretimeout, set_param_int, get_param_int, &pretimeout, 0644); 299 + module_param(pretimeout, timeout, 0644); 290 300 MODULE_PARM_DESC(pretimeout, "Pretimeout value in seconds."); 291 301 292 - module_param_call(action, set_param_str, get_param_str, action_op, 0644); 302 + module_param_cb(action, &param_ops_str, action_op, 0644); 293 303 MODULE_PARM_DESC(action, "Timeout action. One of: " 294 304 "reset, none, power_cycle, power_off."); 295 305 296 - module_param_call(preaction, set_param_str, get_param_str, preaction_op, 0644); 306 + module_param_cb(preaction, &param_ops_str, preaction_op, 0644); 297 307 MODULE_PARM_DESC(preaction, "Pretimeout action. One of: " 298 308 "pre_none, pre_smi, pre_nmi, pre_int."); 299 309 300 - module_param_call(preop, set_param_str, get_param_str, preop_op, 0644); 310 + module_param_cb(preop, &param_ops_str, preop_op, 0644); 301 311 MODULE_PARM_DESC(preop, "Pretimeout driver operation. One of: " 302 312 "preop_none, preop_panic, preop_give_data."); 303 313
+13 -7
drivers/ide/ide.c
··· 177 177 module_param_named(pci_clock, ide_pci_clk, int, 0); 178 178 MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)"); 179 179 180 - static int ide_set_dev_param_mask(const char *s, struct kernel_param *kp) 180 + static int ide_set_dev_param_mask(const char *s, const struct kernel_param *kp) 181 181 { 182 182 int a, b, i, j = 1; 183 183 unsigned int *dev_param_mask = (unsigned int *)kp->arg; ··· 200 200 return 0; 201 201 } 202 202 203 + static struct kernel_param_ops param_ops_ide_dev_mask = { 204 + .set = ide_set_dev_param_mask 205 + }; 206 + 207 + #define param_check_ide_dev_mask(name, p) param_check_uint(name, p) 208 + 203 209 static unsigned int ide_nodma; 204 210 205 - module_param_call(nodma, ide_set_dev_param_mask, NULL, &ide_nodma, 0); 211 + module_param_named(nodma, ide_nodma, ide_dev_mask, 0); 206 212 MODULE_PARM_DESC(nodma, "disallow DMA for a device"); 207 213 208 214 static unsigned int ide_noflush; 209 215 210 - module_param_call(noflush, ide_set_dev_param_mask, NULL, &ide_noflush, 0); 216 + module_param_named(noflush, ide_noflush, ide_dev_mask, 0); 211 217 MODULE_PARM_DESC(noflush, "disable flush requests for a device"); 212 218 213 219 static unsigned int ide_nohpa; 214 220 215 - module_param_call(nohpa, ide_set_dev_param_mask, NULL, &ide_nohpa, 0); 221 + module_param_named(nohpa, ide_nohpa, ide_dev_mask, 0); 216 222 MODULE_PARM_DESC(nohpa, "disable Host Protected Area for a device"); 217 223 218 224 static unsigned int ide_noprobe; 219 225 220 - module_param_call(noprobe, ide_set_dev_param_mask, NULL, &ide_noprobe, 0); 226 + module_param_named(noprobe, ide_noprobe, ide_dev_mask, 0); 221 227 MODULE_PARM_DESC(noprobe, "skip probing for a device"); 222 228 223 229 static unsigned int ide_nowerr; 224 230 225 - module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0); 231 + module_param_named(nowerr, ide_nowerr, ide_dev_mask, 0); 226 232 MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device"); 227 233 228 234 static unsigned int ide_cdroms; 229 235 230 - module_param_call(cdrom, ide_set_dev_param_mask, NULL, &ide_cdroms, 0); 236 + module_param_named(cdrom, ide_cdroms, ide_dev_mask, 0); 231 237 MODULE_PARM_DESC(cdrom, "force device as a CD-ROM"); 232 238 233 239 struct chs_geom {
+17 -9
drivers/input/misc/ati_remote2.c
··· 38 38 }; 39 39 40 40 static int ati_remote2_set_mask(const char *val, 41 - struct kernel_param *kp, unsigned int max) 41 + const struct kernel_param *kp, 42 + unsigned int max) 42 43 { 43 44 unsigned long mask; 44 45 int ret; ··· 60 59 } 61 60 62 61 static int ati_remote2_set_channel_mask(const char *val, 63 - struct kernel_param *kp) 62 + const struct kernel_param *kp) 64 63 { 65 64 pr_debug("%s()\n", __func__); 66 65 67 66 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK); 68 67 } 69 68 70 - static int ati_remote2_get_channel_mask(char *buffer, struct kernel_param *kp) 69 + static int ati_remote2_get_channel_mask(char *buffer, 70 + const struct kernel_param *kp) 71 71 { 72 72 pr_debug("%s()\n", __func__); 73 73 74 74 return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg); 75 75 } 76 76 77 - static int ati_remote2_set_mode_mask(const char *val, struct kernel_param *kp) 77 + static int ati_remote2_set_mode_mask(const char *val, 78 + const struct kernel_param *kp) 78 79 { 79 80 pr_debug("%s()\n", __func__); 80 81 81 82 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK); 82 83 } 83 84 84 - static int ati_remote2_get_mode_mask(char *buffer, struct kernel_param *kp) 85 + static int ati_remote2_get_mode_mask(char *buffer, 86 + const struct kernel_param *kp) 85 87 { 86 88 pr_debug("%s()\n", __func__); 87 89 ··· 93 89 94 90 static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK; 95 91 #define param_check_channel_mask(name, p) __param_check(name, p, unsigned int) 96 - #define param_set_channel_mask ati_remote2_set_channel_mask 97 - #define param_get_channel_mask ati_remote2_get_channel_mask 92 + static struct kernel_param_ops param_ops_channel_mask = { 93 + .set = ati_remote2_set_channel_mask, 94 + .get = ati_remote2_get_channel_mask, 95 + }; 98 96 module_param(channel_mask, channel_mask, 0644); 99 97 MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>"); 100 98 101 99 static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK; 102 100 #define param_check_mode_mask(name, p) __param_check(name, p, unsigned int) 103 - #define param_set_mode_mask ati_remote2_set_mode_mask 104 - #define param_get_mode_mask ati_remote2_get_mode_mask 101 + static struct kernel_param_ops param_ops_mode_mask = { 102 + .set = ati_remote2_set_mode_mask, 103 + .get = ati_remote2_get_mode_mask, 104 + }; 105 105 module_param(mode_mask, mode_mask, 0644); 106 106 MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>"); 107 107
+8 -6
drivers/input/mouse/psmouse-base.c
··· 39 39 MODULE_LICENSE("GPL"); 40 40 41 41 static unsigned int psmouse_max_proto = PSMOUSE_AUTO; 42 - static int psmouse_set_maxproto(const char *val, struct kernel_param *kp); 43 - static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp); 42 + static int psmouse_set_maxproto(const char *val, const struct kernel_param *); 43 + static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp); 44 + static struct kernel_param_ops param_ops_proto_abbrev = { 45 + .set = psmouse_set_maxproto, 46 + .get = psmouse_get_maxproto, 47 + }; 44 48 #define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int) 45 - #define param_set_proto_abbrev psmouse_set_maxproto 46 - #define param_get_proto_abbrev psmouse_get_maxproto 47 49 module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644); 48 50 MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches."); 49 51 ··· 1681 1679 } 1682 1680 1683 1681 1684 - static int psmouse_set_maxproto(const char *val, struct kernel_param *kp) 1682 + static int psmouse_set_maxproto(const char *val, const struct kernel_param *kp) 1685 1683 { 1686 1684 const struct psmouse_protocol *proto; 1687 1685 ··· 1698 1696 return 0; 1699 1697 } 1700 1698 1701 - static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp) 1699 + static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp) 1702 1700 { 1703 1701 int type = *((unsigned int *)kp->arg); 1704 1702
+1 -2
drivers/message/fusion/mptbase.c
··· 110 110 111 111 int mpt_fwfault_debug; 112 112 EXPORT_SYMBOL(mpt_fwfault_debug); 113 - module_param_call(mpt_fwfault_debug, param_set_int, param_get_int, 114 - &mpt_fwfault_debug, 0600); 113 + module_param(mpt_fwfault_debug, int, 0600); 115 114 MODULE_PARM_DESC(mpt_fwfault_debug, "Enable detection of Firmware fault" 116 115 " and halt Firmware on fault - (default=0)"); 117 116
+2 -2
drivers/misc/lkdtm.c
··· 124 124 module_param(recur_count, int, 0644); 125 125 MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test, "\ 126 126 "default is 10"); 127 - module_param(cpoint_name, charp, 0644); 127 + module_param(cpoint_name, charp, 0444); 128 128 MODULE_PARM_DESC(cpoint_name, " Crash Point, where kernel is to be crashed"); 129 - module_param(cpoint_type, charp, 0644); 129 + module_param(cpoint_type, charp, 0444); 130 130 MODULE_PARM_DESC(cpoint_type, " Crash Point Type, action to be taken on "\ 131 131 "hitting the crash point"); 132 132 module_param(cpoint_count, int, 0644);
+41 -13
drivers/net/myri10ge/myri10ge.c
··· 239 239 int watchdog_resets; 240 240 int watchdog_pause; 241 241 int pause; 242 + bool fw_name_allocated; 242 243 char *fw_name; 243 244 char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE]; 244 245 char *product_code_string; ··· 272 271 MODULE_FIRMWARE("myri10ge_rss_ethp_z8e.dat"); 273 272 MODULE_FIRMWARE("myri10ge_rss_eth_z8e.dat"); 274 273 274 + /* Careful: must be accessed under kparam_block_sysfs_write */ 275 275 static char *myri10ge_fw_name = NULL; 276 276 module_param(myri10ge_fw_name, charp, S_IRUGO | S_IWUSR); 277 277 MODULE_PARM_DESC(myri10ge_fw_name, "Firmware image name"); ··· 377 375 } 378 376 379 377 static struct net_device_stats *myri10ge_get_stats(struct net_device *dev); 378 + 379 + static void set_fw_name(struct myri10ge_priv *mgp, char *name, bool allocated) 380 + { 381 + if (mgp->fw_name_allocated) 382 + kfree(mgp->fw_name); 383 + mgp->fw_name = name; 384 + mgp->fw_name_allocated = allocated; 385 + } 380 386 381 387 static int 382 388 myri10ge_send_cmd(struct myri10ge_priv *mgp, u32 cmd, ··· 757 747 dev_warn(&mgp->pdev->dev, "via hotplug\n"); 758 748 } 759 749 760 - mgp->fw_name = "adopted"; 750 + set_fw_name(mgp, "adopted", false); 761 751 mgp->tx_boundary = 2048; 762 752 myri10ge_dummy_rdma(mgp, 1); 763 753 status = myri10ge_get_firmware_capabilities(mgp); ··· 3243 3233 * load the optimized firmware (which assumes aligned PCIe 3244 3234 * completions) in order to see if it works on this host. 3245 3235 */ 3246 - mgp->fw_name = myri10ge_fw_aligned; 3236 + set_fw_name(mgp, myri10ge_fw_aligned, false); 3247 3237 status = myri10ge_load_firmware(mgp, 1); 3248 3238 if (status != 0) { 3249 3239 goto abort; ··· 3271 3261 abort: 3272 3262 /* fall back to using the unaligned firmware */ 3273 3263 mgp->tx_boundary = 2048; 3274 - mgp->fw_name = myri10ge_fw_unaligned; 3264 + set_fw_name(mgp, myri10ge_fw_unaligned, false); 3275 3265 3276 3266 } 3277 3267 ··· 3294 3284 dev_info(&mgp->pdev->dev, "PCIE x%d Link\n", 3295 3285 link_width); 3296 3286 mgp->tx_boundary = 4096; 3297 - mgp->fw_name = myri10ge_fw_aligned; 3287 + set_fw_name(mgp, myri10ge_fw_aligned, false); 3298 3288 } else { 3299 3289 myri10ge_firmware_probe(mgp); 3300 3290 } ··· 3303 3293 dev_info(&mgp->pdev->dev, 3304 3294 "Assuming aligned completions (forced)\n"); 3305 3295 mgp->tx_boundary = 4096; 3306 - mgp->fw_name = myri10ge_fw_aligned; 3296 + set_fw_name(mgp, myri10ge_fw_aligned, false); 3307 3297 } else { 3308 3298 dev_info(&mgp->pdev->dev, 3309 3299 "Assuming unaligned completions (forced)\n"); 3310 3300 mgp->tx_boundary = 2048; 3311 - mgp->fw_name = myri10ge_fw_unaligned; 3301 + set_fw_name(mgp, myri10ge_fw_unaligned, false); 3312 3302 } 3313 3303 } 3304 + 3305 + kparam_block_sysfs_write(myri10ge_fw_name); 3314 3306 if (myri10ge_fw_name != NULL) { 3315 - overridden = 1; 3316 - mgp->fw_name = myri10ge_fw_name; 3307 + char *fw_name = kstrdup(myri10ge_fw_name, GFP_KERNEL); 3308 + if (fw_name) { 3309 + overridden = 1; 3310 + set_fw_name(mgp, fw_name, true); 3311 + } 3317 3312 } 3313 + kparam_unblock_sysfs_write(myri10ge_fw_name); 3314 + 3318 3315 if (mgp->board_number < MYRI10GE_MAX_BOARDS && 3319 3316 myri10ge_fw_names[mgp->board_number] != NULL && 3320 3317 strlen(myri10ge_fw_names[mgp->board_number])) { 3321 - mgp->fw_name = myri10ge_fw_names[mgp->board_number]; 3318 + set_fw_name(mgp, myri10ge_fw_names[mgp->board_number], false); 3322 3319 overridden = 1; 3323 3320 } 3324 3321 if (overridden) ··· 3677 3660 struct myri10ge_cmd cmd; 3678 3661 struct pci_dev *pdev = mgp->pdev; 3679 3662 char *old_fw; 3663 + bool old_allocated; 3680 3664 int i, status, ncpus, msix_cap; 3681 3665 3682 3666 mgp->num_slices = 1; ··· 3690 3672 3691 3673 /* try to load the slice aware rss firmware */ 3692 3674 old_fw = mgp->fw_name; 3675 + old_allocated = mgp->fw_name_allocated; 3676 + /* don't free old_fw if we override it. */ 3677 + mgp->fw_name_allocated = false; 3678 + 3693 3679 if (myri10ge_fw_name != NULL) { 3694 3680 dev_info(&mgp->pdev->dev, "overriding rss firmware to %s\n", 3695 3681 myri10ge_fw_name); 3696 - mgp->fw_name = myri10ge_fw_name; 3682 + set_fw_name(mgp, myri10ge_fw_name, false); 3697 3683 } else if (old_fw == myri10ge_fw_aligned) 3698 - mgp->fw_name = myri10ge_fw_rss_aligned; 3684 + set_fw_name(mgp, myri10ge_fw_rss_aligned, false); 3699 3685 else 3700 - mgp->fw_name = myri10ge_fw_rss_unaligned; 3686 + set_fw_name(mgp, myri10ge_fw_rss_unaligned, false); 3701 3687 status = myri10ge_load_firmware(mgp, 0); 3702 3688 if (status != 0) { 3703 3689 dev_info(&pdev->dev, "Rss firmware not found\n"); 3690 + if (old_allocated) 3691 + kfree(old_fw); 3704 3692 return; 3705 3693 } 3706 3694 ··· 3771 3747 mgp->num_slices); 3772 3748 if (status == 0) { 3773 3749 pci_disable_msix(pdev); 3750 + if (old_allocated) 3751 + kfree(old_fw); 3774 3752 return; 3775 3753 } 3776 3754 if (status > 0) ··· 3789 3763 3790 3764 abort_with_fw: 3791 3765 mgp->num_slices = 1; 3792 - mgp->fw_name = old_fw; 3766 + set_fw_name(mgp, old_fw, old_allocated); 3793 3767 myri10ge_load_firmware(mgp, 0); 3794 3768 } 3795 3769 ··· 4019 3993 pci_disable_device(pdev); 4020 3994 4021 3995 abort_with_netdev: 3996 + set_fw_name(mgp, NULL, false); 4022 3997 free_netdev(netdev); 4023 3998 return status; 4024 3999 } ··· 4064 4037 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd), 4065 4038 mgp->cmd, mgp->cmd_bus); 4066 4039 4040 + set_fw_name(mgp, NULL, false); 4067 4041 free_netdev(netdev); 4068 4042 pci_disable_device(pdev); 4069 4043 pci_set_drvdata(pdev, NULL);
+30 -2
drivers/net/wireless/libertas/if_sdio.c
··· 125 125 126 126 const char *helper; 127 127 const char *firmware; 128 + bool helper_allocated; 129 + bool firmware_allocated; 128 130 129 131 u8 buffer[65536]; 130 132 ··· 986 984 card->helper = if_sdio_models[i].helper; 987 985 card->firmware = if_sdio_models[i].firmware; 988 986 987 + kparam_block_sysfs_write(helper_name); 989 988 if (lbs_helper_name) { 989 + char *helper = kstrdup(lbs_helper_name, GFP_KERNEL); 990 + if (!helper) { 991 + kparam_unblock_sysfs_write(helper_name); 992 + ret = -ENOMEM; 993 + goto free; 994 + } 990 995 lbs_deb_sdio("overriding helper firmware: %s\n", 991 996 lbs_helper_name); 992 - card->helper = lbs_helper_name; 997 + card->helper = helper; 998 + card->helper_allocated = true; 993 999 } 1000 + kparam_unblock_sysfs_write(helper_name); 994 1001 1002 + kparam_block_sysfs_write(fw_name); 995 1003 if (lbs_fw_name) { 1004 + char *fw_name = kstrdup(lbs_fw_name, GFP_KERNEL); 1005 + if (!fw_name) { 1006 + kparam_unblock_sysfs_write(fw_name); 1007 + ret = -ENOMEM; 1008 + goto free; 1009 + } 996 1010 lbs_deb_sdio("overriding firmware: %s\n", lbs_fw_name); 997 - card->firmware = lbs_fw_name; 1011 + card->firmware = fw_name; 1012 + card->firmware_allocated = true; 998 1013 } 1014 + kparam_unblock_sysfs_write(fw_name); 999 1015 1000 1016 sdio_claim_host(func); 1001 1017 ··· 1147 1127 kfree(packet); 1148 1128 } 1149 1129 1130 + if (card->helper_allocated) 1131 + kfree(card->helper); 1132 + if (card->firmware_allocated) 1133 + kfree(card->firmware); 1150 1134 kfree(card); 1151 1135 1152 1136 goto out; ··· 1201 1177 kfree(packet); 1202 1178 } 1203 1179 1180 + if (card->helper_allocated) 1181 + kfree(card->helper); 1182 + if (card->firmware_allocated) 1183 + kfree(card->firmware); 1204 1184 kfree(card); 1205 1185 1206 1186 lbs_deb_leave(LBS_DEB_SDIO);
+3
drivers/net/wireless/libertas/if_usb.c
··· 289 289 } 290 290 291 291 /* Upload firmware */ 292 + kparam_block_sysfs_write(fw_name); 292 293 if (__if_usb_prog_firmware(cardp, lbs_fw_name, BOOT_CMD_FW_BY_USB)) { 294 + kparam_unblock_sysfs_write(fw_name); 293 295 lbs_deb_usbd(&udev->dev, "FW upload failed\n"); 294 296 goto err_prog_firmware; 295 297 } 298 + kparam_unblock_sysfs_write(fw_name); 296 299 297 300 if (!(priv = lbs_add_card(cardp, &udev->dev))) 298 301 goto err_prog_firmware;
+3
drivers/net/wireless/libertas_tf/if_usb.c
··· 811 811 812 812 lbtf_deb_enter(LBTF_DEB_USB); 813 813 814 + kparam_block_sysfs_write(fw_name); 814 815 ret = request_firmware(&cardp->fw, lbtf_fw_name, &cardp->udev->dev); 815 816 if (ret < 0) { 816 817 pr_err("request_firmware() failed with %#x\n", ret); 817 818 pr_err("firmware %s not found\n", lbtf_fw_name); 819 + kparam_unblock_sysfs_write(fw_name); 818 820 goto done; 819 821 } 822 + kparam_unblock_sysfs_write(fw_name); 820 823 821 824 if (check_fwfile_format(cardp->fw->data, cardp->fw->size)) 822 825 goto release_fw;
+2
drivers/scsi/bfa/bfad.c
··· 788 788 memset(&driver_info, 0, sizeof(driver_info)); 789 789 strncpy(driver_info.version, BFAD_DRIVER_VERSION, 790 790 sizeof(driver_info.version) - 1); 791 + __kernel_param_lock(); 791 792 if (host_name) 792 793 strncpy(driver_info.host_machine_name, host_name, 793 794 sizeof(driver_info.host_machine_name) - 1); ··· 798 797 if (os_patch) 799 798 strncpy(driver_info.host_os_patch, os_patch, 800 799 sizeof(driver_info.host_os_patch) - 1); 800 + __kernel_param_unlock(); 801 801 802 802 strncpy(driver_info.os_device_name, bfad->pci_name, 803 803 sizeof(driver_info.os_device_name - 1));
+3 -3
drivers/staging/rtl8187se/r8180_core.c
··· 61 61 }; 62 62 63 63 64 - static char *ifname = "wlan%d"; 64 + static char ifname[IFNAMSIZ] = "wlan%d"; 65 65 static int hwseqnum = 0; 66 66 static int hwwep = 0; 67 67 static int channels = 0x3fff; ··· 72 72 MODULE_DESCRIPTION("Linux driver for Realtek RTL8180 / RTL8185 WiFi cards"); 73 73 74 74 75 - module_param(ifname, charp, S_IRUGO|S_IWUSR); 75 + module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR); 76 76 module_param(hwseqnum, int, S_IRUGO|S_IWUSR); 77 77 module_param(hwwep, int, S_IRUGO|S_IWUSR); 78 78 module_param(channels, int, S_IRUGO|S_IWUSR); ··· 3609 3609 3610 3610 if (dev_alloc_name(dev, ifname) < 0) { 3611 3611 DMESG("Oops: devname already taken! Trying wlan%%d...\n"); 3612 - ifname = "wlan%d"; 3612 + strcpy(ifname, "wlan%d"); 3613 3613 dev_alloc_name(dev, ifname); 3614 3614 } 3615 3615
+3 -3
drivers/staging/rtl8192e/r8192E_core.c
··· 112 112 {} 113 113 }; 114 114 115 - static char* ifname = "wlan%d"; 115 + static char ifname[IFNAMSIZ] = "wlan%d"; 116 116 static int hwwep = 1; //default use hw. set 0 to use software security 117 117 static int channels = 0x3fff; 118 118 ··· 123 123 MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards"); 124 124 125 125 126 - module_param(ifname, charp, S_IRUGO|S_IWUSR ); 126 + module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR); 127 127 //module_param(hwseqnum,int, S_IRUGO|S_IWUSR); 128 128 module_param(hwwep,int, S_IRUGO|S_IWUSR); 129 129 module_param(channels,int, S_IRUGO|S_IWUSR); ··· 6446 6446 6447 6447 if (dev_alloc_name(dev, ifname) < 0){ 6448 6448 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n"); 6449 - ifname = "wlan%d"; 6449 + strcpy(ifname, "wlan%d"); 6450 6450 dev_alloc_name(dev, ifname); 6451 6451 } 6452 6452
+3 -3
drivers/staging/rtl8192su/r8192U_core.c
··· 144 144 MODULE_DEVICE_TABLE(usb, rtl8192_usb_id_tbl); 145 145 MODULE_DESCRIPTION("Linux driver for Realtek RTL8192 USB WiFi cards"); 146 146 147 - static char* ifname = "wlan%d"; 147 + static char ifname[IFNAMSIZ] = "wlan%d"; 148 148 static int hwwep = 1; //default use hw. set 0 to use software security 149 149 static int channels = 0x3fff; 150 150 151 151 152 152 153 - module_param(ifname, charp, S_IRUGO|S_IWUSR ); 153 + module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR); 154 154 //module_param(hwseqnum,int, S_IRUGO|S_IWUSR); 155 155 module_param(hwwep,int, S_IRUGO|S_IWUSR); 156 156 module_param(channels,int, S_IRUGO|S_IWUSR); ··· 7406 7406 7407 7407 if (dev_alloc_name(dev, ifname) < 0){ 7408 7408 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n"); 7409 - ifname = "wlan%d"; 7409 + strcpy(ifname, "wlan%d"); 7410 7410 dev_alloc_name(dev, ifname); 7411 7411 } 7412 7412
+2
drivers/usb/atm/ueagle-atm.c
··· 1577 1577 char file_arr[] = "CMVxy.bin"; 1578 1578 char *file; 1579 1579 1580 + kparam_block_sysfs_write(cmv_file); 1580 1581 /* set proper name corresponding modem version and line type */ 1581 1582 if (cmv_file[sc->modem_index] == NULL) { 1582 1583 if (UEA_CHIP_VERSION(sc) == ADI930) ··· 1596 1595 strlcat(cmv_name, file, UEA_FW_NAME_MAX); 1597 1596 if (ver == 2) 1598 1597 strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX); 1598 + kparam_unblock_sysfs_write(cmv_file); 1599 1599 } 1600 1600 1601 1601 static int request_cmvs_old(struct uea_softc *sc,
+4 -3
drivers/video/uvesafb.c
··· 1977 1977 1978 1978 module_exit(uvesafb_exit); 1979 1979 1980 - #define param_get_scroll NULL 1981 - static int param_set_scroll(const char *val, struct kernel_param *kp) 1980 + static int param_set_scroll(const char *val, const struct kernel_param *kp) 1982 1981 { 1983 1982 ypan = 0; 1984 1983 ··· 1992 1993 1993 1994 return 0; 1994 1995 } 1995 - 1996 + static struct kernel_param_ops param_ops_scroll = { 1997 + .set = param_set_scroll, 1998 + }; 1996 1999 #define param_check_scroll(name, p) __param_check(name, p, void) 1997 2000 1998 2001 module_param_named(scroll, ypan, scroll, 0);
+2
drivers/video/vt8623fb.c
··· 726 726 727 727 /* Prepare startup mode */ 728 728 729 + kparam_block_sysfs_write(mode_option); 729 730 rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8); 731 + kparam_unblock_sysfs_write(mode_option); 730 732 if (! ((rc == 1) || (rc == 2))) { 731 733 rc = -EINVAL; 732 734 dev_err(info->device, "mode %s not found\n", mode_option);
+5 -6
fs/nfs/callback.c
··· 45 45 unsigned short nfs_callback_tcpport6; 46 46 #define NFS_CALLBACK_MAXPORTNR (65535U) 47 47 48 - static int param_set_portnr(const char *val, struct kernel_param *kp) 48 + static int param_set_portnr(const char *val, const struct kernel_param *kp) 49 49 { 50 50 unsigned long num; 51 51 int ret; ··· 58 58 *((unsigned int *)kp->arg) = num; 59 59 return 0; 60 60 } 61 - 62 - static int param_get_portnr(char *buffer, struct kernel_param *kp) 63 - { 64 - return param_get_uint(buffer, kp); 65 - } 61 + static struct kernel_param_ops param_ops_portnr = { 62 + .set = param_set_portnr, 63 + .get = param_get_uint, 64 + }; 66 65 #define param_check_portnr(name, p) __param_check(name, p, unsigned int); 67 66 68 67 module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
+221 -67
include/linux/moduleparam.h
··· 31 31 32 32 struct kernel_param; 33 33 34 - /* Returns 0, or -errno. arg is in kp->arg. */ 35 - typedef int (*param_set_fn)(const char *val, struct kernel_param *kp); 36 - /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ 37 - typedef int (*param_get_fn)(char *buffer, struct kernel_param *kp); 34 + struct kernel_param_ops { 35 + /* Returns 0, or -errno. arg is in kp->arg. */ 36 + int (*set)(const char *val, const struct kernel_param *kp); 37 + /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ 38 + int (*get)(char *buffer, const struct kernel_param *kp); 39 + /* Optional function to free kp->arg when module unloaded. */ 40 + void (*free)(void *arg); 41 + }; 38 42 39 43 /* Flag bits for kernel_param.flags */ 40 44 #define KPARAM_ISBOOL 2 41 45 42 46 struct kernel_param { 43 47 const char *name; 48 + const struct kernel_param_ops *ops; 44 49 u16 perm; 45 50 u16 flags; 46 - param_set_fn set; 47 - param_get_fn get; 48 51 union { 49 52 void *arg; 50 53 const struct kparam_string *str; ··· 66 63 { 67 64 unsigned int max; 68 65 unsigned int *num; 69 - param_set_fn set; 70 - param_get_fn get; 66 + const struct kernel_param_ops *ops; 71 67 unsigned int elemsize; 72 68 void *elem; 73 69 }; 70 + 71 + /** 72 + * module_param - typesafe helper for a module/cmdline parameter 73 + * @value: the variable to alter, and exposed parameter name. 74 + * @type: the type of the parameter 75 + * @perm: visibility in sysfs. 76 + * 77 + * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a 78 + * ".") the kernel commandline parameter. Note that - is changed to _, so 79 + * the user can use "foo-bar=1" even for variable "foo_bar". 80 + * 81 + * @perm is 0 if the the variable is not to appear in sysfs, or 0444 82 + * for world-readable, 0644 for root-writable, etc. Note that if it 83 + * is writable, you may need to use kparam_block_sysfs_write() around 84 + * accesses (esp. charp, which can be kfreed when it changes). 85 + * 86 + * The @type is simply pasted to refer to a param_ops_##type and a 87 + * param_check_##type: for convenience many standard types are provided but 88 + * you can create your own by defining those variables. 89 + * 90 + * Standard types are: 91 + * byte, short, ushort, int, uint, long, ulong 92 + * charp: a character pointer 93 + * bool: a bool, values 0/1, y/n, Y/N. 94 + * invbool: the above, only sense-reversed (N = true). 95 + */ 96 + #define module_param(name, type, perm) \ 97 + module_param_named(name, name, type, perm) 98 + 99 + /** 100 + * module_param_named - typesafe helper for a renamed module/cmdline parameter 101 + * @name: a valid C identifier which is the parameter name. 102 + * @value: the actual lvalue to alter. 103 + * @type: the type of the parameter 104 + * @perm: visibility in sysfs. 105 + * 106 + * Usually it's a good idea to have variable names and user-exposed names the 107 + * same, but that's harder if the variable must be non-static or is inside a 108 + * structure. This allows exposure under a different name. 109 + */ 110 + #define module_param_named(name, value, type, perm) \ 111 + param_check_##type(name, &(value)); \ 112 + module_param_cb(name, &param_ops_##type, &value, perm); \ 113 + __MODULE_PARM_TYPE(name, #type) 114 + 115 + /** 116 + * module_param_cb - general callback for a module/cmdline parameter 117 + * @name: a valid C identifier which is the parameter name. 118 + * @ops: the set & get operations for this parameter. 119 + * @perm: visibility in sysfs. 120 + * 121 + * The ops can have NULL set or get functions. 122 + */ 123 + #define module_param_cb(name, ops, arg, perm) \ 124 + __module_param_call(MODULE_PARAM_PREFIX, \ 125 + name, ops, arg, __same_type((arg), bool *), perm) 74 126 75 127 /* On alpha, ia64 and ppc64 relocations to global data cannot go into 76 128 read-only sections (which is part of respective UNIX ABI on these ··· 138 80 #endif 139 81 140 82 /* This is the fundamental function for registering boot/module 141 - parameters. perm sets the visibility in sysfs: 000 means it's 142 - not there, read bits mean it's readable, write bits mean it's 143 - writable. */ 144 - #define __module_param_call(prefix, name, set, get, arg, isbool, perm) \ 83 + parameters. */ 84 + #define __module_param_call(prefix, name, ops, arg, isbool, perm) \ 145 85 /* Default value instead of permissions? */ \ 146 86 static int __param_perm_check_##name __attribute__((unused)) = \ 147 87 BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)) \ ··· 148 92 static struct kernel_param __moduleparam_const __param_##name \ 149 93 __used \ 150 94 __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ 151 - = { __param_str_##name, perm, isbool ? KPARAM_ISBOOL : 0, \ 152 - set, get, { arg } } 95 + = { __param_str_##name, ops, perm, isbool ? KPARAM_ISBOOL : 0, \ 96 + { arg } } 153 97 154 - #define module_param_call(name, set, get, arg, perm) \ 155 - __module_param_call(MODULE_PARAM_PREFIX, \ 156 - name, set, get, arg, \ 157 - __same_type(*(arg), bool), perm) 98 + /* Obsolete - use module_param_cb() */ 99 + #define module_param_call(name, set, get, arg, perm) \ 100 + static struct kernel_param_ops __param_ops_##name = \ 101 + { (void *)set, (void *)get }; \ 102 + __module_param_call(MODULE_PARAM_PREFIX, \ 103 + name, &__param_ops_##name, arg, \ 104 + __same_type(arg, bool *), \ 105 + (perm) + sizeof(__check_old_set_param(set))*0) 158 106 159 - /* Helper functions: type is byte, short, ushort, int, uint, long, 160 - ulong, charp, bool or invbool, or XXX if you define param_get_XXX, 161 - param_set_XXX and param_check_XXX. */ 162 - #define module_param_named(name, value, type, perm) \ 163 - param_check_##type(name, &(value)); \ 164 - module_param_call(name, param_set_##type, param_get_##type, &value, perm); \ 165 - __MODULE_PARM_TYPE(name, #type) 107 + /* We don't get oldget: it's often a new-style param_get_uint, etc. */ 108 + static inline int 109 + __check_old_set_param(int (*oldset)(const char *, struct kernel_param *)) 110 + { 111 + return 0; 112 + } 166 113 167 - #define module_param(name, type, perm) \ 168 - module_param_named(name, name, type, perm) 114 + /** 115 + * kparam_block_sysfs_write - make sure a parameter isn't written via sysfs. 116 + * @name: the name of the parameter 117 + * 118 + * There's no point blocking write on a paramter that isn't writable via sysfs! 119 + */ 120 + #define kparam_block_sysfs_write(name) \ 121 + do { \ 122 + BUG_ON(!(__param_##name.perm & 0222)); \ 123 + __kernel_param_lock(); \ 124 + } while (0) 125 + 126 + /** 127 + * kparam_unblock_sysfs_write - allows sysfs to write to a parameter again. 128 + * @name: the name of the parameter 129 + */ 130 + #define kparam_unblock_sysfs_write(name) \ 131 + do { \ 132 + BUG_ON(!(__param_##name.perm & 0222)); \ 133 + __kernel_param_unlock(); \ 134 + } while (0) 135 + 136 + /** 137 + * kparam_block_sysfs_read - make sure a parameter isn't read via sysfs. 138 + * @name: the name of the parameter 139 + * 140 + * This also blocks sysfs writes. 141 + */ 142 + #define kparam_block_sysfs_read(name) \ 143 + do { \ 144 + BUG_ON(!(__param_##name.perm & 0444)); \ 145 + __kernel_param_lock(); \ 146 + } while (0) 147 + 148 + /** 149 + * kparam_unblock_sysfs_read - allows sysfs to read a parameter again. 150 + * @name: the name of the parameter 151 + */ 152 + #define kparam_unblock_sysfs_read(name) \ 153 + do { \ 154 + BUG_ON(!(__param_##name.perm & 0444)); \ 155 + __kernel_param_unlock(); \ 156 + } while (0) 157 + 158 + #ifdef CONFIG_SYSFS 159 + extern void __kernel_param_lock(void); 160 + extern void __kernel_param_unlock(void); 161 + #else 162 + static inline void __kernel_param_lock(void) 163 + { 164 + } 165 + static inline void __kernel_param_unlock(void) 166 + { 167 + } 168 + #endif 169 169 170 170 #ifndef MODULE 171 171 /** 172 172 * core_param - define a historical core kernel parameter. 173 173 * @name: the name of the cmdline and sysfs parameter (often the same as var) 174 174 * @var: the variable 175 - * @type: the type (for param_set_##type and param_get_##type) 175 + * @type: the type of the parameter 176 176 * @perm: visibility in sysfs 177 177 * 178 178 * core_param is just like module_param(), but cannot be modular and ··· 238 126 */ 239 127 #define core_param(name, var, type, perm) \ 240 128 param_check_##type(name, &(var)); \ 241 - __module_param_call("", name, param_set_##type, param_get_##type, \ 129 + __module_param_call("", name, &param_ops_##type, \ 242 130 &var, __same_type(var, bool), perm) 243 131 #endif /* !MODULE */ 244 132 245 - /* Actually copy string: maxlen param is usually sizeof(string). */ 133 + /** 134 + * module_param_string - a char array parameter 135 + * @name: the name of the parameter 136 + * @string: the string variable 137 + * @len: the maximum length of the string, incl. terminator 138 + * @perm: visibility in sysfs. 139 + * 140 + * This actually copies the string when it's set (unlike type charp). 141 + * @len is usually just sizeof(string). 142 + */ 246 143 #define module_param_string(name, string, len, perm) \ 247 144 static const struct kparam_string __param_string_##name \ 248 145 = { len, string }; \ 249 146 __module_param_call(MODULE_PARAM_PREFIX, name, \ 250 - param_set_copystring, param_get_string, \ 147 + &param_ops_string, \ 251 148 .str = &__param_string_##name, 0, perm); \ 252 149 __MODULE_PARM_TYPE(name, "string") 253 150 254 151 /* Called on module insert or kernel boot */ 255 152 extern int parse_args(const char *name, 256 153 char *args, 257 - struct kernel_param *params, 154 + const struct kernel_param *params, 258 155 unsigned num, 259 156 int (*unknown)(char *param, char *val)); 260 157 ··· 283 162 #define __param_check(name, p, type) \ 284 163 static inline type *__check_##name(void) { return(p); } 285 164 286 - extern int param_set_byte(const char *val, struct kernel_param *kp); 287 - extern int param_get_byte(char *buffer, struct kernel_param *kp); 165 + extern struct kernel_param_ops param_ops_byte; 166 + extern int param_set_byte(const char *val, const struct kernel_param *kp); 167 + extern int param_get_byte(char *buffer, const struct kernel_param *kp); 288 168 #define param_check_byte(name, p) __param_check(name, p, unsigned char) 289 169 290 - extern int param_set_short(const char *val, struct kernel_param *kp); 291 - extern int param_get_short(char *buffer, struct kernel_param *kp); 170 + extern struct kernel_param_ops param_ops_short; 171 + extern int param_set_short(const char *val, const struct kernel_param *kp); 172 + extern int param_get_short(char *buffer, const struct kernel_param *kp); 292 173 #define param_check_short(name, p) __param_check(name, p, short) 293 174 294 - extern int param_set_ushort(const char *val, struct kernel_param *kp); 295 - extern int param_get_ushort(char *buffer, struct kernel_param *kp); 175 + extern struct kernel_param_ops param_ops_ushort; 176 + extern int param_set_ushort(const char *val, const struct kernel_param *kp); 177 + extern int param_get_ushort(char *buffer, const struct kernel_param *kp); 296 178 #define param_check_ushort(name, p) __param_check(name, p, unsigned short) 297 179 298 - extern int param_set_int(const char *val, struct kernel_param *kp); 299 - extern int param_get_int(char *buffer, struct kernel_param *kp); 180 + extern struct kernel_param_ops param_ops_int; 181 + extern int param_set_int(const char *val, const struct kernel_param *kp); 182 + extern int param_get_int(char *buffer, const struct kernel_param *kp); 300 183 #define param_check_int(name, p) __param_check(name, p, int) 301 184 302 - extern int param_set_uint(const char *val, struct kernel_param *kp); 303 - extern int param_get_uint(char *buffer, struct kernel_param *kp); 185 + extern struct kernel_param_ops param_ops_uint; 186 + extern int param_set_uint(const char *val, const struct kernel_param *kp); 187 + extern int param_get_uint(char *buffer, const struct kernel_param *kp); 304 188 #define param_check_uint(name, p) __param_check(name, p, unsigned int) 305 189 306 - extern int param_set_long(const char *val, struct kernel_param *kp); 307 - extern int param_get_long(char *buffer, struct kernel_param *kp); 190 + extern struct kernel_param_ops param_ops_long; 191 + extern int param_set_long(const char *val, const struct kernel_param *kp); 192 + extern int param_get_long(char *buffer, const struct kernel_param *kp); 308 193 #define param_check_long(name, p) __param_check(name, p, long) 309 194 310 - extern int param_set_ulong(const char *val, struct kernel_param *kp); 311 - extern int param_get_ulong(char *buffer, struct kernel_param *kp); 195 + extern struct kernel_param_ops param_ops_ulong; 196 + extern int param_set_ulong(const char *val, const struct kernel_param *kp); 197 + extern int param_get_ulong(char *buffer, const struct kernel_param *kp); 312 198 #define param_check_ulong(name, p) __param_check(name, p, unsigned long) 313 199 314 - extern int param_set_charp(const char *val, struct kernel_param *kp); 315 - extern int param_get_charp(char *buffer, struct kernel_param *kp); 200 + extern struct kernel_param_ops param_ops_charp; 201 + extern int param_set_charp(const char *val, const struct kernel_param *kp); 202 + extern int param_get_charp(char *buffer, const struct kernel_param *kp); 316 203 #define param_check_charp(name, p) __param_check(name, p, char *) 317 204 318 205 /* For historical reasons "bool" parameters can be (unsigned) "int". */ 319 - extern int param_set_bool(const char *val, struct kernel_param *kp); 320 - extern int param_get_bool(char *buffer, struct kernel_param *kp); 206 + extern struct kernel_param_ops param_ops_bool; 207 + extern int param_set_bool(const char *val, const struct kernel_param *kp); 208 + extern int param_get_bool(char *buffer, const struct kernel_param *kp); 321 209 #define param_check_bool(name, p) \ 322 210 static inline void __check_##name(void) \ 323 211 { \ 324 - BUILD_BUG_ON(!__same_type(*(p), bool) && \ 325 - !__same_type(*(p), unsigned int) && \ 326 - !__same_type(*(p), int)); \ 212 + BUILD_BUG_ON(!__same_type((p), bool *) && \ 213 + !__same_type((p), unsigned int *) && \ 214 + !__same_type((p), int *)); \ 327 215 } 328 216 329 - extern int param_set_invbool(const char *val, struct kernel_param *kp); 330 - extern int param_get_invbool(char *buffer, struct kernel_param *kp); 217 + extern struct kernel_param_ops param_ops_invbool; 218 + extern int param_set_invbool(const char *val, const struct kernel_param *kp); 219 + extern int param_get_invbool(char *buffer, const struct kernel_param *kp); 331 220 #define param_check_invbool(name, p) __param_check(name, p, bool) 332 221 333 - /* Comma-separated array: *nump is set to number they actually specified. */ 222 + /** 223 + * module_param_array - a parameter which is an array of some type 224 + * @name: the name of the array variable 225 + * @type: the type, as per module_param() 226 + * @nump: optional pointer filled in with the number written 227 + * @perm: visibility in sysfs 228 + * 229 + * Input and output are as comma-separated values. Commas inside values 230 + * don't work properly (eg. an array of charp). 231 + * 232 + * ARRAY_SIZE(@name) is used to determine the number of elements in the 233 + * array, so the definition must be visible. 234 + */ 235 + #define module_param_array(name, type, nump, perm) \ 236 + module_param_array_named(name, name, type, nump, perm) 237 + 238 + /** 239 + * module_param_array_named - renamed parameter which is an array of some type 240 + * @name: a valid C identifier which is the parameter name 241 + * @array: the name of the array variable 242 + * @type: the type, as per module_param() 243 + * @nump: optional pointer filled in with the number written 244 + * @perm: visibility in sysfs 245 + * 246 + * This exposes a different name than the actual variable name. See 247 + * module_param_named() for why this might be necessary. 248 + */ 334 249 #define module_param_array_named(name, array, type, nump, perm) \ 335 250 static const struct kparam_array __param_arr_##name \ 336 - = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\ 251 + = { ARRAY_SIZE(array), nump, &param_ops_##type, \ 337 252 sizeof(array[0]), array }; \ 338 253 __module_param_call(MODULE_PARAM_PREFIX, name, \ 339 - param_array_set, param_array_get, \ 254 + &param_array_ops, \ 340 255 .arr = &__param_arr_##name, \ 341 256 __same_type(array[0], bool), perm); \ 342 257 __MODULE_PARM_TYPE(name, "array of " #type) 343 258 344 - #define module_param_array(name, type, nump, perm) \ 345 - module_param_array_named(name, name, type, nump, perm) 259 + extern struct kernel_param_ops param_array_ops; 346 260 347 - extern int param_array_set(const char *val, struct kernel_param *kp); 348 - extern int param_array_get(char *buffer, struct kernel_param *kp); 349 - 350 - extern int param_set_copystring(const char *val, struct kernel_param *kp); 351 - extern int param_get_string(char *buffer, struct kernel_param *kp); 261 + extern struct kernel_param_ops param_ops_string; 262 + extern int param_set_copystring(const char *val, const struct kernel_param *); 263 + extern int param_get_string(char *buffer, const struct kernel_param *kp); 352 264 353 265 /* for exporting parameters in /sys/parameters */ 354 266 ··· 389 235 390 236 #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES) 391 237 extern int module_param_sysfs_setup(struct module *mod, 392 - struct kernel_param *kparam, 238 + const struct kernel_param *kparam, 393 239 unsigned int num_params); 394 240 395 241 extern void module_param_sysfs_remove(struct module *mod); 396 242 #else 397 243 static inline int module_param_sysfs_setup(struct module *mod, 398 - struct kernel_param *kparam, 244 + const struct kernel_param *kparam, 399 245 unsigned int num_params) 400 246 { 401 247 return 0;
+4 -4
init/main.c
··· 201 201 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, }; 202 202 static const char *panic_later, *panic_param; 203 203 204 - extern struct obs_kernel_param __setup_start[], __setup_end[]; 204 + extern const struct obs_kernel_param __setup_start[], __setup_end[]; 205 205 206 206 static int __init obsolete_checksetup(char *line) 207 207 { 208 - struct obs_kernel_param *p; 208 + const struct obs_kernel_param *p; 209 209 int had_early_param = 0; 210 210 211 211 p = __setup_start; ··· 458 458 /* Check for early params. */ 459 459 static int __init do_early_param(char *param, char *val) 460 460 { 461 - struct obs_kernel_param *p; 461 + const struct obs_kernel_param *p; 462 462 463 463 for (p = __setup_start; p < __setup_end; p++) { 464 464 if ((p->early && strcmp(param, p->str) == 0) || ··· 536 536 asmlinkage void __init start_kernel(void) 537 537 { 538 538 char * command_line; 539 - extern struct kernel_param __start___param[], __stop___param[]; 539 + extern const struct kernel_param __start___param[], __stop___param[]; 540 540 541 541 smp_setup_processor_id(); 542 542
+161 -72
kernel/params.c
··· 31 31 #define DEBUGP(fmt, a...) 32 32 #endif 33 33 34 + /* Protects all parameters, and incidentally kmalloced_param list. */ 35 + static DEFINE_MUTEX(param_lock); 36 + 37 + /* This just allows us to keep track of which parameters are kmalloced. */ 38 + struct kmalloced_param { 39 + struct list_head list; 40 + char val[]; 41 + }; 42 + static LIST_HEAD(kmalloced_params); 43 + 44 + static void *kmalloc_parameter(unsigned int size) 45 + { 46 + struct kmalloced_param *p; 47 + 48 + p = kmalloc(sizeof(*p) + size, GFP_KERNEL); 49 + if (!p) 50 + return NULL; 51 + 52 + list_add(&p->list, &kmalloced_params); 53 + return p->val; 54 + } 55 + 56 + /* Does nothing if parameter wasn't kmalloced above. */ 57 + static void maybe_kfree_parameter(void *param) 58 + { 59 + struct kmalloced_param *p; 60 + 61 + list_for_each_entry(p, &kmalloced_params, list) { 62 + if (p->val == param) { 63 + list_del(&p->list); 64 + kfree(p); 65 + break; 66 + } 67 + } 68 + } 69 + 34 70 static inline char dash2underscore(char c) 35 71 { 36 72 if (c == '-') ··· 85 49 86 50 static int parse_one(char *param, 87 51 char *val, 88 - struct kernel_param *params, 52 + const struct kernel_param *params, 89 53 unsigned num_params, 90 54 int (*handle_unknown)(char *param, char *val)) 91 55 { 92 56 unsigned int i; 57 + int err; 93 58 94 59 /* Find parameter */ 95 60 for (i = 0; i < num_params; i++) { 96 61 if (parameq(param, params[i].name)) { 62 + /* Noone handled NULL, so do it here. */ 63 + if (!val && params[i].ops->set != param_set_bool) 64 + return -EINVAL; 97 65 DEBUGP("They are equal! Calling %p\n", 98 - params[i].set); 99 - return params[i].set(val, &params[i]); 66 + params[i].ops->set); 67 + mutex_lock(&param_lock); 68 + err = params[i].ops->set(val, &params[i]); 69 + mutex_unlock(&param_lock); 70 + return err; 100 71 } 101 72 } 102 73 ··· 171 128 /* Args looks like "foo=bar,bar2 baz=fuz wiz". */ 172 129 int parse_args(const char *name, 173 130 char *args, 174 - struct kernel_param *params, 131 + const struct kernel_param *params, 175 132 unsigned num, 176 133 int (*unknown)(char *param, char *val)) 177 134 { ··· 219 176 220 177 /* Lazy bastard, eh? */ 221 178 #define STANDARD_PARAM_DEF(name, type, format, tmptype, strtolfn) \ 222 - int param_set_##name(const char *val, struct kernel_param *kp) \ 179 + int param_set_##name(const char *val, const struct kernel_param *kp) \ 223 180 { \ 224 181 tmptype l; \ 225 182 int ret; \ 226 183 \ 227 - if (!val) return -EINVAL; \ 228 184 ret = strtolfn(val, 0, &l); \ 229 185 if (ret == -EINVAL || ((type)l != l)) \ 230 186 return -EINVAL; \ 231 187 *((type *)kp->arg) = l; \ 232 188 return 0; \ 233 189 } \ 234 - int param_get_##name(char *buffer, struct kernel_param *kp) \ 190 + int param_get_##name(char *buffer, const struct kernel_param *kp) \ 235 191 { \ 236 192 return sprintf(buffer, format, *((type *)kp->arg)); \ 237 - } 193 + } \ 194 + struct kernel_param_ops param_ops_##name = { \ 195 + .set = param_set_##name, \ 196 + .get = param_get_##name, \ 197 + }; \ 198 + EXPORT_SYMBOL(param_set_##name); \ 199 + EXPORT_SYMBOL(param_get_##name); \ 200 + EXPORT_SYMBOL(param_ops_##name) 201 + 238 202 239 203 STANDARD_PARAM_DEF(byte, unsigned char, "%c", unsigned long, strict_strtoul); 240 204 STANDARD_PARAM_DEF(short, short, "%hi", long, strict_strtol); ··· 251 201 STANDARD_PARAM_DEF(long, long, "%li", long, strict_strtol); 252 202 STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, strict_strtoul); 253 203 254 - int param_set_charp(const char *val, struct kernel_param *kp) 204 + int param_set_charp(const char *val, const struct kernel_param *kp) 255 205 { 256 - if (!val) { 257 - printk(KERN_ERR "%s: string parameter expected\n", 258 - kp->name); 259 - return -EINVAL; 260 - } 261 - 262 206 if (strlen(val) > 1024) { 263 207 printk(KERN_ERR "%s: string parameter too long\n", 264 208 kp->name); 265 209 return -ENOSPC; 266 210 } 267 211 268 - /* This is a hack. We can't need to strdup in early boot, and we 212 + maybe_kfree_parameter(*(char **)kp->arg); 213 + 214 + /* This is a hack. We can't kmalloc in early boot, and we 269 215 * don't need to; this mangled commandline is preserved. */ 270 216 if (slab_is_available()) { 271 - *(char **)kp->arg = kstrdup(val, GFP_KERNEL); 217 + *(char **)kp->arg = kmalloc_parameter(strlen(val)+1); 272 218 if (!*(char **)kp->arg) 273 219 return -ENOMEM; 220 + strcpy(*(char **)kp->arg, val); 274 221 } else 275 222 *(const char **)kp->arg = val; 276 223 277 224 return 0; 278 225 } 226 + EXPORT_SYMBOL(param_set_charp); 279 227 280 - int param_get_charp(char *buffer, struct kernel_param *kp) 228 + int param_get_charp(char *buffer, const struct kernel_param *kp) 281 229 { 282 230 return sprintf(buffer, "%s", *((char **)kp->arg)); 283 231 } 232 + EXPORT_SYMBOL(param_get_charp); 233 + 234 + static void param_free_charp(void *arg) 235 + { 236 + maybe_kfree_parameter(*((char **)arg)); 237 + } 238 + 239 + struct kernel_param_ops param_ops_charp = { 240 + .set = param_set_charp, 241 + .get = param_get_charp, 242 + .free = param_free_charp, 243 + }; 244 + EXPORT_SYMBOL(param_ops_charp); 284 245 285 246 /* Actually could be a bool or an int, for historical reasons. */ 286 - int param_set_bool(const char *val, struct kernel_param *kp) 247 + int param_set_bool(const char *val, const struct kernel_param *kp) 287 248 { 288 249 bool v; 289 250 ··· 319 258 *(int *)kp->arg = v; 320 259 return 0; 321 260 } 261 + EXPORT_SYMBOL(param_set_bool); 322 262 323 - int param_get_bool(char *buffer, struct kernel_param *kp) 263 + int param_get_bool(char *buffer, const struct kernel_param *kp) 324 264 { 325 265 bool val; 326 266 if (kp->flags & KPARAM_ISBOOL) ··· 332 270 /* Y and N chosen as being relatively non-coder friendly */ 333 271 return sprintf(buffer, "%c", val ? 'Y' : 'N'); 334 272 } 273 + EXPORT_SYMBOL(param_get_bool); 274 + 275 + struct kernel_param_ops param_ops_bool = { 276 + .set = param_set_bool, 277 + .get = param_get_bool, 278 + }; 279 + EXPORT_SYMBOL(param_ops_bool); 335 280 336 281 /* This one must be bool. */ 337 - int param_set_invbool(const char *val, struct kernel_param *kp) 282 + int param_set_invbool(const char *val, const struct kernel_param *kp) 338 283 { 339 284 int ret; 340 285 bool boolval; ··· 354 285 *(bool *)kp->arg = !boolval; 355 286 return ret; 356 287 } 288 + EXPORT_SYMBOL(param_set_invbool); 357 289 358 - int param_get_invbool(char *buffer, struct kernel_param *kp) 290 + int param_get_invbool(char *buffer, const struct kernel_param *kp) 359 291 { 360 292 return sprintf(buffer, "%c", (*(bool *)kp->arg) ? 'N' : 'Y'); 361 293 } 294 + EXPORT_SYMBOL(param_get_invbool); 295 + 296 + struct kernel_param_ops param_ops_invbool = { 297 + .set = param_set_invbool, 298 + .get = param_get_invbool, 299 + }; 300 + EXPORT_SYMBOL(param_ops_invbool); 362 301 363 302 /* We break the rule and mangle the string. */ 364 303 static int param_array(const char *name, 365 304 const char *val, 366 305 unsigned int min, unsigned int max, 367 306 void *elem, int elemsize, 368 - int (*set)(const char *, struct kernel_param *kp), 307 + int (*set)(const char *, const struct kernel_param *kp), 369 308 u16 flags, 370 309 unsigned int *num) 371 310 { ··· 385 308 kp.name = name; 386 309 kp.arg = elem; 387 310 kp.flags = flags; 388 - 389 - /* No equals sign? */ 390 - if (!val) { 391 - printk(KERN_ERR "%s: expects arguments\n", name); 392 - return -EINVAL; 393 - } 394 311 395 312 *num = 0; 396 313 /* We expect a comma-separated list of values. */ ··· 401 330 /* nul-terminate and parse */ 402 331 save = val[len]; 403 332 ((char *)val)[len] = '\0'; 333 + BUG_ON(!mutex_is_locked(&param_lock)); 404 334 ret = set(val, &kp); 405 335 406 336 if (ret != 0) ··· 419 347 return 0; 420 348 } 421 349 422 - int param_array_set(const char *val, struct kernel_param *kp) 350 + static int param_array_set(const char *val, const struct kernel_param *kp) 423 351 { 424 352 const struct kparam_array *arr = kp->arr; 425 353 unsigned int temp_num; 426 354 427 355 return param_array(kp->name, val, 1, arr->max, arr->elem, 428 - arr->elemsize, arr->set, kp->flags, 356 + arr->elemsize, arr->ops->set, kp->flags, 429 357 arr->num ?: &temp_num); 430 358 } 431 359 432 - int param_array_get(char *buffer, struct kernel_param *kp) 360 + static int param_array_get(char *buffer, const struct kernel_param *kp) 433 361 { 434 362 int i, off, ret; 435 363 const struct kparam_array *arr = kp->arr; ··· 440 368 if (i) 441 369 buffer[off++] = ','; 442 370 p.arg = arr->elem + arr->elemsize * i; 443 - ret = arr->get(buffer + off, &p); 371 + BUG_ON(!mutex_is_locked(&param_lock)); 372 + ret = arr->ops->get(buffer + off, &p); 444 373 if (ret < 0) 445 374 return ret; 446 375 off += ret; ··· 450 377 return off; 451 378 } 452 379 453 - int param_set_copystring(const char *val, struct kernel_param *kp) 380 + static void param_array_free(void *arg) 381 + { 382 + unsigned int i; 383 + const struct kparam_array *arr = arg; 384 + 385 + if (arr->ops->free) 386 + for (i = 0; i < (arr->num ? *arr->num : arr->max); i++) 387 + arr->ops->free(arr->elem + arr->elemsize * i); 388 + } 389 + 390 + struct kernel_param_ops param_array_ops = { 391 + .set = param_array_set, 392 + .get = param_array_get, 393 + .free = param_array_free, 394 + }; 395 + EXPORT_SYMBOL(param_array_ops); 396 + 397 + int param_set_copystring(const char *val, const struct kernel_param *kp) 454 398 { 455 399 const struct kparam_string *kps = kp->str; 456 400 457 - if (!val) { 458 - printk(KERN_ERR "%s: missing param set value\n", kp->name); 459 - return -EINVAL; 460 - } 461 401 if (strlen(val)+1 > kps->maxlen) { 462 402 printk(KERN_ERR "%s: string doesn't fit in %u chars.\n", 463 403 kp->name, kps->maxlen-1); ··· 479 393 strcpy(kps->string, val); 480 394 return 0; 481 395 } 396 + EXPORT_SYMBOL(param_set_copystring); 482 397 483 - int param_get_string(char *buffer, struct kernel_param *kp) 398 + int param_get_string(char *buffer, const struct kernel_param *kp) 484 399 { 485 400 const struct kparam_string *kps = kp->str; 486 401 return strlcpy(buffer, kps->string, kps->maxlen); 487 402 } 403 + EXPORT_SYMBOL(param_get_string); 404 + 405 + struct kernel_param_ops param_ops_string = { 406 + .set = param_set_copystring, 407 + .get = param_get_string, 408 + }; 409 + EXPORT_SYMBOL(param_ops_string); 488 410 489 411 /* sysfs output in /sys/modules/XYZ/parameters/ */ 490 412 #define to_module_attr(n) container_of(n, struct module_attribute, attr) ··· 503 409 struct param_attribute 504 410 { 505 411 struct module_attribute mattr; 506 - struct kernel_param *param; 412 + const struct kernel_param *param; 507 413 }; 508 414 509 415 struct module_param_attrs ··· 522 428 int count; 523 429 struct param_attribute *attribute = to_param_attr(mattr); 524 430 525 - if (!attribute->param->get) 431 + if (!attribute->param->ops->get) 526 432 return -EPERM; 527 433 528 - count = attribute->param->get(buf, attribute->param); 434 + mutex_lock(&param_lock); 435 + count = attribute->param->ops->get(buf, attribute->param); 436 + mutex_unlock(&param_lock); 529 437 if (count > 0) { 530 438 strcat(buf, "\n"); 531 439 ++count; ··· 543 447 int err; 544 448 struct param_attribute *attribute = to_param_attr(mattr); 545 449 546 - if (!attribute->param->set) 450 + if (!attribute->param->ops->set) 547 451 return -EPERM; 548 452 549 - err = attribute->param->set(buf, attribute->param); 453 + mutex_lock(&param_lock); 454 + err = attribute->param->ops->set(buf, attribute->param); 455 + mutex_unlock(&param_lock); 550 456 if (!err) 551 457 return len; 552 458 return err; ··· 562 464 #endif 563 465 564 466 #ifdef CONFIG_SYSFS 467 + void __kernel_param_lock(void) 468 + { 469 + mutex_lock(&param_lock); 470 + } 471 + EXPORT_SYMBOL(__kernel_param_lock); 472 + 473 + void __kernel_param_unlock(void) 474 + { 475 + mutex_unlock(&param_lock); 476 + } 477 + EXPORT_SYMBOL(__kernel_param_unlock); 478 + 565 479 /* 566 480 * add_sysfs_param - add a parameter to sysfs 567 481 * @mk: struct module_kobject ··· 585 475 * if there's an error. 586 476 */ 587 477 static __modinit int add_sysfs_param(struct module_kobject *mk, 588 - struct kernel_param *kp, 478 + const struct kernel_param *kp, 589 479 const char *name) 590 480 { 591 481 struct module_param_attrs *new; ··· 667 557 * /sys/module/[mod->name]/parameters/ 668 558 */ 669 559 int module_param_sysfs_setup(struct module *mod, 670 - struct kernel_param *kparam, 560 + const struct kernel_param *kparam, 671 561 unsigned int num_params) 672 562 { 673 563 int i, err; ··· 712 602 713 603 void destroy_params(const struct kernel_param *params, unsigned num) 714 604 { 715 - /* FIXME: This should free kmalloced charp parameters. It doesn't. */ 605 + unsigned int i; 606 + 607 + for (i = 0; i < num; i++) 608 + if (params[i].ops->free) 609 + params[i].ops->free(params[i].arg); 716 610 } 717 611 718 612 static void __init kernel_add_sysfs_param(const char *name, ··· 882 768 subsys_initcall(param_sysfs_init); 883 769 884 770 #endif /* CONFIG_SYSFS */ 885 - 886 - EXPORT_SYMBOL(param_set_byte); 887 - EXPORT_SYMBOL(param_get_byte); 888 - EXPORT_SYMBOL(param_set_short); 889 - EXPORT_SYMBOL(param_get_short); 890 - EXPORT_SYMBOL(param_set_ushort); 891 - EXPORT_SYMBOL(param_get_ushort); 892 - EXPORT_SYMBOL(param_set_int); 893 - EXPORT_SYMBOL(param_get_int); 894 - EXPORT_SYMBOL(param_set_uint); 895 - EXPORT_SYMBOL(param_get_uint); 896 - EXPORT_SYMBOL(param_set_long); 897 - EXPORT_SYMBOL(param_get_long); 898 - EXPORT_SYMBOL(param_set_ulong); 899 - EXPORT_SYMBOL(param_get_ulong); 900 - EXPORT_SYMBOL(param_set_charp); 901 - EXPORT_SYMBOL(param_get_charp); 902 - EXPORT_SYMBOL(param_set_bool); 903 - EXPORT_SYMBOL(param_get_bool); 904 - EXPORT_SYMBOL(param_set_invbool); 905 - EXPORT_SYMBOL(param_get_invbool); 906 - EXPORT_SYMBOL(param_array_set); 907 - EXPORT_SYMBOL(param_array_get); 908 - EXPORT_SYMBOL(param_set_copystring); 909 - EXPORT_SYMBOL(param_get_string);
+2
net/mac80211/rate.c
··· 103 103 struct rate_control_ops *ops; 104 104 const char *alg_name; 105 105 106 + kparam_block_sysfs_write(ieee80211_default_rc_algo); 106 107 if (!name) 107 108 alg_name = ieee80211_default_rc_algo; 108 109 else ··· 121 120 /* try built-in one if specific alg requested but not found */ 122 121 if (!ops && strlen(CONFIG_MAC80211_RC_DEFAULT)) 123 122 ops = ieee80211_try_rate_control_ops_get(CONFIG_MAC80211_RC_DEFAULT); 123 + kparam_unblock_sysfs_write(ieee80211_default_rc_algo); 124 124 125 125 return ops; 126 126 }
+7 -2
net/sunrpc/auth.c
··· 39 39 static unsigned long number_cred_unused; 40 40 41 41 #define MAX_HASHTABLE_BITS (10) 42 - static int param_set_hashtbl_sz(const char *val, struct kernel_param *kp) 42 + static int param_set_hashtbl_sz(const char *val, const struct kernel_param *kp) 43 43 { 44 44 unsigned long num; 45 45 unsigned int nbits; ··· 61 61 return -EINVAL; 62 62 } 63 63 64 - static int param_get_hashtbl_sz(char *buffer, struct kernel_param *kp) 64 + static int param_get_hashtbl_sz(char *buffer, const struct kernel_param *kp) 65 65 { 66 66 unsigned int nbits; 67 67 ··· 70 70 } 71 71 72 72 #define param_check_hashtbl_sz(name, p) __param_check(name, p, unsigned int); 73 + 74 + static struct kernel_param_ops param_ops_hashtbl_sz = { 75 + .set = param_set_hashtbl_sz, 76 + .get = param_get_hashtbl_sz, 77 + }; 73 78 74 79 module_param_named(auth_hashtable_size, auth_hashbits, hashtbl_sz, 0644); 75 80 MODULE_PARM_DESC(auth_hashtable_size, "RPC credential cache hashtable size");
+15 -11
net/sunrpc/xprtsock.c
··· 2577 2577 xprt_unregister_transport(&xs_bc_tcp_transport); 2578 2578 } 2579 2579 2580 - static int param_set_uint_minmax(const char *val, struct kernel_param *kp, 2580 + static int param_set_uint_minmax(const char *val, 2581 + const struct kernel_param *kp, 2581 2582 unsigned int min, unsigned int max) 2582 2583 { 2583 2584 unsigned long num; ··· 2593 2592 return 0; 2594 2593 } 2595 2594 2596 - static int param_set_portnr(const char *val, struct kernel_param *kp) 2595 + static int param_set_portnr(const char *val, const struct kernel_param *kp) 2597 2596 { 2598 2597 return param_set_uint_minmax(val, kp, 2599 2598 RPC_MIN_RESVPORT, 2600 2599 RPC_MAX_RESVPORT); 2601 2600 } 2602 2601 2603 - static int param_get_portnr(char *buffer, struct kernel_param *kp) 2604 - { 2605 - return param_get_uint(buffer, kp); 2606 - } 2602 + static struct kernel_param_ops param_ops_portnr = { 2603 + .set = param_set_portnr, 2604 + .get = param_get_uint, 2605 + }; 2606 + 2607 2607 #define param_check_portnr(name, p) \ 2608 2608 __param_check(name, p, unsigned int); 2609 2609 2610 2610 module_param_named(min_resvport, xprt_min_resvport, portnr, 0644); 2611 2611 module_param_named(max_resvport, xprt_max_resvport, portnr, 0644); 2612 2612 2613 - static int param_set_slot_table_size(const char *val, struct kernel_param *kp) 2613 + static int param_set_slot_table_size(const char *val, 2614 + const struct kernel_param *kp) 2614 2615 { 2615 2616 return param_set_uint_minmax(val, kp, 2616 2617 RPC_MIN_SLOT_TABLE, 2617 2618 RPC_MAX_SLOT_TABLE); 2618 2619 } 2619 2620 2620 - static int param_get_slot_table_size(char *buffer, struct kernel_param *kp) 2621 - { 2622 - return param_get_uint(buffer, kp); 2623 - } 2621 + static struct kernel_param_ops param_ops_slot_table_size = { 2622 + .set = param_set_slot_table_size, 2623 + .get = param_get_uint, 2624 + }; 2625 + 2624 2626 #define param_check_slot_table_size(name, p) \ 2625 2627 __param_check(name, p, unsigned int); 2626 2628
+13
scripts/mod/modpost.c
··· 1035 1035 * fromsec = .data* 1036 1036 * atsym =__param* 1037 1037 * 1038 + * Pattern 1a: 1039 + * module_param_call() ops can refer to __init set function if permissions=0 1040 + * The pattern is identified by: 1041 + * tosec = .init.text 1042 + * fromsec = .data* 1043 + * atsym = __param_ops_* 1044 + * 1038 1045 * Pattern 2: 1039 1046 * Many drivers utilise a *driver container with references to 1040 1047 * add, remove, probe functions etc. ··· 1074 1067 if (match(tosec, init_data_sections) && 1075 1068 match(fromsec, data_sections) && 1076 1069 (strncmp(fromsym, "__param", strlen("__param")) == 0)) 1070 + return 0; 1071 + 1072 + /* Check for pattern 1a */ 1073 + if (strcmp(tosec, ".init.text") == 0 && 1074 + match(fromsec, data_sections) && 1075 + (strncmp(fromsym, "__param_ops_", strlen("__param_ops_")) == 0)) 1077 1076 return 0; 1078 1077 1079 1078 /* Check for pattern 2 */
+24 -12
security/apparmor/lsm.c
··· 667 667 * AppArmor sysfs module parameters 668 668 */ 669 669 670 - static int param_set_aabool(const char *val, struct kernel_param *kp); 671 - static int param_get_aabool(char *buffer, struct kernel_param *kp); 670 + static int param_set_aabool(const char *val, const struct kernel_param *kp); 671 + static int param_get_aabool(char *buffer, const struct kernel_param *kp); 672 672 #define param_check_aabool(name, p) __param_check(name, p, int) 673 + static struct kernel_param_ops param_ops_aabool = { 674 + .set = param_set_aabool, 675 + .get = param_get_aabool 676 + }; 673 677 674 - static int param_set_aauint(const char *val, struct kernel_param *kp); 675 - static int param_get_aauint(char *buffer, struct kernel_param *kp); 678 + static int param_set_aauint(const char *val, const struct kernel_param *kp); 679 + static int param_get_aauint(char *buffer, const struct kernel_param *kp); 676 680 #define param_check_aauint(name, p) __param_check(name, p, int) 681 + static struct kernel_param_ops param_ops_aauint = { 682 + .set = param_set_aauint, 683 + .get = param_get_aauint 684 + }; 677 685 678 - static int param_set_aalockpolicy(const char *val, struct kernel_param *kp); 679 - static int param_get_aalockpolicy(char *buffer, struct kernel_param *kp); 686 + static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp); 687 + static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp); 680 688 #define param_check_aalockpolicy(name, p) __param_check(name, p, int) 689 + static struct kernel_param_ops param_ops_aalockpolicy = { 690 + .set = param_set_aalockpolicy, 691 + .get = param_get_aalockpolicy 692 + }; 681 693 682 694 static int param_set_audit(const char *val, struct kernel_param *kp); 683 695 static int param_get_audit(char *buffer, struct kernel_param *kp); ··· 763 751 __setup("apparmor=", apparmor_enabled_setup); 764 752 765 753 /* set global flag turning off the ability to load policy */ 766 - static int param_set_aalockpolicy(const char *val, struct kernel_param *kp) 754 + static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp) 767 755 { 768 756 if (!capable(CAP_MAC_ADMIN)) 769 757 return -EPERM; ··· 772 760 return param_set_bool(val, kp); 773 761 } 774 762 775 - static int param_get_aalockpolicy(char *buffer, struct kernel_param *kp) 763 + static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp) 776 764 { 777 765 if (!capable(CAP_MAC_ADMIN)) 778 766 return -EPERM; 779 767 return param_get_bool(buffer, kp); 780 768 } 781 769 782 - static int param_set_aabool(const char *val, struct kernel_param *kp) 770 + static int param_set_aabool(const char *val, const struct kernel_param *kp) 783 771 { 784 772 if (!capable(CAP_MAC_ADMIN)) 785 773 return -EPERM; 786 774 return param_set_bool(val, kp); 787 775 } 788 776 789 - static int param_get_aabool(char *buffer, struct kernel_param *kp) 777 + static int param_get_aabool(char *buffer, const struct kernel_param *kp) 790 778 { 791 779 if (!capable(CAP_MAC_ADMIN)) 792 780 return -EPERM; 793 781 return param_get_bool(buffer, kp); 794 782 } 795 783 796 - static int param_set_aauint(const char *val, struct kernel_param *kp) 784 + static int param_set_aauint(const char *val, const struct kernel_param *kp) 797 785 { 798 786 if (!capable(CAP_MAC_ADMIN)) 799 787 return -EPERM; 800 788 return param_set_uint(val, kp); 801 789 } 802 790 803 - static int param_get_aauint(char *buffer, struct kernel_param *kp) 791 + static int param_get_aauint(char *buffer, const struct kernel_param *kp) 804 792 { 805 793 if (!capable(CAP_MAC_ADMIN)) 806 794 return -EPERM;