Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757332Ab2BCRf4 (ORCPT ); Fri, 3 Feb 2012 12:35:56 -0500 Received: from terminus.zytor.com ([198.137.202.10]:58257 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757272Ab2BCRfz (ORCPT ); Fri, 3 Feb 2012 12:35:55 -0500 Message-ID: <4F2C1AC9.7090509@zytor.com> Date: Fri, 03 Feb 2012 09:35:05 -0800 From: "H. Peter Anvin" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111222 Thunderbird/9.0 MIME-Version: 1.0 To: Cyrill Gorcunov CC: Andrew Morton , Ingo Molnar , linux-kernel@vger.kernel.org, Pavel Emelyanov , Serge Hallyn , KAMEZAWA Hiroyuki , Kees Cook , Tejun Heo , Andrew Vagin , "Eric W. Biederman" , Alexey Dobriyan , Andi Kleen , KOSAKI Motohiro , Thomas Gleixner , Glauber Costa , Matt Helsley , Pekka Enberg , Eric Dumazet , Vasiliy Kulikov , Valdis.Kletnieks@vt.edu Subject: Re: [patch cr 2/4] [RFC] syscalls, x86: Add __NR_kcmp syscall v7 References: <20120130140905.441199885@openvz.org> <20120130141852.309402052@openvz.org> <20120203074656.GC30543@elte.hu> <20120203083530.GD1968@moon> <20120203090929.GA23996@elte.hu> <20120203012241.bcd3d0c8.akpm@linux-foundation.org> <20120203092823.GE1968@moon> <4F2C1A46.4010105@zytor.com> In-Reply-To: <4F2C1A46.4010105@zytor.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1507 Lines: 60 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; } -- 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/