Re: [patch cr 2/4] [RFC] syscalls, x86: Add __NR_kcmp syscall v7

H. Peter Anvin
2012-02-03T17:33:58Z

On 02/03/2012 01:28 AM, Cyrill Gorcunov wrote:
> static __init int kcmp_cookie_init(void)
> {
> int i, j;
>
> for (i = 0; i< KCMP_TYPES; i++) {
> for (j = 0; j< 2; j++)
> get_random_bytes(&cookies[i][j], sizeof(long));
> cookies[i][1] |= (~(~0UL>> 1) | 1);
> }
>
> return 0;
> }
>
> I thought in first place that sizeof(cookies[i][j]) would allow me
> to change type of cookies in one place (ie at declaration) but
> if cookies type will be changed -- the code will need careful review
> anway, so sizeof(long) will be enough I think.
>
> On the other hands, maybe more clean variant will be
>
> static __init int kcmp_cookie_init(void)
> {
> const int size = sizeof(cookies[0][0]);
> int i, j;
>
> for (i = 0; i< KCMP_TYPES; i++) {
> for (j = 0; j< 2; j++)
> get_random_bytes(&cookies[i][j], size);
> cookies[i][1] |= (~(~0UL>> 1) | 1);
> }
>

How about:

const int size = sizeof(cookies[0]);

get_random_bytes(&cookies[i], size);

... and skip the completely unnecessary for loop?

-hpa