From patchwork Tue Aug 27 19:08:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Martins X-Patchwork-Id: 13780080 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 8849B1CFECE for ; Tue, 27 Aug 2024 19:09:49 +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=1724785791; cv=none; b=EnmmvTt7rhOPV8AjiWBxgddsG12wnYem0tL/aCHe26opCgDVyTCge1ElGbfG1p3AMhmuwKr1JjuDXHGH9zBO5Wlt/CrGLxmXq+XNxx2g7AWwiunsiV1PxcbScqlYJPSP3CO4pZ2ZSEyDxiAlaNcJ/IBAlOCYSeOlOI4MY5ekD2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724785791; c=relaxed/simple; bh=ckxYPzrPQlT9vM2ZhhYrmMzB2ZLZnvY6nV1orUAS1kc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GH+eD4D1ebn2NJtlRvzFHAIYcWeSVYzQzq9dRQD+UgdBmuNoKEQ5caOC0LaDsU3ksLDuIaBPucGVheo4kfOR5Wg1aGYVhkbhRXDSTCOIdI0KlgtiyPnkIX3dKBVgDkmQxms3hWulSSdw7ilWEJC/7mgW559JLj2RXMY/WtJuq/U= 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=PWAwSRtM; 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="PWAwSRtM" Received: by mail-oi1-f195.google.com with SMTP id 5614622812f47-3db51133978so675583b6e.3 for ; Tue, 27 Aug 2024 12:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724785788; x=1725390588; 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=XaakoZrOtarCzY3JxedCLrPGLwHUEONAWAetO9xbe1g=; b=PWAwSRtMCQuyuTQxIxEWoUTEEMM06NJXsrcxscbxHa/83FA6qiw/j2sgmWLNYaHZ0/ AjEJAS9FGqj4uG6gypif3tUcytt4zLoQM+Q3Mb6XkKs/8zCi7UjbI1JwUPxBgqCMdH+G CVqs8whJXWRDVycnLNrfQA3NRgJzNJSIOf7pp4riEGR0CI1iVyLYPiK5REF0IvM6nYZ6 fanZ171Jn+IswK2MhaSTGwH+zhawCHZb11v77uojoZyzrtc3oxUj4SS1hsoqfTs/nzdx 9VLqRJTQ5+/N4dbzAESycF4HCpF2DMyiBWgfZGN+Re7yOi42JNhGSOZglGnBdBRQOPaV fUhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724785788; x=1725390588; 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=XaakoZrOtarCzY3JxedCLrPGLwHUEONAWAetO9xbe1g=; b=tExxEGrUNonb1uiqJLNvQ/Ja+ETwPNY3QtYH6wUochnrqbu0oQNSQDJqVNTWee8H2o nP1baPhJpGK9wLENRUWmtRCGS3+Y0IWnetstAEZLbj2biEt4G3MzCGTKp7t61hUo2nGk E604oGfeD8ypDe42cxuBYmUNJy4cnAkAssolcByaAym5FGmopitiSLngcbkicUBpvJOt 28OLZpun6GpkwMMcruhm2mzHlCLwrdUUVeVvyEOlryPVlHN7/5RaMap1nK5BxrTdJ9ee R2WSNpVtSnJBgkvtyYBiEYpSqlgybT+rs64iQbYJ/bkr9SSLxPmRVsa9BFLnuLf6l0/3 DyUg== X-Gm-Message-State: AOJu0YwLlolCVhDmIMw4rUCnBngIf8zqmoOAKz8k6Wl7DSxaZNpROCS5 93Y+018aNZ+c7BAj15tHZmCt+svX8+semxIKieANP00SIS6D3eO4wpV5g/9K X-Google-Smtp-Source: AGHT+IEX7B9gQFnWN3biJR4a7lNuEo8XHUMKPw//m2QJ/CNo1xTKWk8RH7+Adqw84XxTeIKhcSYWCw== X-Received: by 2002:a05:6808:3c93:b0:3d9:4163:654f with SMTP id 5614622812f47-3def3faa314mr4399503b6e.32.1724785788361; Tue, 27 Aug 2024 12:09:48 -0700 (PDT) Received: from localhost (fwdproxy-eag-003.fbsv.net. [2a03:2880:3ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225c95c3sm2672159b6e.46.2024.08.27.12.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 12:09:48 -0700 (PDT) From: Leo Martins To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v2 1/3] btrfs: DEFINE_FREE for btrfs_free_path Date: Tue, 27 Aug 2024 12:08:43 -0700 Message-ID: <6951e579322f1389bcc02de692a696880edb2a7e.1724785204.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. --- 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..babc86af564a2 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 *, if (!IS_ERR_OR_NULL(_T)) 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 19:08:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Martins X-Patchwork-Id: 13780081 Received: from mail-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) (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 1A1211D3181 for ; Tue, 27 Aug 2024 19:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724785792; cv=none; b=hcUgrMtBrEmcCrGehISmTf9xAQmlwUC9+SJQRD/3FPpGvEcEoyxp2oFp1rBbp/htuq9xd6UXhzq2jFUJ87gdek+cKwkBgFDLZl3wWQkU6RYTsEhBOoq9vS+ZT+SXcpHCuzovo9UhcPlhcZTAPFHcFrciSUaSzA3vdXVa5i6AvSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724785792; c=relaxed/simple; bh=VTVbdeZ7m/yShOS/JfSfvNtOAHt5e3BhJfk96jpX39I=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S2BmlTzqy9R4keLOWvclnRHnG8/qZRjgi91IwIkKmBje4gCBsBq9ndBJbJLHbT61KapsWe4SKHPprH482DsEfE5hfyRf/Q6DWY4OfPwGMWxVhymxXWViUg92sUH8447YTWAg3u7TiOVKeeEYpdzt9X+hFn6LSorWjURzHpehwM8= 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=knd1QM+I; arc=none smtp.client-ip=209.85.210.65 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="knd1QM+I" Received: by mail-ot1-f65.google.com with SMTP id 46e09a7af769-7095bfd6346so5228296a34.0 for ; Tue, 27 Aug 2024 12:09:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724785790; x=1725390590; 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=TgCXovq2H9JnOdzJX6Nr9BDbcORhNZ6yZsuhVd1ZMCI=; b=knd1QM+Icg4KvX5A2OEzObkwpf85ao0pvyGFYpPQ1f6GyZEiT/PsXkQZwBmNlne0u8 vyjVGBf4ryTWadLqwnOELYCztk/JB2a+MMLic1dy3y9JrrJjA8cbcioSyFsdTgk3L5l+ dWmuNf3Syvi4w3rsHtMjZL/YCaGCQn3tupwQP0wUTPwdgdEkfylPILHR4tJs++NxzS8A TOAYhPBzYGO8r3KRazHm+BIgKxgz5ZcgLXFG91cViGZiDYVGiR0Vt7ZfADvbv/tP2ZNh /H/svRjIWFj6lH6CSqDrv5mJJRo4SYjGWnxleDr5mS1J6LT4yxLcQHkc77EZlcEXycf9 hong== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724785790; x=1725390590; 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=TgCXovq2H9JnOdzJX6Nr9BDbcORhNZ6yZsuhVd1ZMCI=; b=rMwFhiLRsTI/O4c7UvJhIw9RkhA5bdma9XBTChArHOFH5uIO65rPTS91hx0H7tcDw4 5DMKinSTI6Q0hoR0Xj3oY1WyWcw6t40jbaCbWUYNOvHL5E52M+Tk5o/VAMrgGqFd7y6c lO9XT+YThdYhn32aSIljTY3dQfkJnTZdjKL0z7QhbzJQMD3rodY8BXIgZETsuTU4F2fj SaR3RjNSGAFRCotW7J7UqXOL3eqb41+JWmKBy7xgSGaDae2QzwftMNYDWkNhcKH5ViGm xM0OQgfr8O9oBc0G3EsxB+thRa6Ke0DDGa28YKZKR7B6Z/DxqOWb0C4PRN0OCDeHd34Q KT4g== X-Gm-Message-State: AOJu0YwRUej4VeyaF5W987xOI5ot/Pn3ZoCuvnOc4dCnrop87GSVkM1W uXNFjl/exOEsbAzuPYm6NJ+7VbAYdqtd7msanSO2mR7VsXmynFWqXTR95PhF X-Google-Smtp-Source: AGHT+IHzeJnwNclWgdQKQYjzUIqHmGx5/n81vEeGqjr57ZcRIfj9NCSfLNn78np1Xs4xvP2gMNxfIw== X-Received: by 2002:a05:6830:63ce:b0:703:5e45:f991 with SMTP id 46e09a7af769-70e0ec200c3mr14806339a34.31.1724785789782; Tue, 27 Aug 2024 12:09:49 -0700 (PDT) Received: from localhost (fwdproxy-eag-004.fbsv.net. [2a03:2880:3ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70e03ab6bfdsm2478503a34.37.2024.08.27.12.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 12:09:49 -0700 (PDT) From: Leo Martins To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v2 2/3] btrfs: BTRFS_PATH_AUTO_FREE in zoned.c Date: Tue, 27 Aug 2024 12:08:44 -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 zoned.c, the examples here are both fairly trivial with one exit path and the only cleanup is btrfs_free_path. --- 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 19:08:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Martins X-Patchwork-Id: 13780082 Received: from mail-oa1-f67.google.com (mail-oa1-f67.google.com [209.85.160.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 AABFF1D2F59 for ; Tue, 27 Aug 2024 19:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.67 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724785794; cv=none; b=CkYMLXg3XVGgYmBAQiAVPu9YYVE6mIRIloYmzLqoMteNLrdxM6cmqQmZr7fu9/Acb/FWTB2bdtTcmmgNDjst0LK2YYPfTCfAurjC9A6UqAvFAxFrXhtJ7Dc3X/V3J0nvzTVhimoF6NXNyIa6o7mDzsBjizqCJjs5A5K4uzMGEQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724785794; c=relaxed/simple; bh=p0R3WE1n5q3lMm+T+FQKxcinl39PlriMO7ne1Qrrfjs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sBdXQkdS74emuusTkvp0lC+1YRN7kIK6UmFXMOG73Nt86/TtKE6ZiwoMHJoIguzW70u4Gpu32uRYsGFjOvA94ujTd1tDmlnxmmEC1NOwrgv1/57kpX9LomrCjFti3iOCthVejeBS01uGsY4ZHkWPcvnks5s/x5QWhccjToHMsYk= 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=KpANlsPn; arc=none smtp.client-ip=209.85.160.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="KpANlsPn" Received: by mail-oa1-f67.google.com with SMTP id 586e51a60fabf-273cf2dbf7dso3909245fac.1 for ; Tue, 27 Aug 2024 12:09:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724785791; x=1725390591; 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=r6s4Luh0slZ6wNtyYxvhQo3FjBvwG7y7hvkIDgghHWk=; b=KpANlsPnhq0zSSV6YzTkASNmNri9yp/Krqgk8ypzYhEsBjnBK27KOIn8avjphqbudx 0TUAh30AOlL/ebZLTSZOm56dTkmI09d2y5WLoG3p7Vui0xiGXP58WUQo73/426K6OLhx cTX51BmA+lHwOdMnYdd1wjnwb/f7KIS0EIxHO1XI99J6V1tCPGdSsMeH7DhdSmZH+/fX YbWDl2WNCdSJwhp9aWbHw9AUK/RNkb8IGp6vtUcdXVo/cfCSUeAzMrKJ5bz2S+4O2AZP lkRRewPOMrJKUkv0ML13l85QMvBmgrglFC7phnBBAhxwJNKQmlXmKPxnA6yeQ8dtqYBd jwxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724785791; x=1725390591; 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=r6s4Luh0slZ6wNtyYxvhQo3FjBvwG7y7hvkIDgghHWk=; b=p6rt7HI57Yy4Su0Y/uI83SZRNZ4Co9auocqFMH+PqmusrDhiF8xHM3BRY0EwXBVWo7 ZSTFZPYN4HgO5Dxokf3gcj+iFd13fjwMfNETdoRPsMpV9LlhvYC2q9fOSqNYBGn0EdLu 96mQbIBtk41rImpoQunObYt1jRsXEXsfegT5G98Lq9/HtaqZjP4/3ZI5lpOQbmr/BobT 0T5y4h9/wKOzZ5rqdMAuwJj93ATQuaXN2r+LfLlYEzdW2D2kRE6johxg5mrtgXeC7mfx Fz5coSsuwe+36X/7SK3KxI0pjACqxG/v/7nSiOIaanEzjHk9n3JgnWBDb5SI1VoDMU8p UzfA== X-Gm-Message-State: AOJu0YxtLOqj2EwcXnZ4HbwPFSmnTt4PXwSG2MoccxNtPhPBIu8Z6QfF tPqmuQPxbvNBM5v2k1kJ1AbZTAaTN+WJztEKQWprvff7BjbgZZ3RO3RleNx/ X-Google-Smtp-Source: AGHT+IFs9St8I+NKSuD6cQgJQa+QMWnL5whsRNg21bPB4v/GYhbFKVIOq9NeuE5ndXgAyXMOG2vacw== X-Received: by 2002:a05:6870:2250:b0:261:142:7b95 with SMTP id 586e51a60fabf-273e654b961mr15939154fac.25.1724785791414; Tue, 27 Aug 2024 12:09:51 -0700 (PDT) Received: from localhost (fwdproxy-eag-003.fbsv.net. [2a03:2880:3ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-273ce9969besm3257884fac.7.2024.08.27.12.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 12:09:51 -0700 (PDT) From: Leo Martins To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v2 3/3] btrfs: BTRFS_PATH_AUTO_FREE in orphan.c Date: Tue, 27 Aug 2024 12:08:45 -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. This is the original example I sent with only one exit point that just frees the path. --- 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); }