Re: Coding style questions for patches..

From: Neil Brown
Date: Sun Jun 13 2004 - 18:57:51 EST


On Saturday June 12, Valdis.Kletnieks@xxxxxx wrote:
>
> Straw-man sample code for illustration:
>
> --- include/linux/pid.h.vt 2003-09-27 20:50:13.000000000 -0400
> +++ include/linux/pid.h 2004-06-12 15:29:02.507247676 -0400
> @@ -61,4 +61,22 @@ extern void switch_exec_pids(struct task
> elem = elem->next, prefetch(elem->next), \
> task = pid_task(elem, type))
>
> +#ifdef CONFIG_SECURITY_RANDPID
> +#include <linux/random.h>
> +extern int security_enable_randpid;
> +
> +static inline int alloc_next_pid(int last_pid) {
> + int next;
> + if (security_enable_randpid && (last_pid >= RESERVED_PIDS)) {
> + pid = (get_random_long() % (pid_max - RESERVED_PIDS)) + RESERVED_PIDS + 1;
> + }
> + else next = last_pid + 1;
> + return next;
> +}
> +#else
> +static inline int alloc_next_pid(int last_pid) {
> + return last_pid + 1;
> +}
> +#endif
> +

This would look better as:

#ifdef CONFIG_SECURITY_RANDPID
#include <linux/random>
extern int security_enable_randpid;
#else
#define security_enable_randpid (0)
#endif

static inline int alloc_next_pid(int last_pid) {
int next;
if (security_enable_randpid && (last_pid >= RESERVED_PIDS)) {
pid = (get_random_long() % (pid_max - RESERVED_PIDS)) + RESERVED_PIDS + 1;
}
else next = last_pid + 1;
return next;
}

and should compile to exactly the same code.
(I know that leaves a lot of your questions unanswered, but I'll leave
that to someone else).

NeilBrown
-
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/