[PATCH net-next] net/sched: act_api: Remove unnecessary nlmsg_trim()

Yue Haibing posted 1 patch 1 month, 3 weeks ago
net/sched/act_api.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
[PATCH net-next] net/sched: act_api: Remove unnecessary nlmsg_trim()
Posted by Yue Haibing 1 month, 3 weeks ago
If tca_get_fill() fails, all callers free the skb immediately, no need to
trim it back to the previous size.

Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
---
 net/sched/act_api.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 9e468e463467..54c92d0755c9 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -1649,7 +1649,7 @@ static int tca_get_fill(struct sk_buff *skb, struct tc_action *actions[],
 
 	nlh = nlmsg_put(skb, portid, seq, event, sizeof(*t), flags);
 	if (!nlh)
-		goto out_nlmsg_trim;
+		goto out;
 	t = nlmsg_data(nlh);
 	t->tca_family = AF_UNSPEC;
 	t->tca__pad1 = 0;
@@ -1657,14 +1657,14 @@ static int tca_get_fill(struct sk_buff *skb, struct tc_action *actions[],
 
 	if (extack && extack->_msg &&
 	    nla_put_string(skb, TCA_ROOT_EXT_WARN_MSG, extack->_msg))
-		goto out_nlmsg_trim;
+		goto out;
 
 	nest = nla_nest_start_noflag(skb, TCA_ACT_TAB);
 	if (!nest)
-		goto out_nlmsg_trim;
+		goto out;
 
 	if (tcf_action_dump(skb, actions, bind, ref, false) < 0)
-		goto out_nlmsg_trim;
+		goto out;
 
 	nla_nest_end(skb, nest);
 
@@ -1672,8 +1672,7 @@ static int tca_get_fill(struct sk_buff *skb, struct tc_action *actions[],
 
 	return skb->len;
 
-out_nlmsg_trim:
-	nlmsg_trim(skb, b);
+out:
 	return -1;
 }
 
-- 
2.33.0
Re: [PATCH net-next] net/sched: act_api: Remove unnecessary nlmsg_trim()
Posted by Jakub Kicinski 1 month, 3 weeks ago
On Wed, 13 Aug 2025 20:59:15 +0800 Yue Haibing wrote:
> If tca_get_fill() fails, all callers free the skb immediately, no need to
> trim it back to the previous size.

Okay, but why do we care enough to change it?
This is a fairly common pattern in netlink message formatting.
-- 
pw-bot: cr