Skip to content

Commit

Permalink
param: add a free hook to kernel_param_ops.
Browse files Browse the repository at this point in the history
This allows us to generalize the KPARAM_KMALLOCED flag, by calling a function
on every parameter when a module is unloaded.

Signed-off-by: Rusty Russell <[email protected]>
Reviewed-by: Takashi Iwai <[email protected]>
Tested-by: Phil Carmody <[email protected]>
  • Loading branch information
rustyrussell committed Aug 11, 2010
1 parent 6a84152 commit e6df34a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/linux/moduleparam.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ struct kernel_param_ops {
int (*set)(const char *val, const struct kernel_param *kp);
/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
int (*get)(char *buffer, const struct kernel_param *kp);
/* Optional function to free kp->arg when module unloaded. */
void (*free)(void *arg);
};

/* Flag bits for kernel_param.flags */
Expand Down
17 changes: 16 additions & 1 deletion kernel/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,20 @@ static int param_array_get(char *buffer, const struct kernel_param *kp)
return off;
}

static void param_array_free(void *arg)
{
unsigned int i;
const struct kparam_array *arr = arg;

if (arr->ops->free)
for (i = 0; i < (arr->num ? *arr->num : arr->max); i++)
arr->ops->free(arr->elem + arr->elemsize * i);
}

struct kernel_param_ops param_array_ops = {
.set = param_array_set,
.get = param_array_get,
.free = param_array_free,
};
EXPORT_SYMBOL(param_array_ops);

Expand Down Expand Up @@ -634,7 +645,11 @@ void module_param_sysfs_remove(struct module *mod)

void destroy_params(const struct kernel_param *params, unsigned num)
{
/* FIXME: This should free kmalloced charp parameters. It doesn't. */
unsigned int i;

for (i = 0; i < num; i++)
if (params[i].ops->free)
params[i].ops->free(params[i].arg);
}

static void __init kernel_add_sysfs_param(const char *name,
Expand Down

0 comments on commit e6df34a

Please sign in to comment.