]> www.infradead.org Git - users/hch/misc.git/commit
blk-cgroup: improve policy registration error handling
authorChen Linxuan <chenlinxuan@uniontech.com>
Mon, 17 Mar 2025 02:29:24 +0000 (10:29 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 18 Mar 2025 18:32:09 +0000 (12:32 -0600)
commite1a0202c6bfda24002a3ae2115154fa90104c649
treede891e9323369bbfc8f266ae784b884f1390b1f4
parent86947bdc28894520ed5aab0cf21b99ff0b659e07
blk-cgroup: improve policy registration error handling

This patch improve the returned error code of blkcg_policy_register().

1. Move the validation check for cpd/pd_alloc_fn and cpd/pd_free_fn
   function pairs to the start of blkcg_policy_register(). This ensures
   we immediately return -EINVAL if the function pairs are not correctly
   provided, rather than returning -ENOSPC after locking and unlocking
   mutexes unnecessarily.

   Those locks should not contention any problems, as error of policy
   registration is a super cold path.

2. Return -ENOMEM when cpd_alloc_fn() failed.

Co-authored-by: Wen Tao <wentao@uniontech.com>
Signed-off-by: Wen Tao <wentao@uniontech.com>
Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
Reviewed-by: Michal Koutný <mkoutny@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/3E333A73B6B6DFC0+20250317022924.150907-1-chenlinxuan@uniontech.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-cgroup.c