From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04D2DC433E2 for ; Wed, 24 Jun 2020 05:13:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E33A32088E for ; Wed, 24 Jun 2020 05:13:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388845AbgFXFNX (ORCPT ); Wed, 24 Jun 2020 01:13:23 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:47028 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727957AbgFXFNW (ORCPT ); Wed, 24 Jun 2020 01:13:22 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id B1D7D2A3349 From: Gabriel Krisman Bertazi To: Daniel Rosenberg Cc: "Theodore Ts'o" , linux-ext4@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net, Eric Biggers , linux-fscrypt@vger.kernel.org, Alexander Viro , Richard Weinberger , linux-mtd@lists.infradead.org, Andreas Dilger , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v9 1/4] unicode: Add utf8_casefold_hash Organization: Collabora References: <20200624043341.33364-1-drosen@google.com> <20200624043341.33364-2-drosen@google.com> Date: Wed, 24 Jun 2020 01:13:17 -0400 In-Reply-To: <20200624043341.33364-2-drosen@google.com> (Daniel Rosenberg's message of "Tue, 23 Jun 2020 21:33:38 -0700") Message-ID: <87h7v1gi6q.fsf@collabora.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Daniel Rosenberg writes: > This adds a case insensitive hash function to allow taking the hash > without needing to allocate a casefolded copy of the string. > > Signed-off-by: Daniel Rosenberg > --- > fs/unicode/utf8-core.c | 23 ++++++++++++++++++++++- > include/linux/unicode.h | 3 +++ > 2 files changed, 25 insertions(+), 1 deletion(-) > > diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c > index 2a878b739115d..90656b9980720 100644 > --- a/fs/unicode/utf8-core.c > +++ b/fs/unicode/utf8-core.c > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > > #include "utf8n.h" > > @@ -122,9 +123,29 @@ int utf8_casefold(const struct unicode_map *um, const struct qstr *str, > } > return -EINVAL; > } > - > EXPORT_SYMBOL(utf8_casefold); > > +int utf8_casefold_hash(const struct unicode_map *um, const void *salt, > + struct qstr *str) > +{ > + const struct utf8data *data = utf8nfdicf(um->version); > + struct utf8cursor cur; > + int c; > + unsigned long hash = init_name_hash(salt); > + > + if (utf8ncursor(&cur, data, str->name, str->len) < 0) > + return -EINVAL; > + > + while ((c = utf8byte(&cur))) { > + if (c < 0) > + return c; Return -EINVAL here to match other unicode functions, since utf8byte will return -1 on a binary blob, which doesn't make sense for this. Other than that, looks good to me. Reviewed-by: Gabriel Krisman Bertazi > + hash = partial_name_hash((unsigned char)c, hash); > + } > + str->hash = end_name_hash(hash); > + return 0; > +} > +EXPORT_SYMBOL(utf8_casefold_hash); > + > int utf8_normalize(const struct unicode_map *um, const struct qstr *str, > unsigned char *dest, size_t dlen) > { > diff --git a/include/linux/unicode.h b/include/linux/unicode.h > index 990aa97d80496..74484d44c7554 100644 > --- a/include/linux/unicode.h > +++ b/include/linux/unicode.h > @@ -27,6 +27,9 @@ int utf8_normalize(const struct unicode_map *um, const struct qstr *str, > int utf8_casefold(const struct unicode_map *um, const struct qstr *str, > unsigned char *dest, size_t dlen); > > +int utf8_casefold_hash(const struct unicode_map *um, const void *salt, > + struct qstr *str); > + > struct unicode_map *utf8_load(const char *version); > void utf8_unload(struct unicode_map *um); -- Gabriel Krisman Bertazi