From patchwork Tue May 20 06:36:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 4207411 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3E06CBEEAB for ; Tue, 20 May 2014 06:34:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 75DD52021A for ; Tue, 20 May 2014 06:34:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 978CF201E4 for ; Tue, 20 May 2014 06:34:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751461AbaETGeG (ORCPT ); Tue, 20 May 2014 02:34:06 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:43238 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751411AbaETGeF (ORCPT ); Tue, 20 May 2014 02:34:05 -0400 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s4K6Xvtc031959 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 20 May 2014 06:33:58 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by ucsinet22.oracle.com (8.14.5+Sun/8.14.5) with ESMTP id s4K6XtUh025962 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 20 May 2014 06:33:56 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s4K6Xtwx017987; Tue, 20 May 2014 06:33:55 GMT Received: from wish.sg.oracle.com (/10.186.101.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 19 May 2014 23:33:54 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: sandeen@redhat.com, rm@romanrm.net Subject: [PATCH 1/2 v2] btrfs: label should not contain return char Date: Tue, 20 May 2014 14:36:48 +0800 Message-Id: <1400567808-9494-1-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1400519071-5580-1-git-send-email-anand.jain@oracle.com> References: <1400519071-5580-1-git-send-email-anand.jain@oracle.com> X-Source-IP: ucsinet22.oracle.com [156.151.31.94] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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); + if (!label) + return -ENOMEM; + + memcpy(label, buf, len); + if ((pos = strchr(label, '\n'))) + *pos = '\0'; + + if (strlen(label) >= BTRFS_LABEL_SIZE) { pr_err("BTRFS: unable to set label with more than %d bytes\n", BTRFS_LABEL_SIZE - 1); + kfree(label); return -EINVAL; } trans = btrfs_start_transaction(root, 0); - if (IS_ERR(trans)) + if (IS_ERR(trans)) { + kfree(label); return PTR_ERR(trans); + } spin_lock(&root->fs_info->super_lock); - strcpy(fs_info->super_copy->label, buf); + strcpy(fs_info->super_copy->label, label); spin_unlock(&root->fs_info->super_lock); ret = btrfs_commit_transaction(trans, root); + kfree(label); if (!ret) return len;