From patchwork Tue Jul 6 15:08:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 110430 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o66F9OcZ003582 for ; Tue, 6 Jul 2010 15:09:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753653Ab0GFPI6 (ORCPT ); Tue, 6 Jul 2010 11:08:58 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:44506 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751814Ab0GFPI5 (ORCPT ); Tue, 6 Jul 2010 11:08:57 -0400 Received: by fxm14 with SMTP id 14so4907720fxm.19 for ; Tue, 06 Jul 2010 08:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=ohBi6dhNWUzum6UNN+8HkilGjAkUuRTh6hoqb1b9KdY=; b=r/4bMleT4glB7tVa7LhwRF+QqsaYNJI845oeaUVf/6fvMmUImlc2YyLZ9CYn8yDj6L 0qmjpIbpZyzKPNWxeIJgkkhdhfefU1luybMnHR20/3Ub+IzFe91HDnn9qwcXy0r8J9iX hSJbgotnL0lO/SGvfItoHvi3CgLVlwm7lRsEU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=AvZbgieHcixBv+NMYUSk4F0qFeYOUlLjo+pvlF22jgAN+KI3pmyk8K2p3NhcZAY2wL uo0nb6fClkaD4BV7pNudpIVarFacUl8DJXYPnJJekJod1rw6KqWv+m+tcbsnUqS+win5 iAfFUQ59NCfuIIqLJQLdl7geFZ/jlOkTxLbT0= Received: by 10.86.52.20 with SMTP id z20mr1220004fgz.34.1278428935794; Tue, 06 Jul 2010 08:08:55 -0700 (PDT) Received: from localhost.localdomain (79-134-110-189.cust.suomicom.fi [79.134.110.189]) by mx.google.com with ESMTPS id h4sm12089361fai.6.2010.07.06.08.08.54 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 06 Jul 2010 08:08:55 -0700 (PDT) From: Andy Shevchenko To: linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Ohad Ben-Cohen , Greg Kroah-Hartman , linux-omap@vger.kernel.org Subject: [PATCH] staging: tidspbridge: gen: simplify and clean up Date: Tue, 6 Jul 2010 18:08:52 +0300 Message-Id: <1278428932-9145-1-git-send-email-andy.shevchenko@gmail.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: References: Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 06 Jul 2010 15:09:27 +0000 (UTC) diff --git a/drivers/staging/tidspbridge/gen/uuidutil.c b/drivers/staging/tidspbridge/gen/uuidutil.c index ce9319d..eb09bc3 100644 --- a/drivers/staging/tidspbridge/gen/uuidutil.c +++ b/drivers/staging/tidspbridge/gen/uuidutil.c @@ -54,61 +54,19 @@ void uuid_uuid_to_string(IN struct dsp_uuid *uuid_obj, OUT char *pszUuid, DBC_ENSURE(i != -1); } -/* - * ======== htoi ======== - * Purpose: - * Converts a hex value to a decimal integer. - */ - -static int htoi(char c) +static s32 uuid_hex_to_bin(char *buf, s32 len) { - switch (c) { - case '0': - return 0; - case '1': - return 1; - case '2': - return 2; - case '3': - return 3; - case '4': - return 4; - case '5': - return 5; - case '6': - return 6; - case '7': - return 7; - case '8': - return 8; - case '9': - return 9; - case 'A': - return 10; - case 'B': - return 11; - case 'C': - return 12; - case 'D': - return 13; - case 'E': - return 14; - case 'F': - return 15; - case 'a': - return 10; - case 'b': - return 11; - case 'c': - return 12; - case 'd': - return 13; - case 'e': - return 14; - case 'f': - return 15; + s32 i; + s32 result = 0; + + for (i = 0; i < len; i++) { + value = hex_to_bin(*buf++); + result *= 16; + if (value > 0) + result += value; } - return 0; + + return result; } /* @@ -118,106 +76,37 @@ static int htoi(char c) */ void uuid_uuid_from_string(IN char *pszUuid, OUT struct dsp_uuid *uuid_obj) { - char c; - s32 i, j; - s32 result; - char *temp = pszUuid; + s32 j; - result = 0; - for (i = 0; i < 8; i++) { - /* Get first character in string */ - c = *temp; - - /* Increase the results by new value */ - result *= 16; - result += htoi(c); - - /* Go to next character in string */ - temp++; - } - uuid_obj->ul_data1 = result; + uuid_obj->ul_data1 = uuid_hex_to_bin(pszUuid, 8); + pszUuid += 8; /* Step over underscore */ - temp++; + pszUuid++; - result = 0; - for (i = 0; i < 4; i++) { - /* Get first character in string */ - c = *temp; - - /* Increase the results by new value */ - result *= 16; - result += htoi(c); - - /* Go to next character in string */ - temp++; - } - uuid_obj->us_data2 = (u16) result; + uuid_obj->us_data2 = (u16) uuid_hex_to_bin(pszUuid, 4); + pszUuid += 4; /* Step over underscore */ - temp++; - - result = 0; - for (i = 0; i < 4; i++) { - /* Get first character in string */ - c = *temp; + pszUuid++; - /* Increase the results by new value */ - result *= 16; - result += htoi(c); - - /* Go to next character in string */ - temp++; - } - uuid_obj->us_data3 = (u16) result; + uuid_obj->us_data3 = (u16) uuid_hex_to_bin(pszUuid, 4); + pszUuid += 4; /* Step over underscore */ - temp++; - - result = 0; - for (i = 0; i < 2; i++) { - /* Get first character in string */ - c = *temp; + pszUuid++; - /* Increase the results by new value */ - result *= 16; - result += htoi(c); + uuid_obj->uc_data4 = (u8) uuid_hex_to_bin(pszUuid, 2); + pszUuid += 2; - /* Go to next character in string */ - temp++; - } - uuid_obj->uc_data4 = (u8) result; - - result = 0; - for (i = 0; i < 2; i++) { - /* Get first character in string */ - c = *temp; - - /* Increase the results by new value */ - result *= 16; - result += htoi(c); - - /* Go to next character in string */ - temp++; - } - uuid_obj->uc_data5 = (u8) result; + uuid_obj->uc_data5 = (u8) uuid_hex_to_bin(pszUuid, 2); + pszUuid += 2; /* Step over underscore */ - temp++; + pszUuid++; for (j = 0; j < 6; j++) { - result = 0; - for (i = 0; i < 2; i++) { - /* Get first character in string */ - c = *temp; - - /* Increase the results by new value */ - result *= 16; - result += htoi(c); - - /* Go to next character in string */ - temp++; - } - uuid_obj->uc_data6[j] = (u8) result; + uuid_obj->uc_data6[j] = (u8) uuid_hex_to_bin(pszUuid, 2); + pszUuid += 2; } }