From 806ebf2aa01749ca4c510fbb42cd146bdfdbe5a4 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Fri, 22 Dec 2023 21:10:32 -0500 Subject: bcachefs: Convert split_devs() to darray Bit of cleanup & modernization: also moving this code to util.c, it'll be used by userspace as well. Signed-off-by: Kent Overstreet --- fs/bcachefs/util.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'fs/bcachefs/util.c') diff --git a/fs/bcachefs/util.c b/fs/bcachefs/util.c index d530277f9017..2e4c5d9606de 100644 --- a/fs/bcachefs/util.c +++ b/fs/bcachefs/util.c @@ -1174,3 +1174,37 @@ u64 *bch2_acc_percpu_u64s(u64 __percpu *p, unsigned nr) return ret; } + +void bch2_darray_str_exit(darray_str *d) +{ + darray_for_each(*d, i) + kfree(*i); + darray_exit(d); +} + +int bch2_split_devs(const char *_dev_name, darray_str *ret) +{ + darray_init(ret); + + char *dev_name = kstrdup(_dev_name, GFP_KERNEL), *s = dev_name; + if (!dev_name) + return -ENOMEM; + + while ((s = strsep(&dev_name, ":"))) { + char *p = kstrdup(s, GFP_KERNEL); + if (!p) + goto err; + + if (darray_push(ret, p)) { + kfree(p); + goto err; + } + } + + kfree(dev_name); + return 0; +err: + bch2_darray_str_exit(ret); + kfree(dev_name); + return -ENOMEM; +} -- cgit