]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: remove NULL-pointer net parameter in ip_metrics_convert
authorJason Xing <kernelxing@tencent.com>
Fri, 31 May 2024 15:46:34 +0000 (23:46 +0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 5 Jun 2024 09:06:00 +0000 (10:06 +0100)
When I was doing some experiments, I found that when using the first
parameter, namely, struct net, in ip_metrics_convert() always triggers NULL
pointer crash. Then I digged into this part, realizing that we can remove
this one due to its uselessness.

Signed-off-by: Jason Xing <kernelxing@tencent.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ip.h
include/net/tcp.h
net/ipv4/fib_semantics.c
net/ipv4/metrics.c
net/ipv4/tcp_cong.c
net/ipv6/route.c

index 6d735e00d3f3ec4b01dd8e4fca93432496c0b62c..c5606cadb1a552f3e282a5e1e721fd47b07432b2 100644 (file)
@@ -506,8 +506,7 @@ static inline unsigned int ip_skb_dst_mtu(struct sock *sk,
        return mtu - lwtunnel_headroom(skb_dst(skb)->lwtstate, mtu);
 }
 
-struct dst_metrics *ip_fib_metrics_init(struct net *net, struct nlattr *fc_mx,
-                                       int fc_mx_len,
+struct dst_metrics *ip_fib_metrics_init(struct nlattr *fc_mx, int fc_mx_len,
                                        struct netlink_ext_ack *extack);
 static inline void ip_fib_metrics_put(struct dst_metrics *fib_metrics)
 {
index 08c3b99501cf6e021dd8d3d8f72d8b1e3dbdc8f5..a70fc39090fe86e892137fa5b0b3362262e1c127 100644 (file)
@@ -1224,7 +1224,7 @@ extern struct tcp_congestion_ops tcp_reno;
 
 struct tcp_congestion_ops *tcp_ca_find(const char *name);
 struct tcp_congestion_ops *tcp_ca_find_key(u32 key);
-u32 tcp_ca_get_key_by_name(struct net *net, const char *name, bool *ecn_ca);
+u32 tcp_ca_get_key_by_name(const char *name, bool *ecn_ca);
 #ifdef CONFIG_INET
 char *tcp_ca_get_name_by_key(u32 key, char *buffer);
 #else
index f669da98d11d8f2a1182e6e84d98c2b92f774a88..7b6b042208bd24ab95b944199d6c2a16c69ee870 100644 (file)
@@ -1030,7 +1030,7 @@ bool fib_metrics_match(struct fib_config *cfg, struct fib_info *fi)
                        bool ecn_ca = false;
 
                        nla_strscpy(tmp, nla, sizeof(tmp));
-                       val = tcp_ca_get_key_by_name(fi->fib_net, tmp, &ecn_ca);
+                       val = tcp_ca_get_key_by_name(tmp, &ecn_ca);
                } else {
                        if (nla_len(nla) != sizeof(u32))
                                return false;
@@ -1459,8 +1459,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
        fi = kzalloc(struct_size(fi, fib_nh, nhs), GFP_KERNEL);
        if (!fi)
                goto failure;
-       fi->fib_metrics = ip_fib_metrics_init(fi->fib_net, cfg->fc_mx,
-                                             cfg->fc_mx_len, extack);
+       fi->fib_metrics = ip_fib_metrics_init(cfg->fc_mx, cfg->fc_mx_len, extack);
        if (IS_ERR(fi->fib_metrics)) {
                err = PTR_ERR(fi->fib_metrics);
                kfree(fi);
index 0e3ee1532848c8f49e0a342b7c8ecc1c27684e67..8ddac1f595ed8cc6077e027f53db7db3c7387843 100644 (file)
@@ -7,7 +7,7 @@
 #include <net/net_namespace.h>
 #include <net/tcp.h>
 
-static int ip_metrics_convert(struct net *net, struct nlattr *fc_mx,
+static int ip_metrics_convert(struct nlattr *fc_mx,
                              int fc_mx_len, u32 *metrics,
                              struct netlink_ext_ack *extack)
 {
@@ -31,7 +31,7 @@ static int ip_metrics_convert(struct net *net, struct nlattr *fc_mx,
                        char tmp[TCP_CA_NAME_MAX];
 
                        nla_strscpy(tmp, nla, sizeof(tmp));
-                       val = tcp_ca_get_key_by_name(net, tmp, &ecn_ca);
+                       val = tcp_ca_get_key_by_name(tmp, &ecn_ca);
                        if (val == TCP_CA_UNSPEC) {
                                NL_SET_ERR_MSG(extack, "Unknown tcp congestion algorithm");
                                return -EINVAL;
@@ -63,7 +63,7 @@ static int ip_metrics_convert(struct net *net, struct nlattr *fc_mx,
        return 0;
 }
 
-struct dst_metrics *ip_fib_metrics_init(struct net *net, struct nlattr *fc_mx,
+struct dst_metrics *ip_fib_metrics_init(struct nlattr *fc_mx,
                                        int fc_mx_len,
                                        struct netlink_ext_ack *extack)
 {
@@ -77,7 +77,7 @@ struct dst_metrics *ip_fib_metrics_init(struct net *net, struct nlattr *fc_mx,
        if (unlikely(!fib_metrics))
                return ERR_PTR(-ENOMEM);
 
-       err = ip_metrics_convert(net, fc_mx, fc_mx_len, fib_metrics->metrics,
+       err = ip_metrics_convert(fc_mx, fc_mx_len, fib_metrics->metrics,
                                 extack);
        if (!err) {
                refcount_set(&fib_metrics->refcnt, 1);
index 28ffcfbeef14e5bb57e62f1610cdf52caaafba89..48617d99abb0d4be003913e40d7a69d95db0138d 100644 (file)
@@ -46,8 +46,7 @@ void tcp_set_ca_state(struct sock *sk, const u8 ca_state)
 }
 
 /* Must be called with rcu lock held */
-static struct tcp_congestion_ops *tcp_ca_find_autoload(struct net *net,
-                                                      const char *name)
+static struct tcp_congestion_ops *tcp_ca_find_autoload(const char *name)
 {
        struct tcp_congestion_ops *ca = tcp_ca_find(name);
 
@@ -178,7 +177,7 @@ int tcp_update_congestion_control(struct tcp_congestion_ops *ca, struct tcp_cong
        return ret;
 }
 
-u32 tcp_ca_get_key_by_name(struct net *net, const char *name, bool *ecn_ca)
+u32 tcp_ca_get_key_by_name(const char *name, bool *ecn_ca)
 {
        const struct tcp_congestion_ops *ca;
        u32 key = TCP_CA_UNSPEC;
@@ -186,7 +185,7 @@ u32 tcp_ca_get_key_by_name(struct net *net, const char *name, bool *ecn_ca)
        might_sleep();
 
        rcu_read_lock();
-       ca = tcp_ca_find_autoload(net, name);
+       ca = tcp_ca_find_autoload(name);
        if (ca) {
                key = ca->key;
                *ecn_ca = ca->flags & TCP_CONG_NEEDS_ECN;
@@ -283,7 +282,7 @@ int tcp_set_default_congestion_control(struct net *net, const char *name)
        int ret;
 
        rcu_read_lock();
-       ca = tcp_ca_find_autoload(net, name);
+       ca = tcp_ca_find_autoload(name);
        if (!ca) {
                ret = -ENOENT;
        } else if (!bpf_try_module_get(ca, ca->owner)) {
@@ -421,7 +420,7 @@ int tcp_set_congestion_control(struct sock *sk, const char *name, bool load,
        if (!load)
                ca = tcp_ca_find(name);
        else
-               ca = tcp_ca_find_autoload(sock_net(sk), name);
+               ca = tcp_ca_find_autoload(name);
 
        /* No change asking for existing value */
        if (ca == icsk->icsk_ca_ops) {
index a504b88ec06b5aec6b0f915c3ff044cd98f864ab..12f647d0fec0f45415de32b6789672c9b772a8dd 100644 (file)
@@ -3761,7 +3761,7 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
        if (!rt)
                goto out;
 
-       rt->fib6_metrics = ip_fib_metrics_init(net, cfg->fc_mx, cfg->fc_mx_len,
+       rt->fib6_metrics = ip_fib_metrics_init(cfg->fc_mx, cfg->fc_mx_len,
                                               extack);
        if (IS_ERR(rt->fib6_metrics)) {
                err = PTR_ERR(rt->fib6_metrics);