Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755495AbcDDNaf (ORCPT ); Mon, 4 Apr 2016 09:30:35 -0400 Received: from mga03.intel.com ([134.134.136.65]:22520 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755460AbcDDNad (ORCPT ); Mon, 4 Apr 2016 09:30:33 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,440,1455004800"; d="scan'208";a="78702351" From: Andy Shevchenko To: Arnd Bergmann , "Theodore Ts'o" , Matt Fleming , Andrew Morton , Rasmus Villemoes , linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, linux-api@vger.kernel.org Cc: Andy Shevchenko Subject: [PATCH v2 6/8] sysctl: use generic UUID library Date: Mon, 4 Apr 2016 16:30:08 +0300 Message-Id: <1459776610-68469-7-git-send-email-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1459776610-68469-1-git-send-email-andriy.shevchenko@linux.intel.com> References: <1459776610-68469-1-git-send-email-andriy.shevchenko@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1544 Lines: 59 UUID library provides uuid_be type and uuid_be_to_bin() function. This substitutes open coded variant by generic library calls. Signed-off-by: Andy Shevchenko --- kernel/sysctl_binary.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c index 055ad65..ce94c45 100644 --- a/kernel/sysctl_binary.c +++ b/kernel/sysctl_binary.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -1117,9 +1118,8 @@ static ssize_t bin_uuid(struct file *file, /* Only supports reads */ if (oldval && oldlen) { - char buf[40], *str = buf; - unsigned char uuid[16]; - int i; + char buf[UUID_STRING_LEN + 1]; + uuid_be uuid; result = kernel_read(file, 0, buf, sizeof(buf) - 1); if (result < 0) @@ -1128,21 +1128,13 @@ static ssize_t bin_uuid(struct file *file, buf[result] = '\0'; /* Convert the uuid to from a string to binary */ - for (i = 0; i < 16; i++) { - if (!isxdigit(str[0]) || !isxdigit(str[1])) - return -EIO; - - uuid[i] = (hex_to_bin(str[0]) << 4) | - hex_to_bin(str[1]); - str += 2; - if (*str == '-') - str++; - } + if (uuid_be_to_bin(buf, &uuid)) + return -EIO; if (oldlen > 16) oldlen = 16; - if (copy_to_user(oldval, uuid, oldlen)) + if (copy_to_user(oldval, &uuid, oldlen)) return -EFAULT; copied = oldlen; -- 2.8.0.rc3