From patchwork Mon Jan 25 13:43:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 370225 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp3992758jam; Mon, 25 Jan 2021 05:27:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJypO3+cikrDpg6fEsk7btBqQ3Jzd0nggRbnpCcldfYqdB72l+oEF3bb3jnzKtWlsSePovLA X-Received: by 2002:a17:906:3ce:: with SMTP id c14mr353980eja.497.1611581255508; Mon, 25 Jan 2021 05:27:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1611581255; cv=pass; d=google.com; s=arc-20160816; b=BX1QSn2hltNgPblaIAdrAR4HAk9D8aO10pfVIWq/RhSvnHrM6XHALd9zRuaelMHCUE l6TBbxFo+HYbxxSIwX0PiB+mHjnZDvkXrJqhY49HW2sU5iYi+Xi8EykEnycqnIq14KPD Y3FK255s+WOtOTaFRHO0u1q9Nx0CWw/3PX7EBUM0g+lRuyaPzbmIFlCH5iRpyks/c/I0 d6rqkqTT01fI97mV/Zs6v8k5nQJOu/jYHTupm7PCbd27T/O7sa7Ght1ZA8XFgwKhadE+ rOuk/hABj4s3SqSUuRMHu4QNfw2B2oGGODh3HUYkUgLfChD6f+S2IKn9/k6mD/p5r9Qm NTsA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version :content-transfer-encoding:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=qSzIFOAmLwBm07txlGSkMyvvanwWEjR+5MWyLOMY4/o=; b=xIYD41q+75rBDHHhQO+03ebdfprC6lnQrEt8EqyJNP45Gv0RkPLUAKIoIEjkBE7s2H DUZsaR2X4uK+7XKQo/kKXyff7SgtFe7glppMgi2OCImAC/9/40UsLrnTqbEy+Z8m/NFp +WW422inJ/eJek3wEASEBuXeUALfNwvr9sjHqu0PHmQNge3O7fUXmv9Vo/HINfQRdoAu pLKim4LTyfqI+JRAFhcO/up3Pvc4tPyKSc3fX3FXScl5gC+XCHBNf8Ovot6LeJi39b6p VJ+tjOEpF2HKfla1hrbCOYUXHXApUItMrYwi7kbdGv57mAgvYPw5NskjPazuB+7EwI/p wrxA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=njB5ZC8j; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a16si5895983ejt.459.2021.01.25.05.27.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jan 2021 05:27:35 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=njB5ZC8j; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DF62782713; Mon, 25 Jan 2021 14:26:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="njB5ZC8j"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8425A8267A; Mon, 25 Jan 2021 14:14:46 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0629.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe1f::629]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 81DC582642 for ; Mon, 25 Jan 2021 14:14:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=peng.fan@nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oMqokSBOuyaNpmh60jrNaLdief0Z66p+QDnMH1WSUVfIInID16s66ZE6OL3AHZu1Epj0om6wqsLEpnXR7HAslxFKWVdiVS+C/2NNTVcQgU3J2AVLrBA18iLcbP3R4K5Cy35QS3ZM4tRGDuibLsGKGJAvY5oxvHvl9Ffs0Alyx7ss8HsEm1oTUQWvmeB6rYiCtSrMaxhgSLkEvOVEx8UrJc+ofKZaSnDnpX87GUhxYDcvA2F4BYdTgJIa1hYSqPVrf2V1/wSKmGmd9NKiDacvPVizfSLZthH91VOTDiDXwMZVInPp+7zSa4EKmcLmeLocZg5BtD2CzY5Do7mFqMBDxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qSzIFOAmLwBm07txlGSkMyvvanwWEjR+5MWyLOMY4/o=; b=JfZmDH/EhsD4aUOCbvtpQ/HD+2eEYWKAAcMncCGOKY1AWIp6ns9ebcfjK35900zxyYcOID9ZOq0bC7kHzUIHLjr24afXH2cRxXgt76vk+0vKhElkw/Ptz8954FV2STrEKDcxWKm9lv++29JKUltZFmOdf4SDky6AnA2eYXELiJ2QFCpqpiGYAcN1bclMniZVupBw82jx3onCa9RpV34g/qTxs3BbY7In7T+bGIKieu6dCWWpfJVu9cWN3z1nm0sLeC0BK34uvbmq+hpCSQH7SwmhDmqSuFVZ96Z0mqLkAJeZewlaufTCpnNrnNk1U5YHk0x2TVL/uN5zqGE3M/ubAw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qSzIFOAmLwBm07txlGSkMyvvanwWEjR+5MWyLOMY4/o=; b=njB5ZC8jkMf4MDPneyngs00OFPy37U9B7gJNXJRDAtvkLZqvo353qLEy0SXzwyzdXbtLiEeAfYn+mraaAp4P3ZO/8PLldTDK8y8WReOIGf2bqvfcX+YXCNMXKNdeMp2Q3nSjnmeDP/4/DfxxxqiIHGBTYo5iAsWSsvFX20cx8no= Authentication-Results: denx.de; dkim=none (message not signed) header.d=none;denx.de; dmarc=none action=none header.from=nxp.com; Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) by DB6PR04MB3128.eurprd04.prod.outlook.com (2603:10a6:6:10::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.13; Mon, 25 Jan 2021 13:14:41 +0000 Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::d58c:d479:d094:43d0]) by DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::d58c:d479:d094:43d0%9]) with mapi id 15.20.3784.019; Mon, 25 Jan 2021 13:14:41 +0000 From: peng.fan@nxp.com To: sbabic@denx.de, lukma@denx.de, marex@denx.de Cc: uboot-imx@nxp.com, u-boot@lists.denx.de, Li Jun , Peng Fan Subject: [PATCH V2 04/17] usb: gadget: move utf8_to_utf16le to header file Date: Mon, 25 Jan 2021 21:43:47 +0800 Message-Id: <20210125134400.780-5-peng.fan@nxp.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210125134400.780-1-peng.fan@nxp.com> References: <20210125134400.780-1-peng.fan@nxp.com> X-Originating-IP: [119.31.174.71] X-ClientProxiedBy: SG2PR03CA0117.apcprd03.prod.outlook.com (2603:1096:4:91::21) To DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from linux-1xn6.ap.freescale.net (119.31.174.71) by SG2PR03CA0117.apcprd03.prod.outlook.com (2603:1096:4:91::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.6 via Frontend Transport; Mon, 25 Jan 2021 13:14:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b6f8ac53-b219-4638-e9e2-08d8c1332d01 X-MS-TrafficTypeDiagnostic: DB6PR04MB3128: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:466; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jxNut7FzBM4TTObuSLbcHZvrKlcpVH3m7d7aSr0DeL8XPLwuu3auSlIJ0UXFLUkqV3W3jm8jfukg3XJcv2NRsxafOMU2I+oYr5nsbqCj4r+8kU1rVSAUenY/HFpSWuPAgEkDoXDkR9saeihHMI1aAwAJzahjxDpgRm+23LdX1XwnZ0khycsdgpWt/Iz9KVEPKfDEujPoKDYU0r+kjyRZsNWGhwKK6+vIKJ0MjUoPXtwqNE2l0NBoPLm/sbo8zcIahedZu3O9oNqqKw6lHA0e2LA1WzatpvfooUcBRgx/Oc9S+iIY8nbdPTvojmxdaV6zItoRc14aQGHUdnMwMpXAuCT/kFKASo4y+HCxAvz4hPhr/Iyug40cOaRsOgYaa9/zrtz5U+FBGxwd1YHsCyjomg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB6PR0402MB2760.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(136003)(39860400002)(376002)(366004)(396003)(6506007)(1076003)(26005)(316002)(6512007)(186003)(4326008)(54906003)(83380400001)(478600001)(8936002)(8676002)(86362001)(6486002)(2906002)(36756003)(6666004)(5660300002)(9686003)(66556008)(2616005)(66476007)(16526019)(956004)(66946007)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: KiHt8H3jJAKnEvhoI4j3K0zNLbrbGqyPIHCrkrdfxynrXMO6dzjXCFzivk34YEXwgVS5TtQnXy/lAkcWnw6nV+mvk6np6yo5FpuwVMemgLVohbBxWiWLzUV+BYPngjl6Cjhu5h3mDYu21NgOKoLsO2xf1m/F25BwE/vCKD9aH39OB9JTvKH/R9V0neMwWBdyBQ8Z33oKi66tsmm2fjWCK5mjcNYaxR0I0O/3ZhuObn3L4oPXQeTPHcVsCz2tHHy6099Csbc3CBF0/uoh/bUsNqjBmtU+yGrNzU2+sKhZIViBewEVBQqbsC7XGyr2vkKaPFv1qF2XNhwTqRaQRtdHTSL6rEIlYftGiJTLAMVejcUrzOTY8DkKtvd60b/pPHmNSxmCi4E9FGdlf8T+o+oXeAUfaUNIXxWKn9vIXJpovx6OkdIyBNJiU6XIinwcQRa1G59wtlasUo9PznAbZDtYtMYAdf1TfAbFnVpABLOEKfa8TH+3jkbUkjMmNDTR+HeFU8tDkQ8TuEtLD29UPDVN6efpR4D7ZbVv7FE5xfpumLytzrim11DxORXQLQE583JhAioMLW8KxduQ9jY4d5kMqtLE6T6CZjYGB6zBvcNJheDG2tPsbs4JqLNWzy1Xz4XiJZBzoo5D4yRDi0yCCfklXS6JE7kxgDBvWK0imI9uxiQnLZi3ENzFSB5l2ij5y20peMC7fmEfPfbLcUYfHjg8+M8FnperAFwTPex5n13q0iQ4j9598MUXJYzZOBHV05PK642e/6qyWwB0eVFw2CyMKZ7zMNC1jlbmtrdtuK6oPihV0gJ9oznrbI8QZOLN/WUu50lLyrSvGndgeJwgp2SfA0YikY+YgJkfK+o7rvlFBXCQBWlIPLcHWDDpl+DfCgHqEvX7fJC6GS1f/+tzUwPeIiM9xza2AR0RJUcca+whUTChDGjk76r4Rf1a8G9v4g7gvkqxkdTBM447P4M8TTZ/ReINMUpM2durKqS++Z7yi0WYc5oaQ2Si201pDIiJ3RON X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b6f8ac53-b219-4638-e9e2-08d8c1332d01 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0402MB2760.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2021 13:14:41.7817 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iSvkS0FPcRfTbloNmckWTvBzMe7rFRIV3UEHLE/X2TJaqstziuRnyBA048geRiw3eD7u9EEwwr7FSgYmpBEgKg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR04MB3128 X-Mailman-Approved-At: Mon, 25 Jan 2021 14:26:22 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Li Jun As other users may use utf8_to_utf16le() to convert the utf8 to utf16 for usb, so move it to head file. Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/usbstring.c | 74 +-------------------------------- include/linux/utf.h | 75 ++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 73 deletions(-) create mode 100644 include/linux/utf.h -- 2.28.0 diff --git a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c index 83cdd8a259..e2464ad923 100644 --- a/drivers/usb/gadget/usbstring.c +++ b/drivers/usb/gadget/usbstring.c @@ -10,79 +10,7 @@ #include #include #include - -#include - - -static int utf8_to_utf16le(const char *s, __le16 *cp, unsigned len) -{ - int count = 0; - u8 c; - u16 uchar; - - /* - * this insists on correct encodings, though not minimal ones. - * BUT it currently rejects legit 4-byte UTF-8 code points, - * which need surrogate pairs. (Unicode 3.1 can use them.) - */ - while (len != 0 && (c = (u8) *s++) != 0) { - if ((c & 0x80)) { - /* - * 2-byte sequence: - * 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx - */ - if ((c & 0xe0) == 0xc0) { - uchar = (c & 0x1f) << 6; - - c = (u8) *s++; - if ((c & 0xc0) != 0x80) - goto fail; - c &= 0x3f; - uchar |= c; - - /* - * 3-byte sequence (most CJKV characters): - * zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx - */ - } else if ((c & 0xf0) == 0xe0) { - uchar = (c & 0x0f) << 12; - - c = (u8) *s++; - if ((c & 0xc0) != 0x80) - goto fail; - c &= 0x3f; - uchar |= c << 6; - - c = (u8) *s++; - if ((c & 0xc0) != 0x80) - goto fail; - c &= 0x3f; - uchar |= c; - - /* no bogus surrogates */ - if (0xd800 <= uchar && uchar <= 0xdfff) - goto fail; - - /* - * 4-byte sequence (surrogate pairs, currently rare): - * 11101110wwwwzzzzyy + 110111yyyyxxxxxx - * = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx - * (uuuuu = wwww + 1) - * FIXME accept the surrogate code points (only) - */ - } else - goto fail; - } else - uchar = c; - put_unaligned_le16(uchar, cp++); - count++; - len--; - } - return count; -fail: - return -1; -} - +#include /** * usb_gadget_get_string - fill out a string descriptor diff --git a/include/linux/utf.h b/include/linux/utf.h new file mode 100644 index 0000000000..e1f7d3bd1d --- /dev/null +++ b/include/linux/utf.h @@ -0,0 +1,75 @@ +#ifndef _LINUX_UTF_H +#define _LINUX_UTF_H + +#include + +static inline int utf8_to_utf16le(const char *s, __le16 *cp, unsigned len) +{ + int count = 0; + u8 c; + u16 uchar; + + /* + * this insists on correct encodings, though not minimal ones. + * BUT it currently rejects legit 4-byte UTF-8 code points, + * which need surrogate pairs. (Unicode 3.1 can use them.) + */ + while (len != 0 && (c = (u8) *s++) != 0) { + if ((c & 0x80)) { + /* + * 2-byte sequence: + * 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx + */ + if ((c & 0xe0) == 0xc0) { + uchar = (c & 0x1f) << 6; + + c = (u8) *s++; + if ((c & 0xc0) != 0x80) + goto fail; + c &= 0x3f; + uchar |= c; + + /* + * 3-byte sequence (most CJKV characters): + * zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx + */ + } else if ((c & 0xf0) == 0xe0) { + uchar = (c & 0x0f) << 12; + + c = (u8) *s++; + if ((c & 0xc0) != 0x80) + goto fail; + c &= 0x3f; + uchar |= c << 6; + + c = (u8) *s++; + if ((c & 0xc0) != 0x80) + goto fail; + c &= 0x3f; + uchar |= c; + + /* no bogus surrogates */ + if (0xd800 <= uchar && uchar <= 0xdfff) + goto fail; + + /* + * 4-byte sequence (surrogate pairs, currently rare): + * 11101110wwwwzzzzyy + 110111yyyyxxxxxx + * = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx + * (uuuuu = wwww + 1) + * FIXME accept the surrogate code points (only) + */ + } else + goto fail; + } else + uchar = c; + put_unaligned_le16(uchar, cp++); + count++; + len--; + } + return count; +fail: + return -1; +} + +#endif /* _LINUX_UTF_H */