Re: [PATCH] per-task delay accounting taskstats interface: control exit data through cpumasks]
From: Thomas Graf
Date: Thu Jul 06 2006 - 18:38:22 EST
* Andrew Morton <akpm@xxxxxxxx> 2006-07-06 14:48
> In the interests of keeping this work decoupled from netlink enhancements
> I'd propose the below. Is it bad to modify the data at nla_data()?
Yes, it points into a skb data buffer which may be shared by sitting
on other queues if the message is to be broadcasted. In this case it
would be harmless but the policy is to leave it unmodified. Otherwise
I agree it's better to move forward and not wait for the API change.
> --- a/kernel/taskstats.c~per-task-delay-accounting-taskstats-interface-control-exit-data-through-cpumasks-fix
> +++ a/kernel/taskstats.c
> @@ -299,6 +299,23 @@ cleanup:
> return 0;
> }
>
> +static int parse(struct nlattr *na, cpumask_t *mask)
> +{
> + char *data;
> + int len;
> +
> + if (na == NULL)
> + return 1;
> + len = nla_len(na);
> + if (len > TASKSTATS_CPUMASK_MAXLEN)
> + return -E2BIG;
> + if (len < 1)
> + return -EINVAL;
> + data = nla_data(na);
> + data[len - 1] = '\0';
> + return cpulist_parse(data, *mask);
> +}
Usually this is done by using strlcpy:
Example fro genetlink.c
if (info->attrs[CTRL_ATTR_FAMILY_NAME]) {
char name[GENL_NAMSIZ];
if (nla_strlcpy(name, info->attrs[CTRL_ATTR_FAMILY_NAME],
GENL_NAMSIZ) >= GENL_NAMSIZ)
goto errout;
res = genl_family_find_byname(name);
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/