Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp280847ybt; Tue, 23 Jun 2020 22:13:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUeo2TZSKXxix9hqa9tXG4igvsfmpIpeiI5C/kDNclnRHaQRAjKrf0ByURh7czngqmV3jN X-Received: by 2002:aa7:c4c7:: with SMTP id p7mr26046520edr.271.1592975635694; Tue, 23 Jun 2020 22:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592975635; cv=none; d=google.com; s=arc-20160816; b=RpYgjEd4daI+4HeInzjaZk9yETR4JmwThtrTw0XORtMN04ggdz2y0CaARmlg9MNrL1 gyA8gFQ9j2By3YkUGgPE/gJnoRpT5UBCYKQkg4vuZqa14lgut//XyXAG+hiZ8CCOuRrz jj7xtQpRVThpFlbpJLYjfdMIS+jrMz4n3zdRoSipEpoiuREwwd+K37c+C55XeF0u1ZpU em5U1z3soh3DbAYj3glihR5x5O2QU3eFWjcvsED0zSz5vioFjut4b+T5P0Y9PPFa79UQ 00H0WSwzS5NE4uCW22T0YJgWGoP5g3M0eI9Ewtc47c4IkxLQjxUJz3q71m1jnfwZX1SL /1iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:organization:subject:cc:to:from; bh=QBExvoWqNx9vJsU+C6RRi1K2Zz724x8K9+x1JEC/hB4=; b=PUn1CBJ8keUu0MG9/ssUTSqFLrMFX+yqDrEQuH7swuN8pZIEYIeAYHUHWS6WjEeXLB ZJzbrf8GJeoWGX2ORWfy9PbfY/3X+0fCPdT1FwlUsCTR0g4EG2gmgigy2AYdDtkYhVh1 0cnoPaH6Vfp4OxIdyL5wOWvV94GX/rSvmwliDLKF0EgbK9nDwXV8cPWhoCaYu0qAfLjR QWDAP8UZ1eZosjrq17Fpp6sLE8owhoXSlhzaLr8ghk4Gq371fu037FtXGqvAMg09nrMx soUfqUrvtSQWIIUupDGr5Tk2hEioguzR2DwBfAKFWCDbiV/Nc6qLQsu7Np4OIT3q/t2B 8aQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb10si17047550edb.410.2020.06.23.22.13.31; Tue, 23 Jun 2020 22:13:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388831AbgFXFNX (ORCPT + 99 others); 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