Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2476566pxa; Mon, 17 Aug 2020 10:30:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHFTxbVGc2l3/vCltIFPEpnllH+ww0NZIljk1i/eA6wZRD607c6OQOEHWq1TOUQwCH6GD7 X-Received: by 2002:a05:6402:896:: with SMTP id e22mr16482688edy.210.1597685457325; Mon, 17 Aug 2020 10:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597685457; cv=none; d=google.com; s=arc-20160816; b=dLH3uRGNGkqBXlf6EqMnZjABq1l8fPev+f3JOly+6ELP48wvubdxTmGVF8FQn16vN+ kSQ+24qYrXaDimhEcxwecz9f44f5ekCNv6MZFRupflPIxsKLnyTODXtETwXMTaq1pFK/ wTUuES8gAKkVRZfKQMJacfSUK6QbT17yreg4wchZIJhD/2sDqP3s11VKma/CfwRD1t7F J48UJThmNGfwz+GVTzBACWpDfhPTcg3tEMU5ELMp6j2l8HIgjY6kCnMAS8yFf0Hzum0C Yw6PB7GdqUjdEa/Ld4PViJU1tBv7EtM0g7Y/pO6Sb2CjjkGtbl+hVl7PGxt3SiFPFEdF LDpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=GLhojqeBc1t5le2BPl//GYnculviIsQyCN+NxIxLvao=; b=cBvwuBltbKEPbFWDXck0WBsCMmMrc+fJn7yqiG7cwJ1hnyDgFWpH9ArDLmFyhRTuGG Nm9Dgs7x4HIj6NuOQW3lWwtKZRbGMQBAHgCN+rI8mvvHBrYanrT1TH5kYFDiXF/9NSQc joL7MCm2zp/kaRmo+bHIvL1ifzsuUOT/036aFuykBz7R7893KsbjK6mpy7Bha0Lvi7ie goTVCj9rxxk8Ma5eItc6WZfEJ+9jWzpjOOZuQZ/oiTacU+HDTuwecaOq0gr5LXdh96DF TbU7hsQU36P9iS6TiKL3nkz5BEU6bF8vxhUODlVaZ1HjwG8bmQgtmqN+oTolk3U91CNF tSzA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z61si11776005ede.593.2020.08.17.10.30.34; Mon, 17 Aug 2020 10:30:57 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389765AbgHQR25 (ORCPT + 99 others); Mon, 17 Aug 2020 13:28:57 -0400 Received: from mx2.suse.de ([195.135.220.15]:50030 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389370AbgHQRIz (ORCPT ); Mon, 17 Aug 2020 13:08:55 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6BD24AC5E; Mon, 17 Aug 2020 17:09:19 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id F19311E12CB; Mon, 17 Aug 2020 19:08:53 +0200 (CEST) Date: Mon, 17 Aug 2020 19:08:53 +0200 From: Jan Kara To: Xianting Tian Cc: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] ext4: use kmemdup_nul() instead of kstrndup() Message-ID: <20200817170853.GC22500@quack2.suse.cz> References: <1596894336-49052-1-git-send-email-xianting_tian@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1596894336-49052-1-git-send-email-xianting_tian@126.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat 08-08-20 09:45:36, Xianting Tian wrote: > kmemdup_nul() is more efficient than kmemdup_nul() if > the size is known exactly. > > The description of kstrndup() already suggested: > Note: Use kmemdup_nul() instead if the size is known exactly. > > Signed-off-by: Xianting Tian Thanks for the patch but I think it is not ideal. The thing is that s_mount_opt is actually a NUL terminated string (we are just careful and don't rely on that to avoid problems when the fs is corrupted). So it is possibly shorter than those 64 bytes reserved for it in the superblock and using kmemdup_nul() will allocate and copy more memory than strictly necessary. Honza > --- > fs/ext4/super.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/ext4/super.c b/fs/ext4/super.c > index 330957e..be37556 100644 > --- a/fs/ext4/super.c > +++ b/fs/ext4/super.c > @@ -4016,7 +4016,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) > } > > if (sbi->s_es->s_mount_opts[0]) { > - char *s_mount_opts = kstrndup(sbi->s_es->s_mount_opts, > + char *s_mount_opts = kmemdup_nul(sbi->s_es->s_mount_opts, > sizeof(sbi->s_es->s_mount_opts), > GFP_KERNEL); > if (!s_mount_opts) > -- > 1.8.3.1 > -- Jan Kara SUSE Labs, CR