* [PATCH v3 01/10] lib/vsprintf: simplify UUID printing
2016-04-05 13:56 [PATCH v3 00/10] uuid: convert users to generic UUID API Andy Shevchenko
@ 2016-04-05 13:56 ` Andy Shevchenko
[not found] ` <1459864579-55988-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (3 subsequent siblings)
4 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 13:56 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA, Andrew Morton, Rasmus Villemoes,
linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
Cc: Andy Shevchenko
Since we have hex_byte_pack_upper() we may use it directly and avoid second
loop.
Signed-off-by: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
lib/vsprintf.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index ccb664b..be0e7cf 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1324,7 +1324,10 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
}
for (i = 0; i < 16; i++) {
- p = hex_byte_pack(p, addr[index[i]]);
+ if (uc)
+ p = hex_byte_pack_upper(p, addr[index[i]]);
+ else
+ p = hex_byte_pack(p, addr[index[i]]);
switch (i) {
case 3:
case 5:
@@ -1337,13 +1340,6 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
*p = 0;
- if (uc) {
- p = uuid;
- do {
- *p = toupper(*p);
- } while (*(++p));
- }
-
return string(buf, end, uuid, spec);
}
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v3 01/10] lib/vsprintf: simplify UUID printing
@ 2016-04-05 13:56 ` Andy Shevchenko
0 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 13:56 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel, linux-api,
Andrew Morton, Rasmus Villemoes, linux-efi, Matt Fleming,
Arnd Bergmann, Theodore Ts'o
Cc: Andy Shevchenko
Since we have hex_byte_pack_upper() we may use it directly and avoid second
loop.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib/vsprintf.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index ccb664b..be0e7cf 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1324,7 +1324,10 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
}
for (i = 0; i < 16; i++) {
- p = hex_byte_pack(p, addr[index[i]]);
+ if (uc)
+ p = hex_byte_pack_upper(p, addr[index[i]]);
+ else
+ p = hex_byte_pack(p, addr[index[i]]);
switch (i) {
case 3:
case 5:
@@ -1337,13 +1340,6 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
*p = 0;
- if (uc) {
- p = uuid;
- do {
- *p = toupper(*p);
- } while (*(++p));
- }
-
return string(buf, end, uuid, spec);
}
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v3 02/10] ima: use %pU to output UUID in printable format
2016-04-05 13:56 [PATCH v3 00/10] uuid: convert users to generic UUID API Andy Shevchenko
@ 2016-04-05 13:56 ` Andy Shevchenko
[not found] ` <1459864579-55988-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (3 subsequent siblings)
4 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 13:56 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA, Andrew Morton, Rasmus Villemoes,
linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
Cc: Andy Shevchenko
Instead of open coded variant re-use extension what vsprintf.c provides us for
ages.
Signed-off-by: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
security/integrity/ima/ima_policy.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index be09e2c..4b0c262 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -972,7 +972,7 @@ static void policy_func_show(struct seq_file *m, enum ima_hooks func)
int ima_policy_show(struct seq_file *m, void *v)
{
struct ima_rule_entry *entry = v;
- int i = 0;
+ int i;
char tbuf[64] = {0,};
rcu_read_lock();
@@ -1012,17 +1012,7 @@ int ima_policy_show(struct seq_file *m, void *v)
}
if (entry->flags & IMA_FSUUID) {
- seq_puts(m, "fsuuid=");
- for (i = 0; i < ARRAY_SIZE(entry->fsuuid); ++i) {
- switch (i) {
- case 4:
- case 6:
- case 8:
- case 10:
- seq_puts(m, "-");
- }
- seq_printf(m, "%x", entry->fsuuid[i]);
- }
+ seq_printf(m, "fsuuid=%pU", entry->fsuuid);
seq_puts(m, " ");
}
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v3 02/10] ima: use %pU to output UUID in printable format
@ 2016-04-05 13:56 ` Andy Shevchenko
0 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 13:56 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel, linux-api,
Andrew Morton, Rasmus Villemoes, linux-efi, Matt Fleming,
Arnd Bergmann, Theodore Ts'o
Cc: Andy Shevchenko
Instead of open coded variant re-use extension what vsprintf.c provides us for
ages.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
security/integrity/ima/ima_policy.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index be09e2c..4b0c262 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -972,7 +972,7 @@ static void policy_func_show(struct seq_file *m, enum ima_hooks func)
int ima_policy_show(struct seq_file *m, void *v)
{
struct ima_rule_entry *entry = v;
- int i = 0;
+ int i;
char tbuf[64] = {0,};
rcu_read_lock();
@@ -1012,17 +1012,7 @@ int ima_policy_show(struct seq_file *m, void *v)
}
if (entry->flags & IMA_FSUUID) {
- seq_puts(m, "fsuuid=");
- for (i = 0; i < ARRAY_SIZE(entry->fsuuid); ++i) {
- switch (i) {
- case 4:
- case 6:
- case 8:
- case 10:
- seq_puts(m, "-");
- }
- seq_printf(m, "%x", entry->fsuuid[i]);
- }
+ seq_printf(m, "fsuuid=%pU", entry->fsuuid);
seq_puts(m, " ");
}
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 27+ messages in thread[parent not found: <1459864579-55988-3-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>]
* Re: [PATCH v3 02/10] ima: use %pU to output UUID in printable format
2016-04-05 13:56 ` Andy Shevchenko
@ 2016-04-05 23:16 ` Joe Perches
-1 siblings, 0 replies; 27+ messages in thread
From: Joe Perches @ 2016-04-05 23:16 UTC (permalink / raw)
To: Andy Shevchenko, Dmitry Kasatkin, Mimi Zohar,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA, Andrew Morton, Rasmus Villemoes,
linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
On Tue, 2016-04-05 at 16:56 +0300, Andy Shevchenko wrote:
> Instead of open coded variant re-use extension what vsprintf.c provides us for
> ages.
trivia:
> diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
[]
> @@ -1012,17 +1012,7 @@ int ima_policy_show(struct seq_file *m, void *v)
> }
>
> if (entry->flags & IMA_FSUUID) {
> - seq_puts(m, "fsuuid=");
> - for (i = 0; i < ARRAY_SIZE(entry->fsuuid); ++i) {
> - switch (i) {
> - case 4:
> - case 6:
> - case 8:
> - case 10:
> - seq_puts(m, "-");
> - }
> - seq_printf(m, "%x", entry->fsuuid[i]);
> - }
> + seq_printf(m, "fsuuid=%pU", entry->fsuuid);
> seq_puts(m, " ");
> }
Maybe combine the printf and puts
seq_printf(m, "fsuuid=%pU ", entry->fsuuid);
^ permalink raw reply [flat|nested] 27+ messages in thread* Re: [PATCH v3 02/10] ima: use %pU to output UUID in printable format
@ 2016-04-05 23:16 ` Joe Perches
0 siblings, 0 replies; 27+ messages in thread
From: Joe Perches @ 2016-04-05 23:16 UTC (permalink / raw)
To: Andy Shevchenko, Dmitry Kasatkin, Mimi Zohar, linux-kernel,
linux-api, Andrew Morton, Rasmus Villemoes, linux-efi,
Matt Fleming, Arnd Bergmann, Theodore Ts'o
On Tue, 2016-04-05 at 16:56 +0300, Andy Shevchenko wrote:
> Instead of open coded variant re-use extension what vsprintf.c provides us for
> ages.
trivia:
> diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
[]
> @@ -1012,17 +1012,7 @@ int ima_policy_show(struct seq_file *m, void *v)
> }
>
> if (entry->flags & IMA_FSUUID) {
> - seq_puts(m, "fsuuid=");
> - for (i = 0; i < ARRAY_SIZE(entry->fsuuid); ++i) {
> - switch (i) {
> - case 4:
> - case 6:
> - case 8:
> - case 10:
> - seq_puts(m, "-");
> - }
> - seq_printf(m, "%x", entry->fsuuid[i]);
> - }
> + seq_printf(m, "fsuuid=%pU", entry->fsuuid);
> seq_puts(m, " ");
> }
Maybe combine the printf and puts
seq_printf(m, "fsuuid=%pU ", entry->fsuuid);
^ permalink raw reply [flat|nested] 27+ messages in thread[parent not found: <1459898182.6715.22.camel-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>]
* Re: [PATCH v3 02/10] ima: use %pU to output UUID in printable format
2016-04-05 23:16 ` Joe Perches
@ 2016-04-06 11:02 ` Andy Shevchenko
-1 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-06 11:02 UTC (permalink / raw)
To: Joe Perches, Dmitry Kasatkin, Mimi Zohar,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA, Andrew Morton, Rasmus Villemoes,
linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
On Tue, 2016-04-05 at 16:16 -0700, Joe Perches wrote:
> On Tue, 2016-04-05 at 16:56 +0300, Andy Shevchenko wrote:
> >
> > Instead of open coded variant re-use extension what vsprintf.c
> > provides us for
> > ages.
> trivia:
>
> >
> > diff --git a/security/integrity/ima/ima_policy.c
> > b/security/integrity/ima/ima_policy.c
> []
> >
> > @@ -1012,17 +1012,7 @@ int ima_policy_show(struct seq_file *m, void
> > *v)
> > }
> >
> > if (entry->flags & IMA_FSUUID) {
> > - seq_puts(m, "fsuuid=");
> > - for (i = 0; i < ARRAY_SIZE(entry->fsuuid); ++i) {
> > - switch (i) {
> > - case 4:
> > - case 6:
> > - case 8:
> > - case 10:
> > - seq_puts(m, "-");
> > - }
> > - seq_printf(m, "%x", entry->fsuuid[i]);
> > - }
> > + seq_printf(m, "fsuuid=%pU", entry->fsuuid);
> > seq_puts(m, " ");
> > }
> Maybe combine the printf and puts
>
> seq_printf(m, "fsuuid=%pU ", entry->fsuuid);
I would prefer my style to keep in order with the rest of the code in
that file.
--
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Intel Finland Oy
^ permalink raw reply [flat|nested] 27+ messages in thread* Re: [PATCH v3 02/10] ima: use %pU to output UUID in printable format
@ 2016-04-06 11:02 ` Andy Shevchenko
0 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-06 11:02 UTC (permalink / raw)
To: Joe Perches, Dmitry Kasatkin, Mimi Zohar, linux-kernel, linux-api,
Andrew Morton, Rasmus Villemoes, linux-efi, Matt Fleming,
Arnd Bergmann, Theodore Ts'o
On Tue, 2016-04-05 at 16:16 -0700, Joe Perches wrote:
> On Tue, 2016-04-05 at 16:56 +0300, Andy Shevchenko wrote:
> >
> > Instead of open coded variant re-use extension what vsprintf.c
> > provides us for
> > ages.
> trivia:
>
> >
> > diff --git a/security/integrity/ima/ima_policy.c
> > b/security/integrity/ima/ima_policy.c
> []
> >
> > @@ -1012,17 +1012,7 @@ int ima_policy_show(struct seq_file *m, void
> > *v)
> > }
> >
> > if (entry->flags & IMA_FSUUID) {
> > - seq_puts(m, "fsuuid=");
> > - for (i = 0; i < ARRAY_SIZE(entry->fsuuid); ++i) {
> > - switch (i) {
> > - case 4:
> > - case 6:
> > - case 8:
> > - case 10:
> > - seq_puts(m, "-");
> > - }
> > - seq_printf(m, "%x", entry->fsuuid[i]);
> > - }
> > + seq_printf(m, "fsuuid=%pU", entry->fsuuid);
> > seq_puts(m, " ");
> > }
> Maybe combine the printf and puts
>
> seq_printf(m, "fsuuid=%pU ", entry->fsuuid);
I would prefer my style to keep in order with the rest of the code in
that file.
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v3 04/10] lib/uuid: introduce few more generic helpers for UUID
2016-04-05 13:56 [PATCH v3 00/10] uuid: convert users to generic UUID API Andy Shevchenko
@ 2016-04-05 13:56 ` Andy Shevchenko
[not found] ` <1459864579-55988-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (3 subsequent siblings)
4 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 13:56 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA, Andrew Morton, Rasmus Villemoes,
linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
Cc: Andy Shevchenko
There are new helpers in this patch:
uuid_is_valid checks if a UUID is valid
uuid_be_to_bin converts from string to binary (big endian)
uuid_le_to_bin converts from string to binary (little endian)
They will be used in future, i.e. in the following patches in the series.
This also moves indices arrays to lib/uuid.c to be shared accross modules.
Signed-off-by: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
include/linux/uuid.h | 13 +++++++++++
lib/uuid.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/vsprintf.c | 9 ++++----
3 files changed, 82 insertions(+), 5 deletions(-)
diff --git a/include/linux/uuid.h b/include/linux/uuid.h
index 91c2b6d..e0b95e7 100644
--- a/include/linux/uuid.h
+++ b/include/linux/uuid.h
@@ -22,6 +22,11 @@
#include <uapi/linux/uuid.h>
+/*
+ * The length of a UUID string ("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
+ * not including trailing NUL.
+ */
+#define UUID_STRING_LEN 36
static inline int uuid_le_cmp(const uuid_le u1, const uuid_le u2)
{
@@ -38,4 +43,12 @@ void generate_random_uuid(unsigned char uuid[16]);
extern void uuid_le_gen(uuid_le *u);
extern void uuid_be_gen(uuid_be *u);
+bool __must_check uuid_is_valid(const char *uuid);
+
+extern const u8 uuid_le_index[16];
+extern const u8 uuid_be_index[16];
+
+int uuid_le_to_bin(const char *uuid, uuid_le *u);
+int uuid_be_to_bin(const char *uuid, uuid_be *u);
+
#endif
diff --git a/lib/uuid.c b/lib/uuid.c
index 6c81c0b..11f467e 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -19,10 +19,17 @@
*/
#include <linux/kernel.h>
+#include <linux/ctype.h>
+#include <linux/errno.h>
#include <linux/export.h>
#include <linux/uuid.h>
#include <linux/random.h>
+const u8 uuid_le_index[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15};
+EXPORT_SYMBOL(uuid_le_index);
+const u8 uuid_be_index[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
+EXPORT_SYMBOL(uuid_be_index);
+
/***************************************************************
* Random UUID interface
*
@@ -65,3 +72,61 @@ void uuid_be_gen(uuid_be *bu)
bu->b[6] = (bu->b[6] & 0x0F) | 0x40;
}
EXPORT_SYMBOL_GPL(uuid_be_gen);
+
+/**
+ * uuid_is_valid - checks if UUID string valid
+ * @uuid: UUID string to check
+ *
+ * Description:
+ * It checks if the UUID string is following the format:
+ * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+ * where x is a hex digit.
+ *
+ * Return: true if input is valid UUID string.
+ */
+bool uuid_is_valid(const char *uuid)
+{
+ unsigned int i;
+
+ for (i = 0; i < UUID_STRING_LEN; i++) {
+ if (i == 8 || i == 13 || i == 18 || i == 23) {
+ if (uuid[i] != '-')
+ return false;
+ } else if (!isxdigit(uuid[i])) {
+ return false;
+ }
+ }
+
+ return true;
+}
+EXPORT_SYMBOL(uuid_is_valid);
+
+static int __uuid_to_bin(const char *uuid, __u8 b[16], const u8 ei[16])
+{
+ static const u8 si[16] = {0,2,4,6,9,11,14,16,19,21,24,26,28,30,32,34};
+ unsigned int i;
+
+ if (uuid_is_valid(uuid))
+ return -EINVAL;
+
+ for (i = 0; i < 16; i++) {
+ int hi = hex_to_bin(uuid[si[i]] + 0);
+ int lo = hex_to_bin(uuid[si[i]] + 1);
+
+ b[ei[i]] = (hi << 4) | lo;
+ }
+
+ return 0;
+}
+
+int uuid_le_to_bin(const char *uuid, uuid_le *u)
+{
+ return __uuid_to_bin(uuid, u->b, uuid_le_index);
+}
+EXPORT_SYMBOL(uuid_le_to_bin);
+
+int uuid_be_to_bin(const char *uuid, uuid_be *u)
+{
+ return __uuid_to_bin(uuid, u->b, uuid_be_index);
+}
+EXPORT_SYMBOL(uuid_be_to_bin);
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index be0e7cf..0967771 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -30,6 +30,7 @@
#include <linux/ioport.h>
#include <linux/dcache.h>
#include <linux/cred.h>
+#include <linux/uuid.h>
#include <net/addrconf.h>
#ifdef CONFIG_BLOCK
#include <linux/blkdev.h>
@@ -1304,19 +1305,17 @@ static noinline_for_stack
char *uuid_string(char *buf, char *end, const u8 *addr,
struct printf_spec spec, const char *fmt)
{
- char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")];
+ char uuid[UUID_STRING_LEN + 1];
char *p = uuid;
int i;
- static const u8 be[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
- static const u8 le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15};
- const u8 *index = be;
+ const u8 *index = uuid_be_index;
bool uc = false;
switch (*(++fmt)) {
case 'L':
uc = true; /* fall-through */
case 'l':
- index = le;
+ index = uuid_le_index;
break;
case 'B':
uc = true;
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v3 04/10] lib/uuid: introduce few more generic helpers for UUID
@ 2016-04-05 13:56 ` Andy Shevchenko
0 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 13:56 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel, linux-api,
Andrew Morton, Rasmus Villemoes, linux-efi, Matt Fleming,
Arnd Bergmann, Theodore Ts'o
Cc: Andy Shevchenko
There are new helpers in this patch:
uuid_is_valid checks if a UUID is valid
uuid_be_to_bin converts from string to binary (big endian)
uuid_le_to_bin converts from string to binary (little endian)
They will be used in future, i.e. in the following patches in the series.
This also moves indices arrays to lib/uuid.c to be shared accross modules.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/uuid.h | 13 +++++++++++
lib/uuid.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/vsprintf.c | 9 ++++----
3 files changed, 82 insertions(+), 5 deletions(-)
diff --git a/include/linux/uuid.h b/include/linux/uuid.h
index 91c2b6d..e0b95e7 100644
--- a/include/linux/uuid.h
+++ b/include/linux/uuid.h
@@ -22,6 +22,11 @@
#include <uapi/linux/uuid.h>
+/*
+ * The length of a UUID string ("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
+ * not including trailing NUL.
+ */
+#define UUID_STRING_LEN 36
static inline int uuid_le_cmp(const uuid_le u1, const uuid_le u2)
{
@@ -38,4 +43,12 @@ void generate_random_uuid(unsigned char uuid[16]);
extern void uuid_le_gen(uuid_le *u);
extern void uuid_be_gen(uuid_be *u);
+bool __must_check uuid_is_valid(const char *uuid);
+
+extern const u8 uuid_le_index[16];
+extern const u8 uuid_be_index[16];
+
+int uuid_le_to_bin(const char *uuid, uuid_le *u);
+int uuid_be_to_bin(const char *uuid, uuid_be *u);
+
#endif
diff --git a/lib/uuid.c b/lib/uuid.c
index 6c81c0b..11f467e 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -19,10 +19,17 @@
*/
#include <linux/kernel.h>
+#include <linux/ctype.h>
+#include <linux/errno.h>
#include <linux/export.h>
#include <linux/uuid.h>
#include <linux/random.h>
+const u8 uuid_le_index[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15};
+EXPORT_SYMBOL(uuid_le_index);
+const u8 uuid_be_index[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
+EXPORT_SYMBOL(uuid_be_index);
+
/***************************************************************
* Random UUID interface
*
@@ -65,3 +72,61 @@ void uuid_be_gen(uuid_be *bu)
bu->b[6] = (bu->b[6] & 0x0F) | 0x40;
}
EXPORT_SYMBOL_GPL(uuid_be_gen);
+
+/**
+ * uuid_is_valid - checks if UUID string valid
+ * @uuid: UUID string to check
+ *
+ * Description:
+ * It checks if the UUID string is following the format:
+ * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+ * where x is a hex digit.
+ *
+ * Return: true if input is valid UUID string.
+ */
+bool uuid_is_valid(const char *uuid)
+{
+ unsigned int i;
+
+ for (i = 0; i < UUID_STRING_LEN; i++) {
+ if (i == 8 || i == 13 || i == 18 || i == 23) {
+ if (uuid[i] != '-')
+ return false;
+ } else if (!isxdigit(uuid[i])) {
+ return false;
+ }
+ }
+
+ return true;
+}
+EXPORT_SYMBOL(uuid_is_valid);
+
+static int __uuid_to_bin(const char *uuid, __u8 b[16], const u8 ei[16])
+{
+ static const u8 si[16] = {0,2,4,6,9,11,14,16,19,21,24,26,28,30,32,34};
+ unsigned int i;
+
+ if (uuid_is_valid(uuid))
+ return -EINVAL;
+
+ for (i = 0; i < 16; i++) {
+ int hi = hex_to_bin(uuid[si[i]] + 0);
+ int lo = hex_to_bin(uuid[si[i]] + 1);
+
+ b[ei[i]] = (hi << 4) | lo;
+ }
+
+ return 0;
+}
+
+int uuid_le_to_bin(const char *uuid, uuid_le *u)
+{
+ return __uuid_to_bin(uuid, u->b, uuid_le_index);
+}
+EXPORT_SYMBOL(uuid_le_to_bin);
+
+int uuid_be_to_bin(const char *uuid, uuid_be *u)
+{
+ return __uuid_to_bin(uuid, u->b, uuid_be_index);
+}
+EXPORT_SYMBOL(uuid_be_to_bin);
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index be0e7cf..0967771 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -30,6 +30,7 @@
#include <linux/ioport.h>
#include <linux/dcache.h>
#include <linux/cred.h>
+#include <linux/uuid.h>
#include <net/addrconf.h>
#ifdef CONFIG_BLOCK
#include <linux/blkdev.h>
@@ -1304,19 +1305,17 @@ static noinline_for_stack
char *uuid_string(char *buf, char *end, const u8 *addr,
struct printf_spec spec, const char *fmt)
{
- char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")];
+ char uuid[UUID_STRING_LEN + 1];
char *p = uuid;
int i;
- static const u8 be[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
- static const u8 le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15};
- const u8 *index = be;
+ const u8 *index = uuid_be_index;
bool uc = false;
switch (*(++fmt)) {
case 'L':
uc = true; /* fall-through */
case 'l':
- index = le;
+ index = uuid_le_index;
break;
case 'B':
uc = true;
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 27+ messages in thread[parent not found: <1459864579-55988-5-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>]
* Re: [PATCH v3 04/10] lib/uuid: introduce few more generic helpers for UUID
2016-04-05 13:56 ` Andy Shevchenko
@ 2016-04-05 14:15 ` Andy Shevchenko
-1 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 14:15 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA, Andrew Morton, Rasmus Villemoes,
linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
On Tue, 2016-04-05 at 16:56 +0300, Andy Shevchenko wrote:
> There are new helpers in this patch:
>
> uuid_is_valid checks if a UUID is valid
> uuid_be_to_bin converts from string to binary (big
> endian)
> uuid_le_to_bin converts from string to binary (little
> endian)
>
> They will be used in future, i.e. in the following patches in the
> series.
>
> This also moves indices arrays to lib/uuid.c to be shared accross
> modules.
>
> --- a/lib/uuid.c
> +++ b/lib/uuid.c
> +static int __uuid_to_bin(const char *uuid, __u8 b[16], const u8
> ei[16])
> +{
> + static const u8 si[16] =
> {0,2,4,6,9,11,14,16,19,21,24,26,28,30,32,34};
> + unsigned int i;
> +
> + if (uuid_is_valid(uuid))
Oops, sorry, typo is here, should be negative check.
if (!uuid_is_valid(uuid))
> + return -EINVAL;
> +
> + for (i = 0; i < 16; i++) {
> + int hi = hex_to_bin(uuid[si[i]] + 0);
> + int lo = hex_to_bin(uuid[si[i]] + 1);
> +
> + b[ei[i]] = (hi << 4) | lo;
> + }
> +
> + return 0;
> +}
--
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Intel Finland Oy
^ permalink raw reply [flat|nested] 27+ messages in thread* Re: [PATCH v3 04/10] lib/uuid: introduce few more generic helpers for UUID
@ 2016-04-05 14:15 ` Andy Shevchenko
0 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 14:15 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel, linux-api,
Andrew Morton, Rasmus Villemoes, linux-efi, Matt Fleming,
Arnd Bergmann, Theodore Ts'o
On Tue, 2016-04-05 at 16:56 +0300, Andy Shevchenko wrote:
> There are new helpers in this patch:
>
> uuid_is_valid checks if a UUID is valid
> uuid_be_to_bin converts from string to binary (big
> endian)
> uuid_le_to_bin converts from string to binary (little
> endian)
>
> They will be used in future, i.e. in the following patches in the
> series.
>
> This also moves indices arrays to lib/uuid.c to be shared accross
> modules.
>
> --- a/lib/uuid.c
> +++ b/lib/uuid.c
> +static int __uuid_to_bin(const char *uuid, __u8 b[16], const u8
> ei[16])
> +{
> + static const u8 si[16] =
> {0,2,4,6,9,11,14,16,19,21,24,26,28,30,32,34};
> + unsigned int i;
> +
> + if (uuid_is_valid(uuid))
Oops, sorry, typo is here, should be negative check.
if (!uuid_is_valid(uuid))
> + return -EINVAL;
> +
> + for (i = 0; i < 16; i++) {
> + int hi = hex_to_bin(uuid[si[i]] + 0);
> + int lo = hex_to_bin(uuid[si[i]] + 1);
> +
> + b[ei[i]] = (hi << 4) | lo;
> + }
> +
> + return 0;
> +}
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v3 05/10] lib/uuid: remove FSF address
2016-04-05 13:56 [PATCH v3 00/10] uuid: convert users to generic UUID API Andy Shevchenko
@ 2016-04-05 13:56 ` Andy Shevchenko
[not found] ` <1459864579-55988-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (3 subsequent siblings)
4 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 13:56 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA, Andrew Morton, Rasmus Villemoes,
linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
Cc: Andy Shevchenko
There is no point to keep an address in the file since it's a subject to
change.
While here, update Intel Copyright years.
Signed-off-by: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
include/linux/uuid.h | 6 +-----
include/uapi/linux/uuid.h | 4 ----
lib/uuid.c | 6 +-----
3 files changed, 2 insertions(+), 14 deletions(-)
diff --git a/include/linux/uuid.h b/include/linux/uuid.h
index e0b95e7..2d095fc 100644
--- a/include/linux/uuid.h
+++ b/include/linux/uuid.h
@@ -1,7 +1,7 @@
/*
* UUID/GUID definition
*
- * Copyright (C) 2010, Intel Corp.
+ * Copyright (C) 2010, 2016 Intel Corp.
* Huang Ying <ying.huang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
*
* This program is free software; you can redistribute it and/or
@@ -12,10 +12,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LINUX_UUID_H_
#define _LINUX_UUID_H_
diff --git a/include/uapi/linux/uuid.h b/include/uapi/linux/uuid.h
index 786f077..3738e5f 100644
--- a/include/uapi/linux/uuid.h
+++ b/include/uapi/linux/uuid.h
@@ -12,10 +12,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _UAPI_LINUX_UUID_H_
diff --git a/lib/uuid.c b/lib/uuid.c
index 11f467e..7442d43 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -1,7 +1,7 @@
/*
* Unified UUID/GUID definition
*
- * Copyright (C) 2009, Intel Corp.
+ * Copyright (C) 2009, 2016 Intel Corp.
* Huang Ying <ying.huang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
*
* This program is free software; you can redistribute it and/or
@@ -12,10 +12,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/kernel.h>
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v3 05/10] lib/uuid: remove FSF address
@ 2016-04-05 13:56 ` Andy Shevchenko
0 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 13:56 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel, linux-api,
Andrew Morton, Rasmus Villemoes, linux-efi, Matt Fleming,
Arnd Bergmann, Theodore Ts'o
Cc: Andy Shevchenko
There is no point to keep an address in the file since it's a subject to
change.
While here, update Intel Copyright years.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/uuid.h | 6 +-----
include/uapi/linux/uuid.h | 4 ----
lib/uuid.c | 6 +-----
3 files changed, 2 insertions(+), 14 deletions(-)
diff --git a/include/linux/uuid.h b/include/linux/uuid.h
index e0b95e7..2d095fc 100644
--- a/include/linux/uuid.h
+++ b/include/linux/uuid.h
@@ -1,7 +1,7 @@
/*
* UUID/GUID definition
*
- * Copyright (C) 2010, Intel Corp.
+ * Copyright (C) 2010, 2016 Intel Corp.
* Huang Ying <ying.huang@intel.com>
*
* This program is free software; you can redistribute it and/or
@@ -12,10 +12,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LINUX_UUID_H_
#define _LINUX_UUID_H_
diff --git a/include/uapi/linux/uuid.h b/include/uapi/linux/uuid.h
index 786f077..3738e5f 100644
--- a/include/uapi/linux/uuid.h
+++ b/include/uapi/linux/uuid.h
@@ -12,10 +12,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _UAPI_LINUX_UUID_H_
diff --git a/lib/uuid.c b/lib/uuid.c
index 11f467e..7442d43 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -1,7 +1,7 @@
/*
* Unified UUID/GUID definition
*
- * Copyright (C) 2009, Intel Corp.
+ * Copyright (C) 2009, 2016 Intel Corp.
* Huang Ying <ying.huang@intel.com>
*
* This program is free software; you can redistribute it and/or
@@ -12,10 +12,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/kernel.h>
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v3 06/10] sysctl: drop away useless label
2016-04-05 13:56 [PATCH v3 00/10] uuid: convert users to generic UUID API Andy Shevchenko
@ 2016-04-05 13:56 ` Andy Shevchenko
[not found] ` <1459864579-55988-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (3 subsequent siblings)
4 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 13:56 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA, Andrew Morton, Rasmus Villemoes,
linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
Cc: Andy Shevchenko
We have no locking in bin_uuid(). Thus, we may remove the out label and use
return statements directly.
Signed-off-by: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
kernel/sysctl_binary.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
index 10a1d7d..055ad65 100644
--- a/kernel/sysctl_binary.c
+++ b/kernel/sysctl_binary.c
@@ -1123,15 +1123,14 @@ static ssize_t bin_uuid(struct file *file,
result = kernel_read(file, 0, buf, sizeof(buf) - 1);
if (result < 0)
- goto out;
+ return result;
buf[result] = '\0';
/* Convert the uuid to from a string to binary */
for (i = 0; i < 16; i++) {
- result = -EIO;
if (!isxdigit(str[0]) || !isxdigit(str[1]))
- goto out;
+ return -EIO;
uuid[i] = (hex_to_bin(str[0]) << 4) |
hex_to_bin(str[1]);
@@ -1143,15 +1142,12 @@ static ssize_t bin_uuid(struct file *file,
if (oldlen > 16)
oldlen = 16;
- result = -EFAULT;
if (copy_to_user(oldval, uuid, oldlen))
- goto out;
+ return -EFAULT;
copied = oldlen;
}
- result = copied;
-out:
- return result;
+ return copied;
}
static ssize_t bin_dn_node_address(struct file *file,
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v3 06/10] sysctl: drop away useless label
@ 2016-04-05 13:56 ` Andy Shevchenko
0 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 13:56 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel, linux-api,
Andrew Morton, Rasmus Villemoes, linux-efi, Matt Fleming,
Arnd Bergmann, Theodore Ts'o
Cc: Andy Shevchenko
We have no locking in bin_uuid(). Thus, we may remove the out label and use
return statements directly.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
kernel/sysctl_binary.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
index 10a1d7d..055ad65 100644
--- a/kernel/sysctl_binary.c
+++ b/kernel/sysctl_binary.c
@@ -1123,15 +1123,14 @@ static ssize_t bin_uuid(struct file *file,
result = kernel_read(file, 0, buf, sizeof(buf) - 1);
if (result < 0)
- goto out;
+ return result;
buf[result] = '\0';
/* Convert the uuid to from a string to binary */
for (i = 0; i < 16; i++) {
- result = -EIO;
if (!isxdigit(str[0]) || !isxdigit(str[1]))
- goto out;
+ return -EIO;
uuid[i] = (hex_to_bin(str[0]) << 4) |
hex_to_bin(str[1]);
@@ -1143,15 +1142,12 @@ static ssize_t bin_uuid(struct file *file,
if (oldlen > 16)
oldlen = 16;
- result = -EFAULT;
if (copy_to_user(oldval, uuid, oldlen))
- goto out;
+ return -EFAULT;
copied = oldlen;
}
- result = copied;
-out:
- return result;
+ return copied;
}
static ssize_t bin_dn_node_address(struct file *file,
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 27+ messages in thread[parent not found: <1459864579-55988-7-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>]
* Re: [PATCH v3 06/10] sysctl: drop away useless label
2016-04-05 13:56 ` Andy Shevchenko
@ 2016-04-05 22:17 ` Andrew Morton
-1 siblings, 0 replies; 27+ messages in thread
From: Andrew Morton @ 2016-04-05 22:17 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Dmitry Kasatkin, Mimi Zohar, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA, Rasmus Villemoes,
linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
On Tue, 5 Apr 2016 16:56:15 +0300 Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> wrote:
> We have no locking in bin_uuid(). Thus, we may remove the out label and use
> return statements directly.
>
> ...
>
> --- a/kernel/sysctl_binary.c
> +++ b/kernel/sysctl_binary.c
> @@ -1123,15 +1123,14 @@ static ssize_t bin_uuid(struct file *file,
>
> result = kernel_read(file, 0, buf, sizeof(buf) - 1);
> if (result < 0)
> - goto out;
> + return result;
>
> buf[result] = '\0';
>
> /* Convert the uuid to from a string to binary */
> for (i = 0; i < 16; i++) {
> - result = -EIO;
> if (!isxdigit(str[0]) || !isxdigit(str[1]))
> - goto out;
> + return -EIO;
>
> uuid[i] = (hex_to_bin(str[0]) << 4) |
> hex_to_bin(str[1]);
> @@ -1143,15 +1142,12 @@ static ssize_t bin_uuid(struct file *file,
> if (oldlen > 16)
> oldlen = 16;
>
> - result = -EFAULT;
> if (copy_to_user(oldval, uuid, oldlen))
> - goto out;
> + return -EFAULT;
>
> copied = oldlen;
> }
> - result = copied;
> -out:
> - return result;
> + return copied;
> }
Sure, but we may add locking or resource allocation in the future, in
which case this change will need to be undone. I think it's better to
leave the code as-is. It's presently quite typical kernel code.
^ permalink raw reply [flat|nested] 27+ messages in thread* Re: [PATCH v3 06/10] sysctl: drop away useless label
@ 2016-04-05 22:17 ` Andrew Morton
0 siblings, 0 replies; 27+ messages in thread
From: Andrew Morton @ 2016-04-05 22:17 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Dmitry Kasatkin, Mimi Zohar, linux-kernel, linux-api,
Rasmus Villemoes, linux-efi, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
On Tue, 5 Apr 2016 16:56:15 +0300 Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> We have no locking in bin_uuid(). Thus, we may remove the out label and use
> return statements directly.
>
> ...
>
> --- a/kernel/sysctl_binary.c
> +++ b/kernel/sysctl_binary.c
> @@ -1123,15 +1123,14 @@ static ssize_t bin_uuid(struct file *file,
>
> result = kernel_read(file, 0, buf, sizeof(buf) - 1);
> if (result < 0)
> - goto out;
> + return result;
>
> buf[result] = '\0';
>
> /* Convert the uuid to from a string to binary */
> for (i = 0; i < 16; i++) {
> - result = -EIO;
> if (!isxdigit(str[0]) || !isxdigit(str[1]))
> - goto out;
> + return -EIO;
>
> uuid[i] = (hex_to_bin(str[0]) << 4) |
> hex_to_bin(str[1]);
> @@ -1143,15 +1142,12 @@ static ssize_t bin_uuid(struct file *file,
> if (oldlen > 16)
> oldlen = 16;
>
> - result = -EFAULT;
> if (copy_to_user(oldval, uuid, oldlen))
> - goto out;
> + return -EFAULT;
>
> copied = oldlen;
> }
> - result = copied;
> -out:
> - return result;
> + return copied;
> }
Sure, but we may add locking or resource allocation in the future, in
which case this change will need to be undone. I think it's better to
leave the code as-is. It's presently quite typical kernel code.
^ permalink raw reply [flat|nested] 27+ messages in thread[parent not found: <20160405151752.de82f221f1c70ff901b2b958-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>]
* Re: [PATCH v3 06/10] sysctl: drop away useless label
2016-04-05 22:17 ` Andrew Morton
@ 2016-04-06 11:34 ` Andy Shevchenko
-1 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-06 11:34 UTC (permalink / raw)
To: Andrew Morton
Cc: Dmitry Kasatkin, Mimi Zohar, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA, Rasmus Villemoes,
linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
On Tue, 2016-04-05 at 15:17 -0700, Andrew Morton wrote:
> On Tue, 5 Apr 2016 16:56:15 +0300 Andy Shevchenko <andriy.shevchenko@
> linux.intel.com> wrote:
>
> >
> > We have no locking in bin_uuid(). Thus, we may remove the out label
> > and use
> > return statements directly.
> >
> Sure, but we may add locking or resource allocation in the future, in
> which case this change will need to be undone. I think it's better to
> leave the code as-is. It's presently quite typical kernel code.
I have noticed you updated the patch already. I'm fine with either.
--
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Intel Finland Oy
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v3 06/10] sysctl: drop away useless label
@ 2016-04-06 11:34 ` Andy Shevchenko
0 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-06 11:34 UTC (permalink / raw)
To: Andrew Morton
Cc: Dmitry Kasatkin, Mimi Zohar, linux-kernel, linux-api,
Rasmus Villemoes, linux-efi, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
On Tue, 2016-04-05 at 15:17 -0700, Andrew Morton wrote:
> On Tue, 5 Apr 2016 16:56:15 +0300 Andy Shevchenko <andriy.shevchenko@
> linux.intel.com> wrote:
>
> >
> > We have no locking in bin_uuid(). Thus, we may remove the out label
> > and use
> > return statements directly.
> >
> Sure, but we may add locking or resource allocation in the future, in
> which case this change will need to be undone. I think it's better to
> leave the code as-is. It's presently quite typical kernel code.
I have noticed you updated the patch already. I'm fine with either.
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v3 08/10] efi: redefine type, constant, macro from generic code
2016-04-05 13:56 [PATCH v3 00/10] uuid: convert users to generic UUID API Andy Shevchenko
@ 2016-04-05 13:56 ` Andy Shevchenko
[not found] ` <1459864579-55988-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (3 subsequent siblings)
4 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 13:56 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA, Andrew Morton, Rasmus Villemoes,
linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Arnd Bergmann,
Theodore Ts'o
Cc: Andy Shevchenko
Generic UUID library defines structure type, macro to define UUID, and the
length of the UUID string. This patch removes duplicate data structure
definition, UUID string length constant as well as macro for UUID handling.
Signed-off-by: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
include/linux/efi.h | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 1626474..5b1d5c5 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -21,6 +21,7 @@
#include <linux/pfn.h>
#include <linux/pstore.h>
#include <linux/reboot.h>
+#include <linux/uuid.h>
#include <asm/page.h>
@@ -43,17 +44,10 @@ typedef u16 efi_char16_t; /* UNICODE character */
typedef u64 efi_physical_addr_t;
typedef void *efi_handle_t;
-
-typedef struct {
- u8 b[16];
-} efi_guid_t;
+typedef uuid_le efi_guid_t;
#define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
-((efi_guid_t) \
-{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
- (b) & 0xff, ((b) >> 8) & 0xff, \
- (c) & 0xff, ((c) >> 8) & 0xff, \
- (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
+ UUID_LE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
/*
* Generic EFI table header
@@ -1050,7 +1044,7 @@ efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
* Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
* not including trailing NUL
*/
-#define EFI_VARIABLE_GUID_LEN 36
+#define EFI_VARIABLE_GUID_LEN UUID_STRING_LEN
/*
* The type of search to perform when calling boottime->locate_handle
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v3 08/10] efi: redefine type, constant, macro from generic code
@ 2016-04-05 13:56 ` Andy Shevchenko
0 siblings, 0 replies; 27+ messages in thread
From: Andy Shevchenko @ 2016-04-05 13:56 UTC (permalink / raw)
To: Dmitry Kasatkin, Mimi Zohar, linux-kernel, linux-api,
Andrew Morton, Rasmus Villemoes, linux-efi, Matt Fleming,
Arnd Bergmann, Theodore Ts'o
Cc: Andy Shevchenko
Generic UUID library defines structure type, macro to define UUID, and the
length of the UUID string. This patch removes duplicate data structure
definition, UUID string length constant as well as macro for UUID handling.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/efi.h | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 1626474..5b1d5c5 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -21,6 +21,7 @@
#include <linux/pfn.h>
#include <linux/pstore.h>
#include <linux/reboot.h>
+#include <linux/uuid.h>
#include <asm/page.h>
@@ -43,17 +44,10 @@ typedef u16 efi_char16_t; /* UNICODE character */
typedef u64 efi_physical_addr_t;
typedef void *efi_handle_t;
-
-typedef struct {
- u8 b[16];
-} efi_guid_t;
+typedef uuid_le efi_guid_t;
#define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
-((efi_guid_t) \
-{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
- (b) & 0xff, ((b) >> 8) & 0xff, \
- (c) & 0xff, ((c) >> 8) & 0xff, \
- (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
+ UUID_LE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
/*
* Generic EFI table header
@@ -1050,7 +1044,7 @@ efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
* Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
* not including trailing NUL
*/
-#define EFI_VARIABLE_GUID_LEN 36
+#define EFI_VARIABLE_GUID_LEN UUID_STRING_LEN
/*
* The type of search to perform when calling boottime->locate_handle
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 27+ messages in thread