From patchwork Tue Aug 27 22:41:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Martins X-Patchwork-Id: 13780204 Received: from mail-oo1-f66.google.com (mail-oo1-f66.google.com [209.85.161.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 578A11D1F59 for ; Tue, 27 Aug 2024 22:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724798528; cv=none; b=EvNV2ls774u+4yBglzsJHaIFOCd8kfq8bnqwTV6YJYQPNmYe4S+fAEQh2fBZlhYqwXEivYTFLgTjAA+Oh27N338o9xvRO8wliYgL5b4yBVhahBVym8+u09WsIHcDyVOp5cvQfCNmYZKjjX2/kqGHKFmJUGELOp4PReMsNSHRj4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724798528; c=relaxed/simple; bh=n5LbD98MyNqaSQ4tcqe2s26KYYC32K2UmgcnC+bmjsQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iqfuy1boh5GIJQpO23h7bA+5mTVaLl4L2t7xHKefoR78gHMTTnSi1tizIxjT8QiJxoFDctrPJxYaP9gH+ezQyQIC11NPozOB47rTlBTIoiK2EQ9/efT/YT83DxlXOAaeg9Mh4lrTlyIaHCsHXzQQ+KtIFsp7eD6xMZyASPWltoE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WabaKWnn; arc=none smtp.client-ip=209.85.161.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WabaKWnn" Received: by mail-oo1-f66.google.com with SMTP id 006d021491bc7-5d5e97b8adbso4922654eaf.1 for ; Tue, 27 Aug 2024 15:42:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724798526; x=1725403326; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3+YxbXppocQU2l4EFQo704T8jvOcTqNyJkKqw3tNp1o=; b=WabaKWnnFgITjSFyJ8jxPwTWYHzvEkjlDO3ATYj54eEmmpBQpPRRnifJcGuYT62crI lPHGt+o2Hz7uiwoHhFkQkvu1L7RngWGOlANWaS7OSsUajewZOYYd5XEH1NxrayC4vtRQ IUwO7QoG8782+vJ4vI0HwVViJ0ip5gH5x0fBV8RctPOK5BnHMjID2/NsIqPGs+djN1Wu 3AxtL1HNfMaDTqYcKnHryQ6mK7EIRcpSxHqJmChd4k752NYCJVjsPtdKsa+jEZMmQ4fI eBw7+8MsQgY088yaIoLqJuzurRKGOW5R8KkOAowSWN127GRreJRfxUuuu+Hqxgf1YmYe hRPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724798526; x=1725403326; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3+YxbXppocQU2l4EFQo704T8jvOcTqNyJkKqw3tNp1o=; b=KdP9ydoFRVM2AWdIYEVZogObEJBORgy2AsOClCkR1WbSdfs280f8sIBaQvHgKdT2mM FOBvdKEvjf4iDafIB6p9rFtWL8b3/f1kUVm4TYc6vkRzOzfEFbWumi4xVMV6VK/8rMiK uQ+QAPkUahDb5Fn24iitTFiSZbsM9Dlqr0wxlPsBVOXWEU5lQXH5SgrIQydhb3pGqsk5 D+Fw3A+zjwgXt2p+qqEsKJNMadnbw5ip4tzP0eU0G9SPRChR2OIJo+OaSWEPrb5ZYiLx LPVCKxclAVEsCcAUoMZMeNeVjfU7CV2mWTupxWti67FIcc42sQpYF/WURCESWuXYOqpT saMw== X-Gm-Message-State: AOJu0YyWw51p42XWFl75gVmU//tyepVya/YuJGTKuZKT+enlCYw0Mvb9 GLCYsRM+xAut466Hrg3FSRTSPLzLUow4DyrWOdyhcTRfGFojFFQBy0oH61kt X-Google-Smtp-Source: AGHT+IE/3sPBoyZhbzBRYNCDJ0XPQpT1eKnjPdiAe92XgrM5wAavu+lrNkTmVWguTlZB+mR4sEmVeA== X-Received: by 2002:a4a:ec41:0:b0:5c6:5f2d:8430 with SMTP id 006d021491bc7-5dcc5ec241amr15667420eaf.2.1724798526108; Tue, 27 Aug 2024 15:42:06 -0700 (PDT) Received: from localhost (fwdproxy-eag-115.fbsv.net. [2a03:2880:3ff:73::face:b00c]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5dcb5de7c83sm2699104eaf.14.2024.08.27.15.42.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 15:42:05 -0700 (PDT) From: Leo Martins To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 1/3] btrfs: DEFINE_FREE for btrfs_free_path Date: Tue, 27 Aug 2024 15:41:31 -0700 Message-ID: <02d02a785f1d71b41104c48fb38eee7488a672c6.1724792563.git.loemra.dev@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a DEFINE_FREE for btrfs_free_path. This defines a function that can be called using the __free attribute. Defined a macro BTRFS_PATH_AUTO_FREE to make the declaration of an auto freeing path very clear. Signed-off-by: Leo Martins --- fs/btrfs/ctree.c | 2 +- fs/btrfs/ctree.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 451203055bbfb..f0bdea206d672 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -196,7 +196,7 @@ struct btrfs_path *btrfs_alloc_path(void) /* this also releases the path */ void btrfs_free_path(struct btrfs_path *p) { - if (!p) + if (IS_ERR_OR_NULL(p)) return; btrfs_release_path(p); kmem_cache_free(btrfs_path_cachep, p); diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 75fa563e4cacb..fbf1f8644faea 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -6,6 +6,7 @@ #ifndef BTRFS_CTREE_H #define BTRFS_CTREE_H +#include "linux/cleanup.h" #include #include #include @@ -599,6 +600,9 @@ int btrfs_search_slot_for_read(struct btrfs_root *root, void btrfs_release_path(struct btrfs_path *p); struct btrfs_path *btrfs_alloc_path(void); void btrfs_free_path(struct btrfs_path *p); +DEFINE_FREE(btrfs_free_path, struct btrfs_path *, btrfs_free_path(_T)) +#define BTRFS_PATH_AUTO_FREE(path_name) \ + struct btrfs_path *path_name __free(btrfs_free_path) = NULL; int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path, int slot, int nr); From patchwork Tue Aug 27 22:41:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Martins X-Patchwork-Id: 13780205 Received: from mail-oi1-f195.google.com (mail-oi1-f195.google.com [209.85.167.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1B901D4165 for ; Tue, 27 Aug 2024 22:42:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724798530; cv=none; b=OknGhPyFOt8xL0dPP7P8phSePRJwqUqfInNzE1yRkv69bviQ2As7159t4GTwiKu6gKPDYr2W3rFjOe50ApFmMHAN36KdBOgwMVRyilc8Z5T4SKS+VYIf8ANcwYrwwDd9/o4v4lFkQzmqMsHjwKPiD8zrTfYg2sKLMnuA/GeVAvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724798530; c=relaxed/simple; bh=Mj9L80TmcUqhnBNXpA+4LISewFqhqg8Wrv8MloGzFN0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lSL/ljDE6rPT+gsEzX7qqAzKTR5nxdsWRXUHbY2CIvDvQId1Oguv3xqzxV/29qEDbDG5IOtst6goCWP1/Jq+HZYRkG0hEzV3oibbx+Odv20h0q1GzvrPUDh2ePnzXoFZ4ilzDa0CGGcQzdOZgyd9IQRL5eTRdBam4ZyH/PQNmK8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RBbR5FNU; arc=none smtp.client-ip=209.85.167.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RBbR5FNU" Received: by mail-oi1-f195.google.com with SMTP id 5614622812f47-3db51133978so786600b6e.3 for ; Tue, 27 Aug 2024 15:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724798528; x=1725403328; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=j1cQ+5UH/9MovsoNRkqll87lIGd/AatsUKrccEw5cJU=; b=RBbR5FNUUzdVhVcTopZyiBfjFpMTVQ3Pe/BXU1IE/OOvxSnl7oBSWU3c2Qpy4ib/iX b08V3eeGrO3+ixAFlWsEqiBg8dumQGns9KGGWEUNQz6F5ygl+f9vALvAzrDkWWzzMv5u 3OYGF+HbO65YyzvujdWoBfh675+TddLWX7OxtGfFYC+FK05zHyPP0Vkn7tlKcuCLOurj fNH5/g8in3EIuwDywRlNKx64BDTUaOqw4V8Dao5m0RNf1r77Qcvoce6JY3Ij+O3FGgUX SDU0lmRNDbktlrrnyHcxkf9/YMPRJTF7TiZft/5O01MWOFpz04FozpLk/o8OPwtbVKhy qKNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724798528; x=1725403328; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j1cQ+5UH/9MovsoNRkqll87lIGd/AatsUKrccEw5cJU=; b=Vvxbu8IPhsWIM38UQIofGRK6KK0d7xqN5tIAdGZz8/KLVmyibdNqMhiOXvbipT+nUT /wJ2t56RCmBkccFZYzV75oScvy/E1yCzwgp9j4VYNofq58CTWj/FQKnUI71ScsxksI27 /ZQ6f1XW43pPZmuz+T5z7iFwg9T8Wl5SymMOC0dMy+lG3nQ8EP6ShIWwDv1XbMVjF37W L7BgiduqrUK1U4oqJFVM2VWbD7D+zMKNPalAiq9X5BviqyqUVXa0R9ENZ5GQcMGWgoqP yUxHq/C39zEf268Or2LB8qISWaHYq/r/7XvAhVZGlG/aN5McFHIqPTOFmrJjRglTynxt uF5g== X-Gm-Message-State: AOJu0YxQhZEi3bd9DvV0UVWFzB6lweKsdjNsQH/xhjighyuvu4dgQJOZ NwS6AavDnSn1U/vmvKqXqahUStxYRgfiXhfmAr3w23ph/KSj2aDUXkPZEXDY X-Google-Smtp-Source: AGHT+IHnLT2V81YXoYGSfU2+88HaY0Msk5q3IRRPAMnd5i2ZH8BgRhQNmAGRusMqGhdEp+VPEl32SQ== X-Received: by 2002:a05:6808:1296:b0:3d9:2c62:72b4 with SMTP id 5614622812f47-3deffb4925dmr193587b6e.19.1724798527648; Tue, 27 Aug 2024 15:42:07 -0700 (PDT) Received: from localhost (fwdproxy-eag-008.fbsv.net. [2a03:2880:3ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de2254ec26sm2755474b6e.18.2024.08.27.15.42.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 15:42:07 -0700 (PDT) From: Leo Martins To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 2/3] btrfs: BTRFS_PATH_AUTO_FREE in zoned.c Date: Tue, 27 Aug 2024 15:41:32 -0700 Message-ID: <0843271a3901ff3f52658f1a7a4382f3d8263b88.1724792563.git.loemra.dev@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add automatic path freeing in zoned.c, the examples here are both fairly trivial with one exit path and only btrfs_free_path cleanup. Signed-off-by: Leo Martins --- fs/btrfs/zoned.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 66f63e82af793..158bb0b708805 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -287,7 +287,7 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos, /* The emulated zone size is determined from the size of device extent */ static int calculate_emulated_zone_size(struct btrfs_fs_info *fs_info) { - struct btrfs_path *path; + BTRFS_PATH_AUTO_FREE(path); struct btrfs_root *root = fs_info->dev_root; struct btrfs_key key; struct extent_buffer *leaf; @@ -304,28 +304,21 @@ static int calculate_emulated_zone_size(struct btrfs_fs_info *fs_info) ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); if (ret < 0) - goto out; + return ret; if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) { ret = btrfs_next_leaf(root, path); if (ret < 0) - goto out; + return ret; /* No dev extents at all? Not good */ - if (ret > 0) { - ret = -EUCLEAN; - goto out; - } + if (ret > 0) + return -EUCLEAN; } leaf = path->nodes[0]; dext = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_extent); fs_info->zone_size = btrfs_dev_extent_length(leaf, dext); - ret = 0; - -out: - btrfs_free_path(path); - - return ret; + return 0; } int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info) @@ -1211,7 +1204,7 @@ static int calculate_alloc_pointer(struct btrfs_block_group *cache, { struct btrfs_fs_info *fs_info = cache->fs_info; struct btrfs_root *root; - struct btrfs_path *path; + BTRFS_PATH_AUTO_FREE(path); struct btrfs_key key; struct btrfs_key found_key; int ret; @@ -1246,7 +1239,7 @@ static int calculate_alloc_pointer(struct btrfs_block_group *cache, if (!ret) ret = -EUCLEAN; if (ret < 0) - goto out; + return ret; ret = btrfs_previous_extent_item(root, path, cache->start); if (ret) { @@ -1254,7 +1247,7 @@ static int calculate_alloc_pointer(struct btrfs_block_group *cache, ret = 0; *offset_ret = 0; } - goto out; + return ret; } btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]); @@ -1266,15 +1259,10 @@ static int calculate_alloc_pointer(struct btrfs_block_group *cache, if (!(found_key.objectid >= cache->start && found_key.objectid + length <= cache->start + cache->length)) { - ret = -EUCLEAN; - goto out; + return -EUCLEAN; } *offset_ret = found_key.objectid + length - cache->start; - ret = 0; - -out: - btrfs_free_path(path); - return ret; + return 0; } struct zone_info { From patchwork Tue Aug 27 22:41:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Martins X-Patchwork-Id: 13780206 Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E82B1D4176 for ; Tue, 27 Aug 2024 22:42:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.67 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724798531; cv=none; b=ECOpl06nGTIHSVafmmWVAjeO1Kn6b42zALDHFEwRAZ3veYACpxwBurH8u3g/HzcrBeQkqnGabQ3Xw/GhU2yg8T5iwFoA0igRRY+wxN8EgEQ6HoL1db2nzkW0revi0eopQAffk9JVRdGBJGZB1yQ9TLCnRGkgA5OsSuWZOc+izPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724798531; c=relaxed/simple; bh=6NTy+cJ+N43dWLYCSyY6RnjCrKuROVBm/lXfHsAcK3g=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NkzWFQrT/ZmmniNkAYwRLV9Xp5eQfs3K0r5EeptAstkRBkjlCvXOBEEEmqTWeMtFVRXcw/xB0tLvLFxJRUhbM3zr/87X13L6jX6BeSKm/Pm7PRsJ7ib0WUVcpYIhMtk9wBP8usG9Vnn0HCUHGXcGLiKkRgYyEePHb1i+hs3/t2E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iOfoAFqj; arc=none smtp.client-ip=209.85.210.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iOfoAFqj" Received: by mail-ot1-f67.google.com with SMTP id 46e09a7af769-709345dd01dso18374a34.0 for ; Tue, 27 Aug 2024 15:42:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724798529; x=1725403329; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3Np7nLR6uDtfwcAnCN5f5QshCByGw+rq1Q6DA5mSgak=; b=iOfoAFqj1iLuau4aPMT7TjXyUCj3PUo61kAAq7e2rFE5DPTcNNBQSfu8i15ZdCSyUV aDglb6uIzTqZqoivlrgr9minnQdzZeO0Dfbt+4J8E+Qlaua5KaNYaJQRI3dG9zQUxw63 QmgXHb11N+H8NGeg/C6tbt/Dvj/Ajtb/yY199K3WV4akN4JCXGoVDRH+gwyFmZoDWCPI iZNzxuTj583fpzivNkjuKxw55QCEvxWZjzdxoP2qJaL9lh1Y+U6JM1FmardUwij5NjV6 43c7A2FqAPoonNwTUfxrUUmx7CPQyHwc7Q4doY20RkIrdEMLVSoTTaTTOs8ghLSmqACH ss9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724798529; x=1725403329; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3Np7nLR6uDtfwcAnCN5f5QshCByGw+rq1Q6DA5mSgak=; b=icBI8BS6m/FQ+zy//wdT/gMKw1cMjw0tHLIU/W+8OZfqxSYO3IMEbDn0N21p+IJpff IYHns1HV9BG19T8O1yCoQkSYRgcUdiMrDQ9P1FQ05b3ZT8+NpP5Zo/TnLYB0vcbXhquW ocwZZtB8qe0Ipl8yYGsbLmqdRs+hlktCDXJfmvRIzApylwyVnFep9TgFca1GK9N99O+6 AvKOXdyftcn1EVqVJIdwY1RrFBl5Q5BmfBm2XdWBsXB0PDP+ydyg0RXZyNNzclKLQJQr cLRPIPg8k1zyrBQxhFuspHOHWVzMZwFTTo5/LeMKxdOAz73ZmZLWNOZOMqCccZDJzOV2 IFMw== X-Gm-Message-State: AOJu0YxvZZaN1LKGhA5Xjkjk0HuYJrI8W6xTcyjuAijcP4jjGhvCQ/62 ESDcguqjJ0dd9IKpEbJ1ugUFYPI7fhQFtLUwy054DddbB/AktS85TdLAksGh X-Google-Smtp-Source: AGHT+IETUMiFDVnWgma/Bjtw5dI7d9HxTOPcg5cd/iGBN3sUhzwvkrNeKNtSauFpIXNx30qkywBdRQ== X-Received: by 2002:a05:6830:720d:b0:704:4bb7:c99a with SMTP id 46e09a7af769-70f530fd386mr136936a34.0.1724798529343; Tue, 27 Aug 2024 15:42:09 -0700 (PDT) Received: from localhost (fwdproxy-eag-003.fbsv.net. [2a03:2880:3ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70e03ab2a50sm2597017a34.35.2024.08.27.15.42.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 15:42:09 -0700 (PDT) From: Leo Martins To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 3/3] btrfs: BTRFS_PATH_AUTO_FREE in orphan.c Date: Tue, 27 Aug 2024 15:41:33 -0700 Message-ID: X-Mailer: git-send-email 2.43.5 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add automatic path freeing in orphan.c, the examples here are both fairly trivial with one exit path and only btrfs_free_path cleanup. Signed-off-by: Leo Martins --- fs/btrfs/orphan.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/orphan.c b/fs/btrfs/orphan.c index 6195a2215b8fe..696dbaf26af52 100644 --- a/fs/btrfs/orphan.c +++ b/fs/btrfs/orphan.c @@ -9,7 +9,7 @@ int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 offset) { - struct btrfs_path *path; + BTRFS_PATH_AUTO_FREE(path); struct btrfs_key key; int ret = 0; @@ -23,14 +23,13 @@ int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans, ret = btrfs_insert_empty_item(trans, root, path, &key, 0); - btrfs_free_path(path); return ret; } int btrfs_del_orphan_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 offset) { - struct btrfs_path *path; + BTRFS_PATH_AUTO_FREE(path); struct btrfs_key key; int ret = 0; @@ -44,15 +43,9 @@ int btrfs_del_orphan_item(struct btrfs_trans_handle *trans, ret = btrfs_search_slot(trans, root, &key, path, -1, 1); if (ret < 0) - goto out; - if (ret) { /* JDM: Really? */ - ret = -ENOENT; - goto out; - } + return ret; + if (ret) + return -ENOENT; - ret = btrfs_del_item(trans, root, path); - -out: - btrfs_free_path(path); - return ret; + return btrfs_del_item(trans, root, path); }