mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Richard Leitner <richard.leitner@skidata.com>
To: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>,
	<linux-usb@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<gregkh@linuxfoundation.org>, <robh+dt@kernel.org>,
	<mark.rutland@arm.com>, <akpm@linux-foundation.org>,
	<andriy.shevchenko@linux.intel.com>, <keescook@chromium.org>,
	<dev@g0hl1n.net>
Subject: Re: [PATCH v3 1/3] lib/string: introduce ascii2utf16le() helper
Date: Wed, 8 Feb 2017 09:33:31 +0100	[thread overview]
Message-ID: <9316678a-0257-e761-c9b7-758cc492da0c@skidata.com> (raw)
In-Reply-To: <29ff4981-ed4d-d87b-f6e2-112234f6a10a@cogentembedded.com>

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 <richard.leitner@skidata.com>
> [...]
>> 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

  reply	other threads:[~2017-02-08  8:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-06 14:03 [PATCH v3 0/3] usb: misc: add USB251xB/xBi Hi-Speed Hub Controller Driver Richard Leitner
2017-02-06 14:03 ` [PATCH v3 1/3] lib/string: introduce ascii2utf16le() helper Richard Leitner
2017-02-06 15:12   ` Alan Stern
2017-02-06 15:31     ` Richard Leitner
2017-02-06 15:40       ` Alan Stern
2017-02-06 15:43         ` Richard Leitner
2017-02-06 16:48   ` Sergei Shtylyov
2017-02-08  8:33     ` Richard Leitner [this message]
2017-02-06 14:03 ` [PATCH v3 2/3] usb: core: hcd: use ascii2utf16le() in ascii2desc() Richard Leitner
2017-02-06 14:03 ` [PATCH v3 3/3] usb: misc: add USB251xB/xBi Hi-Speed Hub Controller Driver Richard Leitner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9316678a-0257-e761-c9b7-758cc492da0c@skidata.com \
    --to=richard.leitner@skidata.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=dev@g0hl1n.net \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=sergei.shtylyov@cogentembedded.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®