Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some optimizations #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 34 additions & 32 deletions kernel/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,12 @@ static char *next_arg(char *args, char **param, char **val)
quoted = 1;
}

for (i = 0; args[i]; i++) {
if (isspace(args[i]) && !in_quote)
break;
if (equals == 0) {
if (args[i] == '=')
for (i = 0; args[i] && !(isspace(args[i]) && !in_quote); i++) {
if (args[i] == '=') {
if (!equals)
equals = i;
}
if (args[i] == '"')
else if (args[i] == '"')
in_quote = !in_quote;
}

Expand All @@ -170,18 +168,18 @@ static char *next_arg(char *args, char **param, char **val)
/* Don't include quotes in value. */
if (**val == '"') {
(*val)++;
if (args[i-1] == '"')
args[i-1] = '\0';
quoted = 1;
}
if (quoted && args[i-1] == '"')
args[i-1] = '\0';
}

next = args + i;

if (args[i]) {
args[i] = '\0';
next = args + i + 1;
} else
next = args + i;
++next;
}

/* Chew up trailing spaces. */
return skip_spaces(next);
Expand Down Expand Up @@ -210,7 +208,7 @@ char *parse_args(const char *doing,

args = next_arg(args, &param, &val);
/* Stop at -- */
if (!val && strcmp(param, "--") == 0)
if (!val && strncmp(param, "--", 3) == 0)
return args;
irq_was_disabled = irqs_disabled();
ret = parse_one(param, val, doing, params, num,
Expand Down Expand Up @@ -271,7 +269,9 @@ STANDARD_PARAM_DEF(ullong, unsigned long long, "%llu", kstrtoull);

int param_set_charp(const char *val, const struct kernel_param *kp)
{
if (strlen(val) > 1024) {
const size_t val_len = strlen(val);

if (val_len > 1024) {
pr_err("%s: string parameter too long\n", kp->name);
return -ENOSPC;
}
Expand All @@ -281,10 +281,10 @@ int param_set_charp(const char *val, const struct kernel_param *kp)
/* This is a hack. We can't kmalloc in early boot, and we
* don't need to; this mangled commandline is preserved. */
if (slab_is_available()) {
*(char **)kp->arg = kmalloc_parameter(strlen(val)+1);
*(char **)kp->arg = kmalloc_parameter(val_len+1);
if (!*(char **)kp->arg)
return -ENOMEM;
strcpy(*(char **)kp->arg, val);
strncpy(*(char **)kp->arg, val, val_len + 1);
} else
*(const char **)kp->arg = val;

Expand Down Expand Up @@ -447,12 +447,13 @@ static int param_array_set(const char *val, const struct kernel_param *kp)

static int param_array_get(char *buffer, const struct kernel_param *kp)
{
int i, off, ret;
int i, off, ret, max;
const struct kparam_array *arr = kp->arr;
struct kernel_param p;

p = *kp;
for (i = off = 0; i < (arr->num ? *arr->num : arr->max); i++) {
max = (arr->num ? *arr->num : arr->max);
for (i = off = 0; i < max; i++) {
if (i)
buffer[off++] = ',';
p.arg = arr->elem + arr->elemsize * i;
Expand All @@ -468,12 +469,15 @@ static int param_array_get(char *buffer, const struct kernel_param *kp)

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

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

struct kernel_param_ops param_array_ops = {
Expand All @@ -486,13 +490,14 @@ EXPORT_SYMBOL(param_array_ops);
int param_set_copystring(const char *val, const struct kernel_param *kp)
{
const struct kparam_string *kps = kp->str;
const size_t val_len = strlen(val);

if (strlen(val)+1 > kps->maxlen) {
if (val_len + 1 > kps->maxlen) {
pr_err("%s: string doesn't fit in %u chars.\n",
kp->name, kps->maxlen-1);
return -ENOSPC;
}
strcpy(kps->string, val);
strncpy(kps->string, val, val_len + 1);
return 0;
}
EXPORT_SYMBOL(param_set_copystring);
Expand Down Expand Up @@ -719,12 +724,12 @@ int module_param_sysfs_setup(struct module *mod,
*/
void module_param_sysfs_remove(struct module *mod)
{
if (mod->mkobj.mp) {
sysfs_remove_group(&mod->mkobj.kobj, &mod->mkobj.mp->grp);
/* We are positive that no one is using any param
* attrs at this point. Deallocate immediately. */
free_module_param_attrs(&mod->mkobj);
}
if (!mod->mkobj.mp)
return ;
sysfs_remove_group(&mod->mkobj.kobj, &mod->mkobj.mp->grp);
/* We are positive that no one is using any param
* attrs at this point. Deallocate immediately. */
free_module_param_attrs(&mod->mkobj);
}
#endif

Expand Down Expand Up @@ -821,7 +826,7 @@ static void __init param_sysfs_builtin(void)
dot = strchr(kp->name, '.');
if (!dot) {
/* This happens for core_param() */
strcpy(modname, "kernel");
strncpy(modname, "kernel", sizeof("kernel"));
name_len = 0;
} else {
name_len = dot - kp->name + 1;
Expand Down Expand Up @@ -888,17 +893,14 @@ static ssize_t module_attr_store(struct kobject *kobj,
{
struct module_attribute *attribute;
struct module_kobject *mk;
int ret;

attribute = to_module_attr(attr);
mk = to_module_kobject(kobj);

if (!attribute->store)
return -EIO;

ret = attribute->store(attribute, mk, buf, len);

return ret;
return (attribute->store(attribute, mk, buf, len));
}

static const struct sysfs_ops module_sysfs_ops = {
Expand Down