From: Yu Kuai Make code cleaner, we'll create new blkg and then return error if bfq is not enabled for the device, this is fine because this is super cold path. Signed-off-by: Yu Kuai --- block/bfq-cgroup.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index 43790ae91b57..d39c7a5db35d 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -1056,10 +1056,9 @@ static ssize_t bfq_io_set_device_weight(struct kernfs_open_file *of, u64 v; blkg_conf_init(&ctx, buf); - - ret = blkg_conf_prep(blkcg, &blkcg_policy_bfq, &ctx); + ret = blkg_conf_start(blkcg, &ctx); if (ret) - goto out; + return ret; if (sscanf(ctx.body, "%llu", &v) == 1) { /* require "default" on dfl */ @@ -1074,6 +1073,10 @@ static ssize_t bfq_io_set_device_weight(struct kernfs_open_file *of, } bfqg = blkg_to_bfqg(ctx.blkg); + if (!bfqg) { + ret = -EOPNOTSUPP; + goto out; + } ret = -ERANGE; if (!v || (v >= BFQ_MIN_WEIGHT && v <= BFQ_MAX_WEIGHT)) { @@ -1081,7 +1084,7 @@ static ssize_t bfq_io_set_device_weight(struct kernfs_open_file *of, ret = 0; } out: - blkg_conf_exit(&ctx); + blkg_conf_end(&ctx); return ret ?: nbytes; } -- 2.51.0