summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet2020-05-25 21:25:31 -0400
committerKent Overstreet2023-10-22 17:08:39 -0400
commitdc744b51f97ce043d07ebfdd0397b323396c7683 (patch)
tree778f8a87057cbac4dc68f5fead649dea7a5fa9da
parent2628cfe3d3037c20015bcc8bc59143f8b913db6c (diff)
bcachefs: Handle printing of null bkeys
This fixes a null ptr deref. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/bkey_methods.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/fs/bcachefs/bkey_methods.c b/fs/bcachefs/bkey_methods.c
index 55ef4032b37c..36e0c5152b47 100644
--- a/fs/bcachefs/bkey_methods.c
+++ b/fs/bcachefs/bkey_methods.c
@@ -176,13 +176,17 @@ void bch2_bpos_to_text(struct printbuf *out, struct bpos pos)
void bch2_bkey_to_text(struct printbuf *out, const struct bkey *k)
{
- pr_buf(out, "u64s %u type %s ", k->u64s,
- bch2_bkey_types[k->type]);
+ if (k) {
+ pr_buf(out, "u64s %u type %s ", k->u64s,
+ bch2_bkey_types[k->type]);
- bch2_bpos_to_text(out, k->p);
+ bch2_bpos_to_text(out, k->p);
- pr_buf(out, " snap %u len %u ver %llu",
- k->p.snapshot, k->size, k->version.lo);
+ pr_buf(out, " snap %u len %u ver %llu",
+ k->p.snapshot, k->size, k->version.lo);
+ } else {
+ pr_buf(out, "(null)");
+ }
}
void bch2_val_to_text(struct printbuf *out, struct bch_fs *c,
@@ -198,8 +202,11 @@ void bch2_bkey_val_to_text(struct printbuf *out, struct bch_fs *c,
struct bkey_s_c k)
{
bch2_bkey_to_text(out, k.k);
- pr_buf(out, ": ");
- bch2_val_to_text(out, c, k);
+
+ if (k.k) {
+ pr_buf(out, ": ");
+ bch2_val_to_text(out, c, k);
+ }
}
void bch2_bkey_swab_val(struct bkey_s k)