From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Weinberger Subject: Re: [PATCH] Make efi-pstore return a unique id Date: Fri, 01 Nov 2013 21:08:26 +0100 Message-ID: <52740A3A.70202@nod.at> References: <87ppqk6qvx.fsf@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: linux-efi-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Seiji Aguchi Cc: Tony Luck , Madper Xie , "matt.fleming-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org" , linux-kernel , Linux EFI , =?GB2312?B?0Luzyb+l?= List-Id: linux-efi@vger.kernel.org Am 01.11.2013 20:22, schrieb Seiji Aguchi: >>>> +{ >>>> + char id_str[64]; >>>> + u64 id = 0; >>>> + >>>> + sprintf(id_str, "%lu%u%d", timestamp, part, count); >>>> + if (kstrtoull(id_str, 10, &id)) >>>> + pr_warn("efi-pstore: failed to generate id\n"); >>>> + return id; >>>> +} >>> >>> This is just odd. You make a string from three ints and then a parse >>> it to a int again. >> >> Agreed. I liked your ((timestamp * 100 + part) * 100 + count function much >> more than this. > > I was worried that the part and count could be more than 100. > If it happens, the id may not be unique... > > But, currently, size of nvram storage is limited, so it is a corner case. > I respect your opinion. What about feeding the bytes of all three integers into a non-cryptographic hash function? Using this way you get a cheap unique id. Thanks, //richard