All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] blkcg: check pol->cpd_free_fn before free cpd
@ 2017-08-29 16:08 weiping zhang
  0 siblings, 0 replies; 5+ messages in thread
From: weiping zhang @ 2017-08-29 16:08 UTC (permalink / raw)
  To: axboe; +Cc: linux-block

check pol->cpd_free_fn() instead of pol->cpd_alloc_fn() when free cpd.

Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
 block/blk-cgroup.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 0480892..adcbc3e 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1044,7 +1044,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
 	list_del(&blkcg->all_blkcgs_node);
 
 	for (i = 0; i < BLKCG_MAX_POLS; i++)
-		if (blkcg->cpd[i])
+		if (blkcg->cpd[i] && blkcg_policy[i]->cpd_free_fn)
 			blkcg_policy[i]->cpd_free_fn(blkcg->cpd[i]);
 
 	mutex_unlock(&blkcg_pol_mutex);
@@ -1109,7 +1109,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
 
 free_pd_blkcg:
 	for (i--; i >= 0; i--)
-		if (blkcg->cpd[i])
+		if (blkcg->cpd[i] && blkcg_policy[i]->cpd_free_fn)
 			blkcg_policy[i]->cpd_free_fn(blkcg->cpd[i]);
 free_blkcg:
 	kfree(blkcg);
@@ -1450,7 +1450,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]);
@@ -1490,7 +1490,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]);
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] blkcg: check pol->cpd_free_fn before free cpd
  2017-10-10 15:04 ` Jens Axboe
@ 2017-10-10 15:44   ` weiping zhang
  0 siblings, 0 replies; 5+ messages in thread
From: weiping zhang @ 2017-10-10 15:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block

On Tue, Oct 10, 2017 at 09:04:39AM -0600, Jens Axboe wrote:
> On 10/10/2017 08:53 AM, weiping zhang wrote:
> > check pol->cpd_free_fn() instead of pol->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.
> 
Thanks your comments, I'll add a sanity check in blkcg_policy_register
function.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] blkcg: check pol->cpd_free_fn before free cpd
  2017-10-10 14:53 weiping zhang
  2017-10-10 14:59 ` Johannes Thumshirn
@ 2017-10-10 15:04 ` Jens Axboe
  2017-10-10 15:44   ` weiping zhang
  1 sibling, 1 reply; 5+ messages in thread
From: Jens Axboe @ 2017-10-10 15:04 UTC (permalink / raw)
  To: linux-block

On 10/10/2017 08:53 AM, weiping zhang wrote:
> check pol->cpd_free_fn() instead of pol->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.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] blkcg: check pol->cpd_free_fn before free cpd
  2017-10-10 14:53 weiping zhang
@ 2017-10-10 14:59 ` Johannes Thumshirn
  2017-10-10 15:04 ` Jens Axboe
  1 sibling, 0 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2017-10-10 14:59 UTC (permalink / raw)
  To: axboe, linux-block

Good catch,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
-- 
Johannes Thumshirn                                          Storage
jthumshirn@suse.de                                +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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] blkcg: check pol->cpd_free_fn before free cpd
@ 2017-10-10 14:53 weiping zhang
  2017-10-10 14:59 ` Johannes Thumshirn
  2017-10-10 15:04 ` Jens Axboe
  0 siblings, 2 replies; 5+ messages in thread
From: weiping zhang @ 2017-10-10 14:53 UTC (permalink / raw)
  To: axboe; +Cc: linux-block

check pol->cpd_free_fn() instead of pol->cpd_alloc_fn() when free cpd.

Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
 block/blk-cgroup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index d3f56ba..e7ec676 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -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]);
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-10-10 15:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-29 16:08 [PATCH] blkcg: check pol->cpd_free_fn before free cpd weiping zhang
2017-10-10 14:53 weiping zhang
2017-10-10 14:59 ` Johannes Thumshirn
2017-10-10 15:04 ` Jens Axboe
2017-10-10 15:44   ` weiping zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.