From patchwork Mon Oct 24 08:52:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li kunyu X-Patchwork-Id: 8254 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp334962wru; Mon, 24 Oct 2022 02:03:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lZcuwwgaSMwDF65lH4dX2JbLzKLwD3/dxmBfDVMvCv8aw0R83zu0tLcJD5dpHxI4Ti6ex X-Received: by 2002:a17:907:3f95:b0:7a2:36c7:31bd with SMTP id hr21-20020a1709073f9500b007a236c731bdmr7911249ejc.353.1666602209432; Mon, 24 Oct 2022 02:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666602209; cv=none; d=google.com; s=arc-20160816; b=yG9XQV93LpE1dSx1R0qVUYUscomVvNRdwIRw7kBn1IY/QssI9L6Wueqr2IKwc/Fcl3 fa/aMesR5nFOd+XRHkR+2VHHtC+2DfgFVZ7SlWnzwTpEpSB70MNlJ7FlKv7DU8Ahnf3R cWPp20VvrA92MUsVmLbo2qMnx8avdMIt4x8fWhJMEbKV9v4MNCPnj/UaWk1j+fMb3qoY 1nCq0XcZ499BtPfqFq1vFpt/a94L+B3TWAUcfQqM5yW4VueBnNKkvoTiLNJSykAi1w3x iTX5W8sto2VwrFCLgvICNpQUj8r2aSghtmGiaFNnvOLgiBMf7FRCZ/D4SD2pyp7hK1c5 L7Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=G9fDH74OcuvpxR0R77iuNbojtFZZtD6cZczpV/TSwrc=; b=KAb5szr0kGRkclUg02/1v8zJimp9JscxRc3/ev1BsfmF+iOoVGS/T5xCmVH8GwcL2n lIwkov6VuheYx5hzdVRgSg44ns19WbwtJjlsmV6hek0Joqixkx4NkZWjtsuY7XExhAn3 Lg4fU++Mp/kOabpN5Fo+DEMAsQlQHhPGqKyB+pV6mPvVGswUkpYfTV7DFxJMeOioE7gR jIC/0GvIk3+0nb9ZISY5j+LX+7Ujs4nOtWiVhwsglwIIww1xoCzzg8f8qpyRxCUXiLDb rO3W12DNa1ZGNDE+0lExEKGnzEtLN+rdw0uRkPNRHIxMUumfzoSsHACdN6T4D9/f0roW myyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc15-20020a170907168f00b0073d74bcac8dsi25829043ejc.513.2022.10.24.02.03.05; Mon, 24 Oct 2022 02:03:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229936AbiJXIwg (ORCPT + 99 others); Mon, 24 Oct 2022 04:52:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229720AbiJXIwf (ORCPT ); Mon, 24 Oct 2022 04:52:35 -0400 Received: from mail.nfschina.com (unknown [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6F37156BA3; Mon, 24 Oct 2022 01:52:33 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 40B871E80D74; Mon, 24 Oct 2022 16:51:16 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id z6o2LBHNephC; Mon, 24 Oct 2022 16:51:13 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 5B6531E80CA5; Mon, 24 Oct 2022 16:51:13 +0800 (CST) From: Li kunyu To: krisman@collabora.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Li kunyu Subject: [PATCH] unicode: mkutf8data: Add unicode_data_malloc function Date: Mon, 24 Oct 2022 16:52:22 +0800 Message-Id: <20221024085222.179528-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747559078448420063?= X-GMAIL-MSGID: =?utf-8?q?1747559078448420063?= Add unicode_data_malloc function, used to simplify unicode_data member assignment use. Signed-off-by: Li kunyu --- fs/unicode/mkutf8data.c | 43 +++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/fs/unicode/mkutf8data.c b/fs/unicode/mkutf8data.c index bc1a7c8b5c8d..f86fa700f7dc 100644 --- a/fs/unicode/mkutf8data.c +++ b/fs/unicode/mkutf8data.c @@ -2113,6 +2113,16 @@ static int ignore_compatibility_form(char *type) return 0; } +static void unicode_data_malloc(void *src, void **dst, size_t len) +{ + unsigned int *um = malloc(len); + + if (um) + memcpy(um, src, len); + + *dst = um; +} + static void nfdi_init(void) { FILE *file; @@ -2120,7 +2130,6 @@ static void nfdi_init(void) unsigned int mapping[19]; /* Magic - guaranteed not to be exceeded. */ char *s; char *type; - unsigned int *um; int count; int i; int ret; @@ -2159,10 +2168,8 @@ static void nfdi_init(void) } mapping[i++] = 0; - um = malloc(i * sizeof(unsigned int)); - memcpy(um, mapping, i * sizeof(unsigned int)); - unicode_data[unichar].utf32nfdi = um; - + unicode_data_malloc(mapping, &unicode_data[unichar].utf32nfdi, + i * sizeof(unsigned int)); if (verbose > 1) print_utf32nfdi(unichar); count++; @@ -2181,7 +2188,6 @@ static void nfdicf_init(void) unsigned int mapping[19]; /* Magic - guaranteed not to be exceeded. */ char status; char *s; - unsigned int *um; int i; int count; int ret; @@ -2215,10 +2221,8 @@ static void nfdicf_init(void) } mapping[i++] = 0; - um = malloc(i * sizeof(unsigned int)); - memcpy(um, mapping, i * sizeof(unsigned int)); - unicode_data[unichar].utf32nfdicf = um; - + unicode_data_malloc(mapping, &unicode_data[unichar].utf32nfdicf, + i * sizeof(unsigned int)); if (verbose > 1) print_utf32nfdicf(unichar); count++; @@ -2307,7 +2311,6 @@ static void corrections_init(void) unsigned int minor; unsigned int revision; unsigned int age; - unsigned int *um; unsigned int mapping[19]; /* Magic - guaranteed not to be exceeded. */ char *s; int i; @@ -2359,10 +2362,8 @@ static void corrections_init(void) } mapping[i++] = 0; - um = malloc(i * sizeof(unsigned int)); - memcpy(um, mapping, i * sizeof(unsigned int)); - corrections[count].utf32nfdi = um; - + unicode_data_malloc(mapping, &corrections[count].utf32nfdi, + i * sizeof(unsigned int)); if (verbose > 1) printf(" %X -> %s -> %s V%d_%d_%d\n", unichar, buf0, buf1, major, minor, revision); @@ -2437,7 +2438,6 @@ static void hangul_decompose(void) /* unsigned int sc = (lc * nc); */ unsigned int unichar; unsigned int mapping[4]; - unsigned int *um; int count; int i; @@ -2458,15 +2458,12 @@ static void hangul_decompose(void) mapping[i++] = tb + ti; mapping[i++] = 0; - assert(!unicode_data[unichar].utf32nfdi); - um = malloc(i * sizeof(unsigned int)); - memcpy(um, mapping, i * sizeof(unsigned int)); - unicode_data[unichar].utf32nfdi = um; + unicode_data_malloc(mapping, &unicode_data[unichar].utf32nfdi, + i * sizeof(unsigned int)); assert(!unicode_data[unichar].utf32nfdicf); - um = malloc(i * sizeof(unsigned int)); - memcpy(um, mapping, i * sizeof(unsigned int)); - unicode_data[unichar].utf32nfdicf = um; + unicode_data_malloc(mapping, &unicode_data[unichar].utf32nfdicf, + i * sizeof(unsigned int)); /* * Add a cookie as a reminder that the hangul syllable