From patchwork Tue Sep 8 08:46:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 7139211 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9B1F99F1D5 for ; Tue, 8 Sep 2015 08:47:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DC1FE206F5 for ; Tue, 8 Sep 2015 08:47:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 09BFE206F4 for ; Tue, 8 Sep 2015 08:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753867AbbIHIrM (ORCPT ); Tue, 8 Sep 2015 04:47:12 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:5824 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753193AbbIHIrK (ORCPT ); Tue, 8 Sep 2015 04:47:10 -0400 Received: from 172.24.1.50 (EHLO szxeml433-hub.china.huawei.com) ([172.24.1.50]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CUN97125; Tue, 08 Sep 2015 16:46:58 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml433-hub.china.huawei.com (10.82.67.210) with Microsoft SMTP Server id 14.3.235.1; Tue, 8 Sep 2015 16:46:47 +0800 From: Sheng Yong To: Subject: [PATCH] btrfs: trival fix of __btrfs_set_acl error handling Date: Tue, 8 Sep 2015 08:46:42 +0000 Message-ID: <1441702002-109706-1-git-send-email-shengyong1@huawei.com> X-Mailer: git-send-email 1.8.3.4 MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 * If the allocation failed, don't free to free it, even though kfree allows to free a NULL pointer. * If posix_acl_to_xattr() failed, cleanup the allocation and return the error directly. Signed-off-by: Sheng Yong --- fs/btrfs/acl.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c index 9a0124a..6d01d09 100644 --- a/fs/btrfs/acl.c +++ b/fs/btrfs/acl.c @@ -103,18 +103,18 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans, if (acl) { size = posix_acl_xattr_size(acl->a_count); value = kmalloc(size, GFP_NOFS); - if (!value) { - ret = -ENOMEM; - goto out; - } + if (!value) + return -ENOMEM; ret = posix_acl_to_xattr(&init_user_ns, acl, value, size); - if (ret < 0) - goto out; + if (ret < 0) { + kfree(value); + return ret; + } } ret = __btrfs_setxattr(trans, inode, name, value, size, 0); -out: + kfree(value); if (!ret)