hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/net/decnet/af_decnet.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12
23 /*
34 * DECnet An implementation of the DECnet protocol suite for the LINUX
....@@ -46,15 +47,6 @@
4647 /******************************************************************************
4748 (c) 1995-1998 E.M. Serrat emserrat@geocities.com
4849
49
- This program is free software; you can redistribute it and/or modify
50
- it under the terms of the GNU General Public License as published by
51
- the Free Software Foundation; either version 2 of the License, or
52
- any later version.
53
-
54
- This program is distributed in the hope that it will be useful,
55
- but WITHOUT ANY WARRANTY; without even the implied warranty of
56
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57
- GNU General Public License for more details.
5850
5951 HISTORY:
6052
....@@ -158,7 +150,8 @@
158150 static struct hlist_head dn_wild_sk;
159151 static atomic_long_t decnet_memory_allocated;
160152
161
-static int __dn_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen, int flags);
153
+static int __dn_setsockopt(struct socket *sock, int level, int optname,
154
+ sockptr_t optval, unsigned int optlen, int flags);
162155 static int __dn_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen, int flags);
163156
164157 static struct hlist_head *dn_find_list(struct sock *sk)
....@@ -192,7 +185,7 @@
192185 static unsigned short port_alloc(struct sock *sk)
193186 {
194187 struct dn_scp *scp = DN_SK(sk);
195
-static unsigned short port = 0x2000;
188
+ static unsigned short port = 0x2000;
196189 unsigned short i_port = port;
197190
198191 while(check_port(cpu_to_le16(++port)) != 0) {
....@@ -444,7 +437,7 @@
444437 skb_queue_purge(&scp->other_xmit_queue);
445438 skb_queue_purge(&scp->other_receive_queue);
446439
447
- dst_release(rcu_dereference_check(sk->sk_dst_cache, 1));
440
+ dst_release(rcu_dereference_protected(sk->sk_dst_cache, 1));
448441 }
449442
450443 static unsigned long dn_memory_pressure;
....@@ -487,8 +480,8 @@
487480 sk->sk_family = PF_DECnet;
488481 sk->sk_protocol = 0;
489482 sk->sk_allocation = gfp;
490
- sk->sk_sndbuf = sysctl_decnet_wmem[1];
491
- sk->sk_rcvbuf = sysctl_decnet_rmem[1];
483
+ sk->sk_sndbuf = READ_ONCE(sysctl_decnet_wmem[1]);
484
+ sk->sk_rcvbuf = READ_ONCE(sysctl_decnet_rmem[1]);
492485
493486 /* Initialization of DECnet Session Control Port */
494487 scp = DN_SK(sk);
....@@ -630,12 +623,12 @@
630623 goto disc_reject;
631624 case DN_RUN:
632625 scp->state = DN_DI;
633
- /* fall through */
626
+ fallthrough;
634627 case DN_DI:
635628 case DN_DR:
636629 disc_reject:
637630 dn_nsp_send_disc(sk, NSP_DISCINIT, 0, sk->sk_allocation);
638
- /* fall through */
631
+ fallthrough;
639632 case DN_NC:
640633 case DN_NR:
641634 case DN_RJ:
....@@ -649,7 +642,7 @@
649642 break;
650643 default:
651644 printk(KERN_DEBUG "DECnet: dn_destroy_sock passed socket in invalid state\n");
652
- /* fall through */
645
+ fallthrough;
653646 case DN_O:
654647 dn_stop_slow_timer(sk);
655648
....@@ -678,7 +671,7 @@
678671 {
679672 struct sock *sk;
680673
681
- if (protocol < 0 || protocol > SK_PROTOCOL_MAX)
674
+ if (protocol < 0 || protocol > U8_MAX)
682675 return -EINVAL;
683676
684677 if (!net_eq(net, &init_net))
....@@ -1096,7 +1089,7 @@
10961089 }
10971090
10981091 cb = DN_SKB_CB(skb);
1099
- sk->sk_ack_backlog--;
1092
+ sk_acceptq_removed(sk);
11001093 newsk = dn_alloc_sock(sock_net(sk), newsock, sk->sk_allocation, kern);
11011094 if (newsk == NULL) {
11021095 release_sock(sk);
....@@ -1325,7 +1318,8 @@
13251318 return err;
13261319 }
13271320
1328
-static int dn_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
1321
+static int dn_setsockopt(struct socket *sock, int level, int optname,
1322
+ sockptr_t optval, unsigned int optlen)
13291323 {
13301324 struct sock *sk = sock->sk;
13311325 int err;
....@@ -1343,7 +1337,8 @@
13431337 return err;
13441338 }
13451339
1346
-static int __dn_setsockopt(struct socket *sock, int level,int optname, char __user *optval, unsigned int optlen, int flags)
1340
+static int __dn_setsockopt(struct socket *sock, int level, int optname,
1341
+ sockptr_t optval, unsigned int optlen, int flags)
13471342 {
13481343 struct sock *sk = sock->sk;
13491344 struct dn_scp *scp = DN_SK(sk);
....@@ -1359,13 +1354,13 @@
13591354 } u;
13601355 int err;
13611356
1362
- if (optlen && !optval)
1357
+ if (optlen && sockptr_is_null(optval))
13631358 return -EINVAL;
13641359
13651360 if (optlen > sizeof(u))
13661361 return -EINVAL;
13671362
1368
- if (copy_from_user(&u, optval, optlen))
1363
+ if (copy_from_sockptr(&u, optval, optlen))
13691364 return -EFAULT;
13701365
13711366 switch (optname) {
....@@ -2139,14 +2134,11 @@
21392134 struct dn_iter_state *state = seq->private;
21402135
21412136 n = sk_next(n);
2142
-try_again:
2143
- if (n)
2144
- goto out;
2145
- if (++state->bucket >= DN_SK_HASH_SIZE)
2146
- goto out;
2147
- n = sk_head(&dn_sk_hash[state->bucket]);
2148
- goto try_again;
2149
-out:
2137
+ while (!n) {
2138
+ if (++state->bucket >= DN_SK_HASH_SIZE)
2139
+ break;
2140
+ n = sk_head(&dn_sk_hash[state->bucket]);
2141
+ }
21502142 return n;
21512143 }
21522144
....@@ -2402,7 +2394,7 @@
24022394
24032395 proto_unregister(&dn_proto);
24042396
2405
- rcu_barrier_bh(); /* Wait for completion of call_rcu_bh()'s */
2397
+ rcu_barrier(); /* Wait for completion of call_rcu()'s */
24062398 }
24072399 module_exit(decnet_exit);
24082400 #endif