From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com ([209.132.183.28]:32290 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753966AbaETQlO (ORCPT ); Tue, 20 May 2014 12:41:14 -0400 Message-ID: <537B85A5.9030406@redhat.com> Date: Tue, 20 May 2014 11:41:09 -0500 From: Eric Sandeen MIME-Version: 1.0 To: dsterba@suse.cz, Anand Jain , linux-btrfs@vger.kernel.org, rm@romanrm.net Subject: Re: [PATCH 1/2 v2] btrfs: label should not contain return char References: <1400519071-5580-1-git-send-email-anand.jain@oracle.com> <1400567808-9494-1-git-send-email-anand.jain@oracle.com> <20140520163352.GL31608@twin.jikos.cz> In-Reply-To: <20140520163352.GL31608@twin.jikos.cz> Content-Type: text/plain; charset=ISO-8859-1 Sender: linux-btrfs-owner@vger.kernel.org List-ID: On 5/20/14, 11:33 AM, David Sterba wrote: > On Tue, May 20, 2014 at 02:36:48PM +0800, Anand Jain wrote: >> From: Anand Jain >> >> generally if you use >> echo "test" > /sys/fs/btrfs//label >> it would introduce return char at the end and it can not >> be part of the label. The correct command is >> echo -n "test" > /sys/fs/btrfs//label >> >> This patch will check for this user error >> >> Signed-off-by: Anand Jain >> --- >> v2: accepts review comments. Thanks Eric and Roman >> >> fs/btrfs/sysfs.c | 20 +++++++++++++++++--- >> 1 files changed, 17 insertions(+), 3 deletions(-) >> >> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c >> index c5eb214..ca63fcd 100644 >> --- a/fs/btrfs/sysfs.c >> +++ b/fs/btrfs/sysfs.c >> @@ -373,22 +373,36 @@ static ssize_t btrfs_label_store(struct kobject *kobj, >> struct btrfs_trans_handle *trans; >> struct btrfs_root *root = fs_info->fs_root; >> int ret; >> + char *label; >> + char *pos; >> >> - if (len >= BTRFS_LABEL_SIZE) { >> + label = kzalloc(len, GFP_NOFS); > > You can avoid allocating the buffer entirely: > > - search for '\n', if found, use only that amount of bytes > - check for maximum size, copy to label if ok that's probably better than my strstrip idea, which requires writable memory. Odds of finding \t are slim. ;) -Eric