From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932952AbdBHIsX (ORCPT ); Wed, 8 Feb 2017 03:48:23 -0500 Received: from mail2.skidata.com ([91.230.2.91]:37629 "EHLO mail2.skidata.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932344AbdBHIq4 (ORCPT ); Wed, 8 Feb 2017 03:46:56 -0500 X-Greylist: delayed 785 seconds by postgrey-1.27 at vger.kernel.org; Wed, 08 Feb 2017 03:46:55 EST X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2GzBwCh15pY/0oKEKxdGwEBAQMBAQEJA?= =?us-ascii?q?QEBhFxfB4NSm3cfEJMXhBuGIgKDIBQBAgEBAQEBAQEDgQeEagEFIw8BRhALDQs?= =?us-ascii?q?CAiYCAkcQBgEMAQUCArlugiUmAosrAQEBAQEBAQMBAQEBAQEiCQGBAYVBggUIg?= =?us-ascii?q?mKHWoJfBYZelRKBf4sxjyEXhi+TEjaBIA8QDwQdhRIggWJ0h3KBDAEBAQ?= X-IPAS-Result: =?us-ascii?q?A2GzBwCh15pY/0oKEKxdGwEBAQMBAQEJAQEBhFxfB4NSm3c?= =?us-ascii?q?fEJMXhBuGIgKDIBQBAgEBAQEBAQEDgQeEagEFIw8BRhALDQsCAiYCAkcQBgEMA?= =?us-ascii?q?QUCArlugiUmAosrAQEBAQEBAQMBAQEBAQEiCQGBAYVBggUIgmKHWoJfBYZelRK?= =?us-ascii?q?Bf4sxjyEXhi+TEjaBIA8QDwQdhRIggWJ0h3KBDAEBAQ?= X-IronPort-AV: E=Sophos;i="5.33,346,1477954800"; d="scan'208";a="370480" Subject: Re: [PATCH v3 1/3] lib/string: introduce ascii2utf16le() helper To: Sergei Shtylyov , References: <29ff4981-ed4d-d87b-f6e2-112234f6a10a@cogentembedded.com> CC: , , , , , , , , From: Richard Leitner Message-ID: <9316678a-0257-e761-c9b7-758cc492da0c@skidata.com> Date: Wed, 8 Feb 2017 09:33:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 MIME-Version: 1.0 In-Reply-To: <29ff4981-ed4d-d87b-f6e2-112234f6a10a@cogentembedded.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [172.16.60.30] X-ClientProxiedBy: sdex1srv.skidata.net (172.16.10.92) To sdex1srv.skidata.net (172.16.10.92) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/06/2017 05:48 PM, Sergei Shtylyov wrote: > Hello! > > On 02/06/2017 05:03 PM, Richard Leitner wrote: > >> For USB string descriptors we need to convert ASCII strings to UTF16-LE. >> Therefore make a simple helper function (based on ascii2desc from >> drivers/usb/core/hcd.c) for that purpose. >> >> Signed-off-by: Richard Leitner > [...] >> diff --git a/lib/string.c b/lib/string.c >> index ed83562..a113e3e 100644 >> --- a/lib/string.c >> +++ b/lib/string.c >> @@ -952,3 +952,29 @@ char *strreplace(char *s, char old, char new) >> return s; >> } >> EXPORT_SYMBOL(strreplace); >> + >> +/** >> + * ascii2utf16le() - Helper routine for producing UTF-16LE string >> descriptors >> + * @s: Null-terminated ASCII (actually ISO-8859-1) string >> + * @buf: Buffer for UTF-16LE string >> + * @len: Length (in bytes; may be odd) of UTF-16LE buffer. >> + * >> + * Return: The number of bytes filled in: 2*strlen(s) or @len, >> whichever is less >> + */ >> +unsigned int ascii2utf16le(char const *s, u8 *buf, unsigned int len) >> +{ >> + unsigned int n, t = 2 * strlen(s); >> + >> + if (len > t) >> + len = t; >> + n = len; >> + while (n--) { >> + t = (unsigned char)*s++; >> + *buf++ = t; >> + if (!n--) >> + break; >> + *buf++ = t >> 8; > > Isn't it always 0? As I will remove this function and use utf8s_to_utf16s() instead (as suggested by Alan Stern) IMHO this issue needs no more attention. Nonetheless, thank you for your feedback! > >> + } >> + return len; >> +} >> +EXPORT_SYMBOL(ascii2utf16le); regards, Richard L