From patchwork Tue Jul 13 12:36:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 12373873 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5448C07E95 for ; Tue, 13 Jul 2021 12:37:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD7706128C for ; Tue, 13 Jul 2021 12:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236268AbhGMMkZ (ORCPT ); Tue, 13 Jul 2021 08:40:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236098AbhGMMkY (ORCPT ); Tue, 13 Jul 2021 08:40:24 -0400 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD4D2C0613DD; Tue, 13 Jul 2021 05:37:34 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1626179853; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qJ5CyNueUybotmlLBmn5JE2YvYoFs1ygZR7RwARKtQM=; b=SnXtWje0E+4InJjXswWfj1lpFZkcgXr1DE1I446vKeBIFrHsiqzBF3O4JQCdQ/6Z8dvpkP 5RRVi3yl2ETiIsTba7/GNq8cZWhU1hdOYFcNFW90il2/pQnYUcN49DRtAUbu0KaRJt/bwZ aB2tHoCtRe/7mVpnQ9uCnnLFu/FUGPA= From: Yajun Deng To: davem@davemloft.net, kuba@kernel.org, jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, yajun.deng@linux.dev, johannes.berg@intel.com, ryazanov.s.a@gmail.com, avagin@gmail.com, vladimir.oltean@nxp.com, roopa@cumulusnetworks.com, zhudi21@huawei.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 1/2] rtnetlink: use nlmsg_{multicast, unicast} instead of netlink_{broadcast,unicast} Date: Tue, 13 Jul 2021 20:36:53 +0800 Message-Id: <20210713123654.31174-2-yajun.deng@linux.dev> In-Reply-To: <20210713123654.31174-1-yajun.deng@linux.dev> References: <20210713123654.31174-1-yajun.deng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: yajun.deng@linux.dev Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org It has a 'NETLINK_CB(' statement in nlmsg_multicast() and has 'if (err' in nlmsg_{multicast, unicast}, use nlmsg_{multicast, unicast} instead of netlink_{broadcast,unicast}. so the caller would not deal with the 'if (err >0 )' statement. Add the return value for nlmsg_multicast. As also, rename rtnetlink_send() to rtnl_send(), this makes style uniform. Signed-off-by: Yajun Deng --- include/linux/rtnetlink.h | 2 +- net/core/rtnetlink.c | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index bb9cb84114c1..60bef82e42ab 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -9,7 +9,7 @@ #include #include -extern int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, u32 group, int echo); +extern int rtnl_send(struct sk_buff *skb, struct net *net, u32 pid, u32 group, int echo); extern int rtnl_unicast(struct sk_buff *skb, struct net *net, u32 pid); extern void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid, u32 group, struct nlmsghdr *nlh, gfp_t flags); diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index f6af3e74fc44..c081d607bb69 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -707,17 +707,18 @@ static int rtnl_link_fill(struct sk_buff *skb, const struct net_device *dev) return err; } -int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, unsigned int group, int echo) +int rtnl_send(struct sk_buff *skb, struct net *net, u32 pid, unsigned int group, int echo) { struct sock *rtnl = net->rtnl; int err = 0; - NETLINK_CB(skb).dst_group = group; - if (echo) + err = nlmsg_multicast(rtnl, skb, pid, group, GFP_KERNEL); + + if (echo) { refcount_inc(&skb->users); - netlink_broadcast(rtnl, skb, pid, group, GFP_KERNEL); - if (echo) - err = netlink_unicast(rtnl, skb, pid, MSG_DONTWAIT); + err = nlmsg_unicast(rtnl, skb, pid); + } + return err; } From patchwork Tue Jul 13 12:53:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 12373887 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88FDCC07E95 for ; Tue, 13 Jul 2021 12:53:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B1AB60E08 for ; Tue, 13 Jul 2021 12:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236283AbhGMM4b (ORCPT ); Tue, 13 Jul 2021 08:56:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236164AbhGMM4a (ORCPT ); Tue, 13 Jul 2021 08:56:30 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D70AC0613DD; Tue, 13 Jul 2021 05:53:40 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1626180817; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=7LjZkWC74fDIMPYNeGmPc/K5Xi038BMB6L+xT27MYqE=; b=w8iSkPr5eesyu4f5GGaFk/2JEkyviH25L+GHL43w+G3PjuvuMdfz3HKCe25FLfngxXJRSI qWxM9BT/SKTFX4v4n+WhWqcY7g/CL1pwqOiWtJLxDRzcWzVykion7/nv/MxFWOuwrazxdy 6OUgw9PwkKcr6nuGaDTaf/WAMEvV80k= From: Yajun Deng To: davem@davemloft.net, kuba@kernel.org, jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, yajun.deng@linux.dev, johannes.berg@intel.com, ryazanov.s.a@gmail.com, avagin@gmail.com, vladimir.oltean@nxp.com, roopa@cumulusnetworks.com, zhudi21@huawei.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 2/2] net/sched: Remove unnecessary judgment statements Date: Tue, 13 Jul 2021 20:53:18 +0800 Message-Id: <20210713125318.2682-1-yajun.deng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: yajun.deng@linux.dev Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org It has been deal with the 'if (err' statement in rtnl_{send, unicast}, so use rtnl_{send, unicast} instead of netlink_{send, unicast}. Signed-off-by: Yajun Deng --- net/sched/act_api.c | 20 ++++++-------------- net/sched/cls_api.c | 28 +++++++++++----------------- net/sched/sch_api.c | 18 ++++++------------ 3 files changed, 23 insertions(+), 43 deletions(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index d17a66aab8ee..96fc6f3d080a 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1349,10 +1349,8 @@ static int tca_action_flush(struct net *net, struct nlattr *nla, nlh->nlmsg_len = skb_tail_pointer(skb) - b; nlh->nlmsg_flags |= NLM_F_ROOT; module_put(ops->owner); - err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, - n->nlmsg_flags & NLM_F_ECHO); - if (err > 0) - return 0; + err = rtnl_send(skb, net, portid, RTNLGRP_TC, + n->nlmsg_flags & NLM_F_ECHO); if (err < 0) NL_SET_ERR_MSG(extack, "Failed to send TC action flush notification"); @@ -1421,10 +1419,8 @@ tcf_del_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[], return ret; } - ret = rtnetlink_send(skb, net, portid, RTNLGRP_TC, - n->nlmsg_flags & NLM_F_ECHO); - if (ret > 0) - return 0; + ret = rtnl_send(skb, net, portid, RTNLGRP_TC, + n->nlmsg_flags & NLM_F_ECHO); return ret; } @@ -1481,7 +1477,6 @@ tcf_add_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[], u32 portid, size_t attr_size, struct netlink_ext_ack *extack) { struct sk_buff *skb; - int err = 0; skb = alloc_skb(attr_size <= NLMSG_GOODSIZE ? NLMSG_GOODSIZE : attr_size, GFP_KERNEL); @@ -1495,11 +1490,8 @@ tcf_add_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[], return -EINVAL; } - err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, - n->nlmsg_flags & NLM_F_ECHO); - if (err > 0) - err = 0; - return err; + return rtnl_send(skb, net, portid, RTNLGRP_TC, + n->nlmsg_flags & NLM_F_ECHO); } static int tcf_action_add(struct net *net, struct nlattr *nla, diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index d73b5c5514a9..bbf1bd028e7c 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -1870,13 +1870,11 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb, } if (unicast) - err = netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT); + err = rtnl_unicast(skb, net, portid); else - err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, - n->nlmsg_flags & NLM_F_ECHO); + err = rtnl_send(skb, net, portid, RTNLGRP_TC, + n->nlmsg_flags & NLM_F_ECHO); - if (err > 0) - err = 0; return err; } @@ -1909,15 +1907,13 @@ static int tfilter_del_notify(struct net *net, struct sk_buff *oskb, } if (unicast) - err = netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT); + err = rtnl_unicast(skb, net, portid); else - err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, - n->nlmsg_flags & NLM_F_ECHO); + err = rtnl_send(skb, net, portid, RTNLGRP_TC, + n->nlmsg_flags & NLM_F_ECHO); if (err < 0) NL_SET_ERR_MSG(extack, "Failed to send filter delete notification"); - if (err > 0) - err = 0; return err; } @@ -2711,13 +2707,11 @@ static int tc_chain_notify(struct tcf_chain *chain, struct sk_buff *oskb, } if (unicast) - err = netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT); + err = rtnl_unicast(skb, net, portid); else - err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, - flags & NLM_F_ECHO); + err = rtnl_send(skb, net, portid, RTNLGRP_TC, + flags & NLM_F_ECHO); - if (err > 0) - err = 0; return err; } @@ -2741,9 +2735,9 @@ static int tc_chain_notify_delete(const struct tcf_proto_ops *tmplt_ops, } if (unicast) - return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT); + return rtnl_unicast(skb, net, portid); - return rtnetlink_send(skb, net, portid, RTNLGRP_TC, flags & NLM_F_ECHO); + return rtnl_send(skb, net, portid, RTNLGRP_TC, flags & NLM_F_ECHO); } static int tc_chain_tmplt_add(struct tcf_chain *chain, struct net *net, diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index f87d07736a14..aaec80a047d6 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -987,8 +987,8 @@ static int qdisc_notify(struct net *net, struct sk_buff *oskb, } if (skb->len) - return rtnetlink_send(skb, net, portid, RTNLGRP_TC, - n->nlmsg_flags & NLM_F_ECHO); + return rtnl_send(skb, net, portid, RTNLGRP_TC, + n->nlmsg_flags & NLM_F_ECHO); err_out: kfree_skb(skb); @@ -1845,7 +1845,6 @@ static int tclass_notify(struct net *net, struct sk_buff *oskb, { struct sk_buff *skb; u32 portid = oskb ? NETLINK_CB(oskb).portid : 0; - int err = 0; skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); if (!skb) @@ -1856,11 +1855,8 @@ static int tclass_notify(struct net *net, struct sk_buff *oskb, return -EINVAL; } - err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, - n->nlmsg_flags & NLM_F_ECHO); - if (err > 0) - err = 0; - return err; + return rtnl_send(skb, net, portid, RTNLGRP_TC, + n->nlmsg_flags & NLM_F_ECHO); } static int tclass_del_notify(struct net *net, @@ -1892,10 +1888,8 @@ static int tclass_del_notify(struct net *net, return err; } - err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, - n->nlmsg_flags & NLM_F_ECHO); - if (err > 0) - err = 0; + err = rtnl_send(skb, net, portid, RTNLGRP_TC, + n->nlmsg_flags & NLM_F_ECHO); return err; }