* [PATCH] block: fix UUID string buffer length
@ 2011-10-05 9:52 Rabin Vincent
2011-10-05 14:41 ` Will Drewry
0 siblings, 1 reply; 6+ messages in thread
From: Rabin Vincent @ 2011-10-05 9:52 UTC (permalink / raw)
To: axboe; +Cc: linux-kernel, Rabin Vincent, Will Drewry
The UUID string buffer is several bytes shorter than what is actually
required, because the space for the hyphens hasn't been taken into
account. Fix it, while also making it a regular char[] rather than a
u8[] to make it clear what we're storing here.
Cc: Will Drewry <wad@chromium.org>
Signed-off-by: Rabin Vincent <rabin@rab.in>
---
block/genhd.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index 8dfa21e..fa955b5 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -736,7 +736,7 @@ void __init printk_all_partitions(void)
struct hd_struct *part;
char name_buf[BDEVNAME_SIZE];
char devt_buf[BDEVT_SIZE];
- u8 uuid[PARTITION_META_INFO_UUIDLTH * 2 + 1];
+ char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")];
/*
* Don't show empty devices or things that have been
@@ -755,7 +755,7 @@ void __init printk_all_partitions(void)
while ((part = disk_part_iter_next(&piter))) {
bool is_part0 = part == &disk->part0;
- uuid[0] = 0;
+ uuid[0] = '\0';
if (part->info)
part_unpack_uuid(part->info->uuid, uuid);
--
1.7.5.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] block: fix UUID string buffer length
2011-10-05 9:52 [PATCH] block: fix UUID string buffer length Rabin Vincent
@ 2011-10-05 14:41 ` Will Drewry
2011-10-05 16:48 ` [alternate PATCH] " Joe Perches
0 siblings, 1 reply; 6+ messages in thread
From: Will Drewry @ 2011-10-05 14:41 UTC (permalink / raw)
To: Rabin Vincent; +Cc: axboe, linux-kernel
On Wed, Oct 5, 2011 at 4:52 AM, Rabin Vincent <rabin@rab.in> wrote:
> The UUID string buffer is several bytes shorter than what is actually
> required, because the space for the hyphens hasn't been taken into
> account. Fix it, while also making it a regular char[] rather than a
> u8[] to make it clear what we're storing here.
>
> Cc: Will Drewry <wad@chromium.org>
> Signed-off-by: Rabin Vincent <rabin@rab.in>
You're absolutely right. It should match the sizeof used by sprintf's
calculation of the uuid string.
( http://lxr.linux.no/linux+v3.0.4/lib/vsprintf.c#L759 ). The type
change is also entirely appropriate (even given the prototype of
part_unpack_uuid).
Thanks!
Reviewed-by: Will Drewry <wad@chromium.org>
> ---
> block/genhd.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/block/genhd.c b/block/genhd.c
> index 8dfa21e..fa955b5 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -736,7 +736,7 @@ void __init printk_all_partitions(void)
> struct hd_struct *part;
> char name_buf[BDEVNAME_SIZE];
> char devt_buf[BDEVT_SIZE];
> - u8 uuid[PARTITION_META_INFO_UUIDLTH * 2 + 1];
> + char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")];
>
> /*
> * Don't show empty devices or things that have been
> @@ -755,7 +755,7 @@ void __init printk_all_partitions(void)
> while ((part = disk_part_iter_next(&piter))) {
> bool is_part0 = part == &disk->part0;
>
> - uuid[0] = 0;
> + uuid[0] = '\0';
> if (part->info)
> part_unpack_uuid(part->info->uuid, uuid);
>
> --
> 1.7.5.4
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread* [alternate PATCH] block: fix UUID string buffer length
2011-10-05 14:41 ` Will Drewry
@ 2011-10-05 16:48 ` Joe Perches
2011-10-05 18:11 ` Vivek Goyal
0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2011-10-05 16:48 UTC (permalink / raw)
To: Will Drewry; +Cc: Rabin Vincent, axboe, linux-kernel
The UUID string buffer is several bytes shorter than what is actually
required. Fix it and remove the used once inline part_unpack_uuid,
use snprintf and printf extension %pU directly.
Based-on-a-patch-by: Rabin Vincent <rabin@rab.in>
cc: Will Drewry <wad@chromium.org>
Signed-off-by: Joe Perches <joe@perches.com>
---
block/genhd.c | 8 +++++---
include/linux/genhd.h | 6 ------
2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index e2f6790..427c955 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -735,7 +735,7 @@ void __init printk_all_partitions(void)
struct hd_struct *part;
char name_buf[BDEVNAME_SIZE];
char devt_buf[BDEVT_SIZE];
- u8 uuid[PARTITION_META_INFO_UUIDLTH * 2 + 1];
+ char uuid[sizeof("12345678-1234-1234-1234-123456789012")];
/*
* Don't show empty devices or things that have been
@@ -754,9 +754,11 @@ void __init printk_all_partitions(void)
while ((part = disk_part_iter_next(&piter))) {
bool is_part0 = part == &disk->part0;
- uuid[0] = 0;
if (part->info)
- part_unpack_uuid(part->info->uuid, uuid);
+ snprintf(uuid, sizeof(uuid),
+ "%pU", part->info->uuid);
+ else
+ uuid[0] = '\0';
printk("%s%s %10llu %s %s", is_part0 ? "" : " ",
bdevt_str(part_devt(part), devt_buf),
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 02fa469..28bd275 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -221,12 +221,6 @@ static inline void part_pack_uuid(const u8 *uuid_str, u8 *to)
}
}
-static inline char *part_unpack_uuid(const u8 *uuid, char *out)
-{
- sprintf(out, "%pU", uuid);
- return out;
-}
-
static inline int disk_max_parts(struct gendisk *disk)
{
if (disk->flags & GENHD_FL_EXT_DEVT)
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [alternate PATCH] block: fix UUID string buffer length
2011-10-05 16:48 ` [alternate PATCH] " Joe Perches
@ 2011-10-05 18:11 ` Vivek Goyal
2011-10-05 18:18 ` Joe Perches
0 siblings, 1 reply; 6+ messages in thread
From: Vivek Goyal @ 2011-10-05 18:11 UTC (permalink / raw)
To: Joe Perches; +Cc: Will Drewry, Rabin Vincent, axboe, linux-kernel
On Wed, Oct 05, 2011 at 09:48:30AM -0700, Joe Perches wrote:
> The UUID string buffer is several bytes shorter than what is actually
> required. Fix it and remove the used once inline part_unpack_uuid,
> use snprintf and printf extension %pU directly.
>
> Based-on-a-patch-by: Rabin Vincent <rabin@rab.in>
> cc: Will Drewry <wad@chromium.org>
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
> block/genhd.c | 8 +++++---
> include/linux/genhd.h | 6 ------
> 2 files changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/block/genhd.c b/block/genhd.c
> index e2f6790..427c955 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -735,7 +735,7 @@ void __init printk_all_partitions(void)
> struct hd_struct *part;
> char name_buf[BDEVNAME_SIZE];
> char devt_buf[BDEVT_SIZE];
> - u8 uuid[PARTITION_META_INFO_UUIDLTH * 2 + 1];
> + char uuid[sizeof("12345678-1234-1234-1234-123456789012")];
will following look better.
char uuid [PARTITION_META_INFO_UUIDLTH * 2 + 5]
4 bytes for hyphen and 1 for NULL.
Thanks
Vivek
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [alternate PATCH] block: fix UUID string buffer length
2011-10-05 18:11 ` Vivek Goyal
@ 2011-10-05 18:18 ` Joe Perches
2011-10-05 18:24 ` Vivek Goyal
0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2011-10-05 18:18 UTC (permalink / raw)
To: Vivek Goyal, Huang Ying; +Cc: Will Drewry, Rabin Vincent, axboe, linux-kernel
On Wed, 2011-10-05 at 14:11 -0400, Vivek Goyal wrote:
> On Wed, Oct 05, 2011 at 09:48:30AM -0700, Joe Perches wrote:
> > The UUID string buffer is several bytes shorter than what is actually
> > required. Fix it and remove the used once inline part_unpack_uuid,
> > use snprintf and printf extension %pU directly.
> >
> > Based-on-a-patch-by: Rabin Vincent <rabin@rab.in>
> > cc: Will Drewry <wad@chromium.org>
> > Signed-off-by: Joe Perches <joe@perches.com>
> > ---
> > block/genhd.c | 8 +++++---
> > include/linux/genhd.h | 6 ------
> > 2 files changed, 5 insertions(+), 9 deletions(-)
> >
> > diff --git a/block/genhd.c b/block/genhd.c
> > index e2f6790..427c955 100644
> > --- a/block/genhd.c
> > +++ b/block/genhd.c
> > @@ -735,7 +735,7 @@ void __init printk_all_partitions(void)
> > struct hd_struct *part;
> > char name_buf[BDEVNAME_SIZE];
> > char devt_buf[BDEVT_SIZE];
> > - u8 uuid[PARTITION_META_INFO_UUIDLTH * 2 + 1];
> > + char uuid[sizeof("12345678-1234-1234-1234-123456789012")];
>
> will following look better.
>
> char uuid [PARTITION_META_INFO_UUIDLTH * 2 + 5]
>
> 4 bytes for hyphen and 1 for NULL.
Perhaps include/linux/uuid.h could be extended to provide
some #defines for the various UUID lengths.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [alternate PATCH] block: fix UUID string buffer length
2011-10-05 18:18 ` Joe Perches
@ 2011-10-05 18:24 ` Vivek Goyal
0 siblings, 0 replies; 6+ messages in thread
From: Vivek Goyal @ 2011-10-05 18:24 UTC (permalink / raw)
To: Joe Perches; +Cc: Huang Ying, Will Drewry, Rabin Vincent, axboe, linux-kernel
On Wed, Oct 05, 2011 at 11:18:15AM -0700, Joe Perches wrote:
> On Wed, 2011-10-05 at 14:11 -0400, Vivek Goyal wrote:
> > On Wed, Oct 05, 2011 at 09:48:30AM -0700, Joe Perches wrote:
> > > The UUID string buffer is several bytes shorter than what is actually
> > > required. Fix it and remove the used once inline part_unpack_uuid,
> > > use snprintf and printf extension %pU directly.
> > >
> > > Based-on-a-patch-by: Rabin Vincent <rabin@rab.in>
> > > cc: Will Drewry <wad@chromium.org>
> > > Signed-off-by: Joe Perches <joe@perches.com>
> > > ---
> > > block/genhd.c | 8 +++++---
> > > include/linux/genhd.h | 6 ------
> > > 2 files changed, 5 insertions(+), 9 deletions(-)
> > >
> > > diff --git a/block/genhd.c b/block/genhd.c
> > > index e2f6790..427c955 100644
> > > --- a/block/genhd.c
> > > +++ b/block/genhd.c
> > > @@ -735,7 +735,7 @@ void __init printk_all_partitions(void)
> > > struct hd_struct *part;
> > > char name_buf[BDEVNAME_SIZE];
> > > char devt_buf[BDEVT_SIZE];
> > > - u8 uuid[PARTITION_META_INFO_UUIDLTH * 2 + 1];
> > > + char uuid[sizeof("12345678-1234-1234-1234-123456789012")];
> >
> > will following look better.
> >
> > char uuid [PARTITION_META_INFO_UUIDLTH * 2 + 5]
> >
> > 4 bytes for hyphen and 1 for NULL.
>
> Perhaps include/linux/uuid.h could be extended to provide
> some #defines for the various UUID lengths.
That would be best. So that everybody uses a common define.
Thanks
Vivek
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-10-05 18:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-05 9:52 [PATCH] block: fix UUID string buffer length Rabin Vincent
2011-10-05 14:41 ` Will Drewry
2011-10-05 16:48 ` [alternate PATCH] " Joe Perches
2011-10-05 18:11 ` Vivek Goyal
2011-10-05 18:18 ` Joe Perches
2011-10-05 18:24 ` Vivek Goyal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox