bcachefs: Fix a couple null ptr derefs when no disk groups exist
Normally successfully parsing a target means disk groups should exist, but we don't want a BUG() or null ptr deref if we end up with an invalid target. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
01566db2fb
commit
2d8c0da1a7
@ -183,7 +183,7 @@ const struct bch_devs_mask *bch2_target_to_mask(struct bch_fs *c, unsigned targe
|
|||||||
case TARGET_GROUP: {
|
case TARGET_GROUP: {
|
||||||
struct bch_disk_groups_cpu *g = rcu_dereference(c->disk_groups);
|
struct bch_disk_groups_cpu *g = rcu_dereference(c->disk_groups);
|
||||||
|
|
||||||
return t.group < g->nr && !g->entries[t.group].deleted
|
return g && t.group < g->nr && !g->entries[t.group].deleted
|
||||||
? &g->entries[t.group].devs
|
? &g->entries[t.group].devs
|
||||||
: NULL;
|
: NULL;
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ bool bch2_dev_in_target(struct bch_fs *c, unsigned dev, unsigned target)
|
|||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
g = rcu_dereference(c->disk_groups);
|
g = rcu_dereference(c->disk_groups);
|
||||||
m = t.group < g->nr && !g->entries[t.group].deleted
|
m = g && t.group < g->nr && !g->entries[t.group].deleted
|
||||||
? &g->entries[t.group].devs
|
? &g->entries[t.group].devs
|
||||||
: NULL;
|
: NULL;
|
||||||
|
|
||||||
|
@ -55,7 +55,9 @@ static bool bch2_target_congested(struct bch_fs *c, u16 target)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
devs = bch2_target_to_mask(c, target);
|
devs = bch2_target_to_mask(c, target) ?:
|
||||||
|
&c->rw_devs[BCH_DATA_user];
|
||||||
|
|
||||||
for_each_set_bit(d, devs->d, BCH_SB_MEMBERS_MAX) {
|
for_each_set_bit(d, devs->d, BCH_SB_MEMBERS_MAX) {
|
||||||
ca = rcu_dereference(c->devs[d]);
|
ca = rcu_dereference(c->devs[d]);
|
||||||
if (!ca)
|
if (!ca)
|
||||||
|
Loading…
Reference in New Issue
Block a user