All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next,v2 0/2] net: sched: remove redundant resource cleanup when init() fails
@ 2022-09-02  8:34 Zhengchao Shao
  2022-09-02  8:34 ` [PATCH net-next,v2 1/2] net: sched: fq_codel: remove redundant resource cleanup in fq_codel_init() Zhengchao Shao
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Zhengchao Shao @ 2022-09-02  8:34 UTC (permalink / raw)
  To: netdev, linux-kernel, jhs, xiyou.wangcong, jiri, davem, edumazet,
	kuba, pabeni
  Cc: weiyongjun1, yuehaibing, shaozhengchao

qdisc_create() calls .init() to initialize qdisc. If the initialization
fails, qdisc_create() will call .destroy() to release resources.

Zhengchao Shao (2):
  net: sched: fq_codel: remove redundant resource cleanup in
    fq_codel_init()
  net: sched: htb: remove redundant resource cleanup in htb_init()

 net/sched/sch_fq_codel.c | 25 ++++++++-----------------
 net/sched/sch_htb.c      | 36 +++++++++---------------------------
 2 files changed, 17 insertions(+), 44 deletions(-)

-- 
2.17.1


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

* [PATCH net-next,v2 1/2] net: sched: fq_codel: remove redundant resource cleanup in fq_codel_init()
  2022-09-02  8:34 [PATCH net-next,v2 0/2] net: sched: remove redundant resource cleanup when init() fails Zhengchao Shao
@ 2022-09-02  8:34 ` Zhengchao Shao
  2022-09-02  8:34 ` [PATCH net-next,v2 2/2] net: sched: htb: remove redundant resource cleanup in htb_init() Zhengchao Shao
  2022-09-03  9:50 ` [PATCH net-next,v2 0/2] net: sched: remove redundant resource cleanup when init() fails patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Zhengchao Shao @ 2022-09-02  8:34 UTC (permalink / raw)
  To: netdev, linux-kernel, jhs, xiyou.wangcong, jiri, davem, edumazet,
	kuba, pabeni
  Cc: weiyongjun1, yuehaibing, shaozhengchao

If fq_codel_init() fails, qdisc_create() invokes fq_codel_destroy() to
clear resources. Therefore, remove redundant resource cleanup in
fq_codel_init().

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
v1: rebase
---
 net/sched/sch_fq_codel.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c
index 23a042adb74d..f97b2adb0a44 100644
--- a/net/sched/sch_fq_codel.c
+++ b/net/sched/sch_fq_codel.c
@@ -481,26 +481,24 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt,
 	if (opt) {
 		err = fq_codel_change(sch, opt, extack);
 		if (err)
-			goto init_failure;
+			return err;
 	}
 
 	err = tcf_block_get(&q->block, &q->filter_list, sch, extack);
 	if (err)
-		goto init_failure;
+		return err;
 
 	if (!q->flows) {
 		q->flows = kvcalloc(q->flows_cnt,
 				    sizeof(struct fq_codel_flow),
 				    GFP_KERNEL);
-		if (!q->flows) {
-			err = -ENOMEM;
-			goto init_failure;
-		}
+		if (!q->flows)
+			return -ENOMEM;
+
 		q->backlogs = kvcalloc(q->flows_cnt, sizeof(u32), GFP_KERNEL);
-		if (!q->backlogs) {
-			err = -ENOMEM;
-			goto alloc_failure;
-		}
+		if (!q->backlogs)
+			return -ENOMEM;
+
 		for (i = 0; i < q->flows_cnt; i++) {
 			struct fq_codel_flow *flow = q->flows + i;
 
@@ -513,13 +511,6 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt,
 	else
 		sch->flags &= ~TCQ_F_CAN_BYPASS;
 	return 0;
-
-alloc_failure:
-	kvfree(q->flows);
-	q->flows = NULL;
-init_failure:
-	q->flows_cnt = 0;
-	return err;
 }
 
 static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb)
-- 
2.17.1


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

* [PATCH net-next,v2 2/2] net: sched: htb: remove redundant resource cleanup in htb_init()
  2022-09-02  8:34 [PATCH net-next,v2 0/2] net: sched: remove redundant resource cleanup when init() fails Zhengchao Shao
  2022-09-02  8:34 ` [PATCH net-next,v2 1/2] net: sched: fq_codel: remove redundant resource cleanup in fq_codel_init() Zhengchao Shao
@ 2022-09-02  8:34 ` Zhengchao Shao
  2022-09-03  9:50 ` [PATCH net-next,v2 0/2] net: sched: remove redundant resource cleanup when init() fails patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Zhengchao Shao @ 2022-09-02  8:34 UTC (permalink / raw)
  To: netdev, linux-kernel, jhs, xiyou.wangcong, jiri, davem, edumazet,
	kuba, pabeni
  Cc: weiyongjun1, yuehaibing, shaozhengchao

If htb_init() fails, qdisc_create() invokes htb_destroy() to clear
resources. Therefore, remove redundant resource cleanup in htb_init().

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
v1: rebase
---
 net/sched/sch_htb.c | 36 +++++++++---------------------------
 1 file changed, 9 insertions(+), 27 deletions(-)

diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index dbbb276aecb3..78d0c7549c74 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -1102,7 +1102,7 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt,
 
 	err = qdisc_class_hash_init(&q->clhash);
 	if (err < 0)
-		goto err_free_direct_qdiscs;
+		return err;
 
 	if (tb[TCA_HTB_DIRECT_QLEN])
 		q->direct_qlen = nla_get_u32(tb[TCA_HTB_DIRECT_QLEN]);
@@ -1123,8 +1123,7 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt,
 		qdisc = qdisc_create_dflt(dev_queue, &pfifo_qdisc_ops,
 					  TC_H_MAKE(sch->handle, 0), extack);
 		if (!qdisc) {
-			err = -ENOMEM;
-			goto err_free_qdiscs;
+			return -ENOMEM;
 		}
 
 		htb_set_lockdep_class_child(qdisc);
@@ -1142,7 +1141,7 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt,
 	};
 	err = htb_offload(dev, &offload_opt);
 	if (err)
-		goto err_free_qdiscs;
+		return err;
 
 	/* Defer this assignment, so that htb_destroy skips offload-related
 	 * parts (especially calling ndo_setup_tc) on errors.
@@ -1150,22 +1149,6 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt,
 	q->offload = true;
 
 	return 0;
-
-err_free_qdiscs:
-	for (ntx = 0; ntx < q->num_direct_qdiscs && q->direct_qdiscs[ntx];
-	     ntx++)
-		qdisc_put(q->direct_qdiscs[ntx]);
-
-	qdisc_class_hash_destroy(&q->clhash);
-	/* Prevent use-after-free and double-free when htb_destroy gets called.
-	 */
-	q->clhash.hash = NULL;
-	q->clhash.hashsize = 0;
-
-err_free_direct_qdiscs:
-	kfree(q->direct_qdiscs);
-	q->direct_qdiscs = NULL;
-	return err;
 }
 
 static void htb_attach_offload(struct Qdisc *sch)
@@ -1688,13 +1671,12 @@ static void htb_destroy(struct Qdisc *sch)
 	qdisc_class_hash_destroy(&q->clhash);
 	__qdisc_reset_queue(&q->direct_queue);
 
-	if (!q->offload)
-		return;
-
-	offload_opt = (struct tc_htb_qopt_offload) {
-		.command = TC_HTB_DESTROY,
-	};
-	htb_offload(dev, &offload_opt);
+	if (q->offload) {
+		offload_opt = (struct tc_htb_qopt_offload) {
+			.command = TC_HTB_DESTROY,
+		};
+		htb_offload(dev, &offload_opt);
+	}
 
 	if (!q->direct_qdiscs)
 		return;
-- 
2.17.1


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

* Re: [PATCH net-next,v2 0/2] net: sched: remove redundant resource cleanup when init() fails
  2022-09-02  8:34 [PATCH net-next,v2 0/2] net: sched: remove redundant resource cleanup when init() fails Zhengchao Shao
  2022-09-02  8:34 ` [PATCH net-next,v2 1/2] net: sched: fq_codel: remove redundant resource cleanup in fq_codel_init() Zhengchao Shao
  2022-09-02  8:34 ` [PATCH net-next,v2 2/2] net: sched: htb: remove redundant resource cleanup in htb_init() Zhengchao Shao
@ 2022-09-03  9:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-09-03  9:50 UTC (permalink / raw)
  To: Zhengchao Shao
  Cc: netdev, linux-kernel, jhs, xiyou.wangcong, jiri, davem, edumazet,
	kuba, pabeni, weiyongjun1, yuehaibing

Hello:

This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Fri, 2 Sep 2022 16:34:28 +0800 you wrote:
> qdisc_create() calls .init() to initialize qdisc. If the initialization
> fails, qdisc_create() will call .destroy() to release resources.
> 
> Zhengchao Shao (2):
>   net: sched: fq_codel: remove redundant resource cleanup in
>     fq_codel_init()
>   net: sched: htb: remove redundant resource cleanup in htb_init()
> 
> [...]

Here is the summary with links:
  - [net-next,v2,1/2] net: sched: fq_codel: remove redundant resource cleanup in fq_codel_init()
    https://git.kernel.org/netdev/net-next/c/494f5063b86c
  - [net-next,v2,2/2] net: sched: htb: remove redundant resource cleanup in htb_init()
    https://git.kernel.org/netdev/net-next/c/d59f4e1d1fe7

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-09-03  9:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-02  8:34 [PATCH net-next,v2 0/2] net: sched: remove redundant resource cleanup when init() fails Zhengchao Shao
2022-09-02  8:34 ` [PATCH net-next,v2 1/2] net: sched: fq_codel: remove redundant resource cleanup in fq_codel_init() Zhengchao Shao
2022-09-02  8:34 ` [PATCH net-next,v2 2/2] net: sched: htb: remove redundant resource cleanup in htb_init() Zhengchao Shao
2022-09-03  9:50 ` [PATCH net-next,v2 0/2] net: sched: remove redundant resource cleanup when init() fails patchwork-bot+netdevbpf

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.