Skip to content

Commit 45fcc70

Browse files
committed
module_param: split perm field into flags and perm
Impact: cleanup Rather than hack KPARAM_KMALLOCED into the perm field, separate it out. Since the perm field was 32 bits and only needs 16, we don't add bloat. Signed-off-by: Rusty Russell <[email protected]>
1 parent 9a71af2 commit 45fcc70

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

include/linux/moduleparam.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ typedef int (*param_set_fn)(const char *val, struct kernel_param *kp);
3636
/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
3737
typedef int (*param_get_fn)(char *buffer, struct kernel_param *kp);
3838

39+
/* Flag bits for kernel_param.flags */
40+
#define KPARAM_KMALLOCED 1
41+
3942
struct kernel_param {
4043
const char *name;
41-
unsigned int perm;
44+
u16 perm;
45+
u16 flags;
4246
param_set_fn set;
4347
param_get_fn get;
4448
union {
@@ -88,7 +92,7 @@ struct kparam_array
8892
static struct kernel_param __moduleparam_const __param_##name \
8993
__used \
9094
__attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
91-
= { __param_str_##name, perm, set, get, { arg } }
95+
= { __param_str_##name, perm, 0, set, get, { arg } }
9296

9397
#define module_param_call(name, set, get, arg, perm) \
9498
__module_param_call(MODULE_PARAM_PREFIX, name, set, get, arg, perm)

kernel/params.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
#include <linux/err.h>
2525
#include <linux/slab.h>
2626

27-
/* We abuse the high bits of "perm" to record whether we kmalloc'ed. */
28-
#define KPARAM_KMALLOCED 0x80000000
29-
3027
#if 0
3128
#define DEBUGP printk
3229
#else
@@ -220,13 +217,13 @@ int param_set_charp(const char *val, struct kernel_param *kp)
220217
return -ENOSPC;
221218
}
222219

223-
if (kp->perm & KPARAM_KMALLOCED)
220+
if (kp->flags & KPARAM_KMALLOCED)
224221
kfree(*(char **)kp->arg);
225222

226223
/* This is a hack. We can't need to strdup in early boot, and we
227224
* don't need to; this mangled commandline is preserved. */
228225
if (slab_is_available()) {
229-
kp->perm |= KPARAM_KMALLOCED;
226+
kp->flags |= KPARAM_KMALLOCED;
230227
*(char **)kp->arg = kstrdup(val, GFP_KERNEL);
231228
if (!kp->arg)
232229
return -ENOMEM;
@@ -591,7 +588,7 @@ void destroy_params(const struct kernel_param *params, unsigned num)
591588
unsigned int i;
592589

593590
for (i = 0; i < num; i++)
594-
if (params[i].perm & KPARAM_KMALLOCED)
591+
if (params[i].flags & KPARAM_KMALLOCED)
595592
kfree(*(char **)params[i].arg);
596593
}
597594

0 commit comments

Comments
 (0)