blkcg: check pol->cpd_free_fn before free cpd
Subsystems (2)
PATCH 1/1 blkcg: check pol->cpd_free_fn before free cpd
check pol->cpd_free_fn() instead of pol->cpd_alloc_fn() when free cpd.
--- block/blk-cgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/blk-cgroup.c +2 -2
@@ -1452,7 +1452,7 @@ int blkcg_policy_register(struct blkcg_policy *pol)return 0 ; err_free_cpds: -if (pol->cpd_alloc_fn) { +if (pol->cpd_free_fn) {list_for_each_entry (blkcg, &all_blkcgs, all_blkcgs_node) {if (blkcg->cpd[pol->plid]) { pol->cpd_free_fn (blkcg->cpd[pol->plid]);
@@ -1492,7 +1492,7 @@ void blkcg_policy_unregister(struct blkcg_policy *pol)/* remove cpds and unregister */ mutex_lock (&blkcg_pol_mutex); -if (pol->cpd_alloc_fn) { +if (pol->cpd_free_fn) {list_for_each_entry (blkcg, &all_blkcgs, all_blkcgs_node) {if (blkcg->cpd[pol->plid]) { pol->cpd_free_fn (blkcg->cpd[pol->plid]);
Signature · 1 line
2.9.4
Good catch,
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Jens Axboe
maintainerQuoted 1 line · weiping zhang
check
pol->cpd_free_fn()instead ofpol->cpd_alloc_fn()when free cpd.
In practice this shouldn't make a difference, since if you have an alloc_fn, you better also have a free_fn. I'd argue a better patch would be ensuring that's the case, since the current situation would at least oops and show you there's an issue, but with the patch we'll just leak the memory.
I'll apply it, but would be nice if this was handled a bit more proactively.
Signature · 1 line
Jens Axboe
Quoted 12 lines · Jens Axboe
Quoted 1 line · weiping zhang
check
pol->cpd_free_fn()instead ofpol->cpd_alloc_fn()when free cpd.In practice this shouldn't make a difference, since if you have an
alloc_fn, you better also have afree_fn. I'd argue a better patch would be ensuring that's the case, since the current situation would at least oops and show you there's an issue, but with the patch we'll just leak the memory.I'll apply it, but would be nice if this was handled a bit more proactively.
Thanks your comments, I'll add a sanity check in blkcg_policy_register function.