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 09:32 AM, H. Peter Anvin wrote:
> 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?
>

Even better:

static __init int kcmp_cookie_init(void)
{
int i;

get_random_bytes(cookies, sizeof cookies);

for (i = 0; i < KCMP_TYPES; i++)
cookies[i][1] |= ~(~0UL >> 1) | 1;
}



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