From: David Sterba <dsterba@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>
Subject: [PATCH 08/10] btrfs: simplify conditions in btrfs_free_chunk_map()
Date: Mon, 19 Feb 2024 12:13:04 +0100 [thread overview]
Message-ID: <cd9ae501762221ffca5408ffb59f1a3b990de14e.1708339010.git.dsterba@suse.com> (raw)
In-Reply-To: <cover.1708339010.git.dsterba@suse.com>
The helper is simple enough for inlining, we can further simplify it by
removing the check for map pointer validity. After this patch all
callers always pass a valid pointer.
The changes to achieve this:
- in verify_one_dev_extent() return and don't jump to the out label
that could potentially pass a NULL pointer to btrfs_free_chunk_map
- in btrfs_load_block_group_zone_info() add a label that specifically
clears the map and does not go through label out that could encounter
a NULL pointer in cache->physical_map
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/volumes.c | 3 +--
fs/btrfs/volumes.h | 2 +-
fs/btrfs/zoned.c | 3 ++-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 752144a31d79..55b91807aba4 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -7979,8 +7979,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
btrfs_err(fs_info,
"dev extent physical offset %llu on devid %llu doesn't have corresponding chunk",
physical_offset, devid);
- ret = -EUCLEAN;
- goto out;
+ return -EUCLEAN;
}
stripe_len = btrfs_calc_stripe_length(map);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 21d4de0e3f1f..ce1aa7684c74 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -566,7 +566,7 @@ struct btrfs_chunk_map {
static inline void btrfs_free_chunk_map(struct btrfs_chunk_map *map)
{
- if (map && refcount_dec_and_test(&map->refs)) {
+ if (refcount_dec_and_test(&map->refs)) {
ASSERT(RB_EMPTY_NODE(&map->rb_node));
kfree(map);
}
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 3317bebfca95..b9346ca82c47 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1564,7 +1564,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
cache->physical_map = btrfs_clone_chunk_map(map, GFP_NOFS);
if (!cache->physical_map) {
ret = -ENOMEM;
- goto out;
+ goto out_free_map;
}
zone_info = kcalloc(map->num_stripes, sizeof(*zone_info), GFP_NOFS);
@@ -1677,6 +1677,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
}
bitmap_free(active);
kfree(zone_info);
+out_free_map:
btrfs_free_chunk_map(map);
return ret;
--
2.42.1
next prev parent reply other threads:[~2024-02-19 11:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-19 11:12 [PATCH 00/10] Static inline cleanups David Sterba
2024-02-19 11:12 ` [PATCH 01/10] btrfs: move balance args conversion helpers to volumes.c David Sterba
2024-02-19 11:12 ` [PATCH 02/10] btrfs: open code btrfs_backref_iter_free() David Sterba
2024-02-19 11:12 ` [PATCH 03/10] btrfs: open code btrfs_backref_get_eb() David Sterba
2024-02-19 11:12 ` [PATCH 04/10] btrfs: uninline some static inline helpers from backref.h David Sterba
2024-02-19 11:12 ` [PATCH 05/10] btrfs: uninline btrfs_init_delayed_root() David Sterba
2024-02-19 11:12 ` [PATCH 06/10] btrfs: drop static inline specifiers from tree-mod-log.c David Sterba
2024-02-19 11:13 ` [PATCH 07/10] btrfs: uninline some static inline helpers from tree-log.h David Sterba
2024-02-19 11:13 ` David Sterba [this message]
2024-02-19 12:27 ` [PATCH 08/10] btrfs: simplify conditions in btrfs_free_chunk_map() Filipe Manana
2024-02-19 14:41 ` David Sterba
2024-02-26 8:31 ` kernel test robot
2024-02-19 11:13 ` [PATCH 09/10] btrfs: open code trivial btrfs_lru_cache_size() David Sterba
2024-02-19 11:13 ` [PATCH 10/10] btrfs: uninline some static inline helpers from delayed-ref.h David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cd9ae501762221ffca5408ffb59f1a3b990de14e.1708339010.git.dsterba@suse.com \
--to=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox