lkml.org 
[lkml]   [2004]   [Jun]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: Coding style questions for patches..
On Saturday June 12, Valdis.Kletnieks@vt.edu 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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:03    [W:0.047 / U:0.328 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site