From: Przemyslaw Marczak <p.marczak@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2 2/3] lib: uuid: add functions to generate UUID version 4
Date: Thu, 13 Mar 2014 19:10:50 +0100 [thread overview]
Message-ID: <5321F4AA.4000402@samsung.com> (raw)
In-Reply-To: <531DF853.5040609@wwwdotorg.org>
Hello again,
On 03/10/2014 06:37 PM, Stephen Warren wrote:
> On 03/05/2014 09:45 AM, Przemyslaw Marczak wrote:
>> This patch adds support to generate UUID (Universally Unique Identifier)
>> in version 4 based on RFC4122, which is randomly.
>>
>> Source: https://www.ietf.org/rfc/rfc4122.txt
>>
>> Changes:
>> - add new config: CONFIG_RANDOM_UUID: compile uuid.c and rand.c
>>
>> Update files:
>> - include/common.h
>> - lib/Makefile
>> - lib/uuid.c
>
> The patch already contains the list of changed files; there's little
> point duplicating this in the patch description.
>
>> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
>> cc: Stephen Warren <swarren@nvidia.com>
>> cc: trini at ti.com
>
> s/cc/Cc/
>
>> diff --git a/lib/Makefile b/lib/Makefile
>> index 70962b2..64a430f 100644
>> --- a/lib/Makefile
>> +++ b/lib/Makefile
>> @@ -59,10 +59,12 @@ obj-y += linux_string.o
>> obj-$(CONFIG_REGEX) += slre.o
>> obj-y += string.o
>> obj-y += time.o
>> +obj-y += vsprintf.o
>
> Moving vsprintf.o seems entirely unrelated to this patch. If you want to
> clean that up, it should be a separate patch.
>
>> obj-$(CONFIG_TRACE) += trace.o
>> obj-$(CONFIG_BOOTP_PXE) += uuid.o
>> obj-$(CONFIG_PARTITION_UUIDS) += uuid.o
>> -obj-y += vsprintf.o
>> +obj-$(CONFIG_RANDOM_UUID) += uuid.o
>> +obj-$(CONFIG_RANDOM_UUID) += rand.o
>> obj-$(CONFIG_RANDOM_MACADDR) += rand.o
>
> I really hope listing the same object multiple times in obj-y is OK.
>
> Why not sort the lines you added so based on the config variable, so
>
>> obj-$(CONFIG_RANDOM_MACADDR) += rand.o
>> +obj-$(CONFIG_RANDOM_UUID) += rand.o
>
> rather than:
>
>> +obj-$(CONFIG_RANDOM_UUID) += rand.o
>> obj-$(CONFIG_RANDOM_MACADDR) += rand.o
>
>> diff --git a/lib/uuid.c b/lib/uuid.c
>> index 803bdcd..c0218ba 100644
>> --- a/lib/uuid.c
>> +++ b/lib/uuid.c
>> @@ -7,6 +7,29 @@
>> #include <linux/ctype.h>
>> #include <errno.h>
>> #include <common.h>
>> +#include <part_efi.h>
>> +#include <malloc.h>
>> +
>> +#define UUID_STR_LEN 36
>> +#define UUID_STR_BYTE_LEN 37
>
> If UUID_STR_BYTE_LEN is the length in bytes, what units is UUID_STR_LEN
> in? I suppose the difference is the NULL terminator, but the names don't
> make that clear at all. I would suggest not defining UUID_STR_BYTE_LEN
> at all, but rather just writing "+ 1" at the appropriate place in the
> source code.
>
>> +#define UUID_BIN_BYTE_LEN 16
>
> Also, s/_BYTE// there.
>
>> +#define UUID_VERSION_CLEAR_BITS 0x0fff
>
> s/CLEAR_BITS/MASK/
>
>> +struct uuid {
>> + unsigned int time_low;
>> + unsigned short time_mid;
>> + unsigned short time_hi_and_version;
>> + unsigned char clock_seq_hi_and_reserved;
>> + unsigned char clock_seq_low;
>> + unsigned char node[6];
>> +};
>
> Is that structure definition endianness-safe?
>
UUID format is big-endian.
Actually for version 4 it doesn't matter because of it is random, and
RFC says that version and variant are the most significant bits of
proper structure field. In this code version and variant mask are stored
at most significant bits - so this is big endian.
Actually we uses it as a string and as you can check in generated uuids
its proper. As wiki says:
"Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
where x is any hexadecimal digit and y is one of 8, 9, A, or B (e.g.,
f47ac10b-58cc-4372-a567-0e02b2c3d479)."
Even if this code runs on big-endian machine, version and variant are
still set properly (most significant bits).
>> +/*
>> + * gen_rand_uuid() - this function generates 16 bytes len UUID V4 (randomly)
>> + * and stores it at a given pointer.
>
> I think "this function generates a random binary UUID v4, and stores it
> into the memory pointed at by the supplied pointer, which must be 16
> bytes in size" would be better.
>
>> +void gen_rand_uuid(unsigned char *uuid_bin)
>> +{
>> + struct uuid *uuid = (struct uuid *)uuid_bin;
>> + unsigned int *ptr = (unsigned int *)uuid_bin;
>> + int i;
>> +
>> + if (!uuid_bin)
>> + return;
>
> I think you should either (a) assume NULL will never be passed to this
> function, or (b) return an error code if it happens. Silently failing to
> do anything doesn't make sense.
>
>> + memset(uuid_bin, 0x0, sizeof(struct uuid));
>> +
>> + /* Set all fields randomly */
>> + for (i = 0; i < sizeof(struct uuid) / sizeof(*ptr); i++)
>> + *(ptr + i) = rand();
>
> If the entire thing is filled randomly, why memset() the struct?
>
>
>> +/*
>> + * gen_rand_uuid_str() - this function generates UUID v4 (randomly)
>> + * into 36 character hexadecimal ASCII string representation of a 128-bit
>> + * (16 octets) UUID (Universally Unique Identifier) version 4 based on RFC4122
>> + * and stores it at a given pointer.
>
> There's a lot of duplication in that description. I think "this function
> generates a random string-formatted UUID v4, and stores it into the
> memory pointed at by the supplied pointer, which must be 37 bytes in
> size" would be better.
>
>> +void gen_rand_uuid_str(char *uuid_str)
>> +{
>> + unsigned char uuid_bin[UUID_BIN_BYTE_LEN];
>> +
>> + if (!uuid_str)
>> + return;
>
> Again, I would drop that error-checking.
>
I also apply other comments to V3.
Thanks
--
Przemyslaw Marczak
Samsung R&D Institute Poland
Samsung Electronics
p.marczak at samsung.com
next prev parent reply other threads:[~2014-03-13 18:10 UTC|newest]
Thread overview: 90+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-28 15:18 [U-Boot] [PATCH 1/2] lib: uuid: add function to generate UUID version 4 Przemyslaw Marczak
2014-02-28 15:18 ` [U-Boot] [PATCH 2/2] cmd:gpt: randomly generate each partition uuid if undefined Przemyslaw Marczak
2014-02-28 17:03 ` Stephen Warren
2014-03-03 13:45 ` Przemyslaw Marczak
2014-03-03 14:13 ` Tom Rini
2014-03-03 15:31 ` Przemyslaw Marczak
2014-03-03 16:46 ` Tom Rini
2014-03-03 17:23 ` Przemyslaw Marczak
2014-03-03 17:35 ` Tom Rini
2014-03-03 17:58 ` Przemyslaw Marczak
2014-02-28 16:55 ` [U-Boot] [PATCH 1/2] lib: uuid: add function to generate UUID version 4 Stephen Warren
2014-03-03 13:44 ` Przemyslaw Marczak
2014-03-03 17:47 ` Stephen Warren
2014-03-05 16:45 ` [U-Boot] [PATCH V2 1/3] part_efi: move uuid_string() and string_uuid() to lib/uuid.c Przemyslaw Marczak
2014-03-05 16:45 ` [U-Boot] [PATCH V2 2/3] lib: uuid: add functions to generate UUID version 4 Przemyslaw Marczak
2014-03-10 17:37 ` Stephen Warren
2014-03-13 18:10 ` Przemyslaw Marczak [this message]
2014-03-13 18:41 ` Wolfgang Denk
2014-03-13 18:41 ` Wolfgang Denk
2014-03-13 19:18 ` Tom Rini
2014-03-13 19:48 ` Wolfgang Denk
2014-03-13 19:55 ` Stephen Warren
2014-03-13 19:51 ` Przemyslaw Marczak
2014-03-05 16:45 ` [U-Boot] [PATCH V2 3/3] cmd:gpt: randomly generate each partition uuid if undefined Przemyslaw Marczak
2014-03-10 17:44 ` Stephen Warren
2014-03-13 17:28 ` Przemyslaw Marczak
2014-03-13 19:49 ` Stephen Warren
2014-03-13 20:13 ` Przemyslaw Marczak
2014-03-10 17:24 ` [U-Boot] [PATCH V2 1/3] part_efi: move uuid_string() and string_uuid() to lib/uuid.c Stephen Warren
2014-03-10 17:28 ` Tom Rini
2014-03-10 17:52 ` Tom Rini
2014-03-10 17:29 ` Stephen Warren
2014-03-10 17:39 ` Tom Rini
2014-03-14 14:37 ` [U-Boot] [PATCH v3 1/3] part_efi: move uuid<->string conversion functions into lib/uuid.c Przemyslaw Marczak
2014-03-14 14:37 ` [U-Boot] [PATCH v3 2/3] lib: uuid: add functions to generate UUID version 4 Przemyslaw Marczak
2014-03-14 16:12 ` Wolfgang Denk
2014-03-17 9:16 ` Przemyslaw Marczak
2014-03-14 14:37 ` [U-Boot] [PATCH v3 3/3] cmd:gpt: randomly generate each partition uuid if undefined Przemyslaw Marczak
2014-03-14 16:16 ` Wolfgang Denk
2014-03-17 9:17 ` Przemyslaw Marczak
2014-03-14 16:06 ` [U-Boot] [PATCH v3 1/3] part_efi: move uuid<->string conversion functions into lib/uuid.c Wolfgang Denk
2014-03-17 9:15 ` Przemyslaw Marczak
2014-03-19 17:58 ` [U-Boot] [PATCH v4 1/6] " Przemyslaw Marczak
2014-03-19 17:58 ` [U-Boot] [PATCH v4 2/6] lib: uuid: code refactor for proper maintain between uuid bin and string Przemyslaw Marczak
2014-03-19 19:20 ` Wolfgang Denk
2014-03-25 19:12 ` Stephen Warren
2014-03-26 12:00 ` Przemyslaw Marczak
2014-03-26 18:43 ` Stephen Warren
2014-03-19 17:58 ` [U-Boot] [PATCH v4 3/6] lib: uuid: add functions to generate UUID version 4 Przemyslaw Marczak
2014-03-25 19:28 ` Stephen Warren
2014-03-26 12:00 ` Przemyslaw Marczak
2014-03-26 18:47 ` Stephen Warren
2014-03-27 9:17 ` Przemyslaw Marczak
2014-03-19 17:58 ` [U-Boot] [PATCH v4 4/6] new commands: uuid and guid - generate random unique identifier Przemyslaw Marczak
2014-03-25 19:37 ` Stephen Warren
2014-03-26 12:01 ` Przemyslaw Marczak
2014-03-26 18:32 ` Stephen Warren
2014-03-27 9:17 ` Przemyslaw Marczak
2014-03-19 17:58 ` [U-Boot] [PATCH v4 5/6] cmd:gpt: randomly generate each partition uuid if undefined Przemyslaw Marczak
2014-03-25 19:51 ` Stephen Warren
2014-03-26 12:01 ` Przemyslaw Marczak
2014-03-26 18:36 ` Stephen Warren
2014-03-27 9:17 ` Przemyslaw Marczak
2014-03-19 17:58 ` [U-Boot] [PATCH v4 6/6] trats/trats2: enable CONFIG_RANDOM_UUID Przemyslaw Marczak
2014-03-25 19:51 ` Stephen Warren
2014-03-26 12:01 ` Przemyslaw Marczak
2014-03-19 19:19 ` [U-Boot] [PATCH v4 1/6] part_efi: move uuid<->string conversion functions into lib/uuid.c Wolfgang Denk
2014-03-20 8:42 ` Przemyslaw Marczak
2014-03-25 19:03 ` Stephen Warren
2014-04-01 14:30 ` [U-Boot] [PATCH v5 " Przemyslaw Marczak
2014-04-01 14:30 ` [U-Boot] [PATCH v5 2/6] lib: uuid: code refactor for proper maintain between uuid bin and string Przemyslaw Marczak
2014-04-01 14:30 ` [U-Boot] [PATCH v5 3/6] lib: uuid: add functions to generate UUID version 4 Przemyslaw Marczak
2014-04-01 14:30 ` [U-Boot] [PATCH v5 4/6] new commands: uuid and guid - generate random unique identifier Przemyslaw Marczak
2014-04-01 14:30 ` [U-Boot] [PATCH v5 5/6] cmd:gpt: randomly generate each partition uuid if undefined Przemyslaw Marczak
2014-04-01 14:30 ` [U-Boot] [PATCH v5 6/6] trats/trats2: enable CONFIG_RANDOM_UUID Przemyslaw Marczak
2014-04-02 1:28 ` Minkyu Kang
2014-04-02 8:20 ` [U-Boot] [PATCH v6 1/6] part_efi: move uuid<->string conversion functions into lib/uuid.c Przemyslaw Marczak
2014-04-02 8:20 ` [U-Boot] [PATCH v6 2/6] lib: uuid: code refactor for proper maintain between uuid bin and string Przemyslaw Marczak
2014-04-02 21:18 ` [U-Boot] [U-Boot, v6, " Tom Rini
2014-04-02 8:20 ` [U-Boot] [PATCH v6 3/6] lib: uuid: add functions to generate UUID version 4 Przemyslaw Marczak
2014-04-02 8:25 ` Przemyslaw Marczak
2014-04-02 21:18 ` [U-Boot] [U-Boot, v6, " Tom Rini
2014-04-02 8:20 ` [U-Boot] [PATCH v6 4/6] new commands: uuid and guid - generate random unique identifier Przemyslaw Marczak
2014-04-02 21:18 ` [U-Boot] [U-Boot, v6, " Tom Rini
2014-04-02 8:20 ` [U-Boot] [PATCH v6 5/6] cmd:gpt: randomly generate each partition uuid if undefined Przemyslaw Marczak
2014-04-02 21:19 ` [U-Boot] [U-Boot, v6, " Tom Rini
2014-04-02 8:20 ` [U-Boot] [PATCH v6 6/6] trats/trats2: enable CONFIG_RANDOM_UUID Przemyslaw Marczak
2014-04-02 21:19 ` [U-Boot] [U-Boot, v6, " Tom Rini
2014-04-02 21:18 ` [U-Boot] [U-Boot, v6, 1/6] part_efi: move uuid<->string conversion functions into lib/uuid.c Tom Rini
2014-04-03 7:10 ` Przemyslaw Marczak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5321F4AA.4000402@samsung.com \
--to=p.marczak@samsung.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox