lkml.org 
[lkml]   [2012]   [Feb]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [patch cr 2/4] [RFC] syscalls, x86: Add __NR_kcmp syscall v7
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



\
 
 \ /
  Last update: 2012-02-03 18:37    [W:0.207 / U:0.240 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site