Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp113091ybl; Tue, 10 Dec 2019 18:49:42 -0800 (PST) X-Google-Smtp-Source: APXvYqygWexJJJ9hjVk6z3MJQ6NnqSYJwb9kjtZ7DF/dxznwpDW0ReCEFfZog0F/do1hFfoiqOkz X-Received: by 2002:aca:de03:: with SMTP id v3mr1100081oig.162.1576032582049; Tue, 10 Dec 2019 18:49:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576032582; cv=none; d=google.com; s=arc-20160816; b=Hy6uvMKKv44dPb7JP5So00kJvmSOrIN4E6edv4H/llIdkpVZhc8gIWamo550SmzWm2 2eJefmqrqx2Ggv8mFYhXzUjK3kI2yPvLMeeJKdAh+k1GxiNqpRnNjSBfWFgsRJ8cz1ka 9HWT3UKSqY7rMmBzthdqxmsakeneBE9wrvujIihLckZAi3a0udReBtID83gGmsojyHgw DIcq6B0J/0RV8pkW0DctKqYoaCzlm96q2jwUSIT68T04VMx2sOzybtQiBvJ8us3tFbn+ KUHNbrm4PTXYcPHG3CWb2pL7kqv1G2TBPXbP9Ev6MHFES5+WR1dtjheQydoP/G9NG5OU LEGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=E6dBASQdLzUHXiZkGqiZcVIUWjiQd0xadsvz+yJF54o=; b=V3q7Ng5Se5R6gGjJrQbZ+J2ZNAUbR8eRwhI3aefkGj/42T2Ah9Q/iQxJZ7vpa60OKN XWb2JORcAA+EJeq9acjfVmiEFpbCI+Qj5Sg0FMo+TKPHbm/T72rrjFngMOUKwm161AdV GDoKibWtFkTFDq9vt6xm0/Q201gcPcAnmrvMvnGZ660NHdWJqyl+jKHoYmOCYSur/QS7 wlVFM4xJPexKiK5+P9c3akpZZ0ZOzpdjO9ExgdYHY84+z1/mtC4rGrOFQsMYfZzLQHOr 8+0y3FzHy9+CCV9aJhHo5FXZJ3DLCr++sQLbcS4qN+wloOT/gOrZe8sAlmIlXEju/qQb BKtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=N6Mbhyj+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u132si342754oig.93.2019.12.10.18.49.29; Tue, 10 Dec 2019 18:49:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=N6Mbhyj+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727707AbfLKCtB (ORCPT + 99 others); Tue, 10 Dec 2019 21:49:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:34736 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbfLKCtA (ORCPT ); Tue, 10 Dec 2019 21:49:00 -0500 Received: from sol.localdomain (c-24-5-143-220.hsd1.ca.comcast.net [24.5.143.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B0DF7205ED; Wed, 11 Dec 2019 02:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576032540; bh=yqkl8TN0O59NwfZP2OD2c0ghY0r4F9Diq35NeQInRfE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=N6Mbhyj+zaSmcMmFEcvuAbn1RXZr+9mfbi1gq5t+KWhaDMkXHPd4QmJPAy6aAUcrj 2rSpBj0soqrTUIN01JzV7gVd2iu0r43RuzzHf62jss0Iw3umpotijYsugx3sPQ+ltC 4KFA6yIXyUlcDslwsYyBzYXbhBt4f/wF3+Zd9F6U= Date: Tue, 10 Dec 2019 18:48:58 -0800 From: Eric Biggers To: Tiezhu Yang Cc: Alexander Viro , "Theodore Y. Ts'o" , Jaegeuk Kim , Chao Yu , Tyler Hicks , linux-fsdevel@vger.kernel.org, ecryptfs@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5] fs: introduce is_dot_or_dotdot helper for cleanup Message-ID: <20191211024858.GB732@sol.localdomain> References: <1576030801-8609-1-git-send-email-yangtiezhu@loongson.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1576030801-8609-1-git-send-email-yangtiezhu@loongson.cn> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 11, 2019 at 10:20:01AM +0800, Tiezhu Yang wrote: > diff --git a/include/linux/namei.h b/include/linux/namei.h > index 7fe7b87..0fd9315 100644 > --- a/include/linux/namei.h > +++ b/include/linux/namei.h > @@ -92,4 +92,14 @@ retry_estale(const long error, const unsigned int flags) > return error == -ESTALE && !(flags & LOOKUP_REVAL); > } > > +static inline bool is_dot_or_dotdot(const unsigned char *name, size_t len) > +{ > + if (unlikely(name[0] == '.')) { > + if (len == 1 || (len == 2 && name[1] == '.')) > + return true; > + } > + > + return false; > +} > + > #endif /* _LINUX_NAMEI_H */ I had suggested adding a len >= 1 check to handle the empty name case correctly. What I had in mind was static inline bool is_dot_or_dotdot(const unsigned char *name, size_t len) { if (len >= 1 && unlikely(name[0] == '.')) { if (len < 2 || (len == 2 && name[1] == '.')) return true; } return false; } As is, you're proposing that it always dereference the first byte even when len=0, which seems like a bad idea for a shared helper function. Did you check whether it's okay for all the existing callers? fscrypt_fname_disk_to_usr() is called from 6 places, did you check all of them? How about keeping the existing optimized code for the hot path in fs/namei.c (i.e. not using the helper function), while having the helper function do the extra check to handle len=0 correctly? - Eric