diff options
Diffstat (limited to 'net/can/raw.c')
| -rw-r--r-- | net/can/raw.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/net/can/raw.c b/net/can/raw.c index da386f1fa815..fdbc36140e9b 100644 --- a/net/can/raw.c +++ b/net/can/raw.c | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | // SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) | 1 | // SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) |
| 2 | /* | 2 | /* raw.c - Raw sockets for protocol family CAN |
| 3 | * raw.c - Raw sockets for protocol family CAN | ||
| 4 | * | 3 | * |
| 5 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research | 4 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research |
| 6 | * All rights reserved. | 5 | * All rights reserved. |
| @@ -65,8 +64,7 @@ MODULE_ALIAS("can-proto-1"); | |||
| 65 | 64 | ||
| 66 | #define MASK_ALL 0 | 65 | #define MASK_ALL 0 |
| 67 | 66 | ||
| 68 | /* | 67 | /* A raw socket has a list of can_filters attached to it, each receiving |
| 69 | * A raw socket has a list of can_filters attached to it, each receiving | ||
| 70 | * the CAN frames matching that filter. If the filter list is empty, | 68 | * the CAN frames matching that filter. If the filter list is empty, |
| 71 | * no CAN frames will be received by the socket. The default after | 69 | * no CAN frames will be received by the socket. The default after |
| 72 | * opening the socket, is to have one filter which receives all frames. | 70 | * opening the socket, is to have one filter which receives all frames. |
| @@ -97,8 +95,7 @@ struct raw_sock { | |||
| 97 | struct uniqframe __percpu *uniq; | 95 | struct uniqframe __percpu *uniq; |
| 98 | }; | 96 | }; |
| 99 | 97 | ||
| 100 | /* | 98 | /* Return pointer to store the extra msg flags for raw_recvmsg(). |
| 101 | * Return pointer to store the extra msg flags for raw_recvmsg(). | ||
| 102 | * We use the space of one unsigned int beyond the 'struct sockaddr_can' | 99 | * We use the space of one unsigned int beyond the 'struct sockaddr_can' |
| 103 | * in skb->cb. | 100 | * in skb->cb. |
| 104 | */ | 101 | */ |
| @@ -157,8 +154,7 @@ static void raw_rcv(struct sk_buff *oskb, void *data) | |||
| 157 | if (!skb) | 154 | if (!skb) |
| 158 | return; | 155 | return; |
| 159 | 156 | ||
| 160 | /* | 157 | /* Put the datagram to the queue so that raw_recvmsg() can |
| 161 | * Put the datagram to the queue so that raw_recvmsg() can | ||
| 162 | * get it from there. We need to pass the interface index to | 158 | * get it from there. We need to pass the interface index to |
| 163 | * raw_recvmsg(). We pass a whole struct sockaddr_can in skb->cb | 159 | * raw_recvmsg(). We pass a whole struct sockaddr_can in skb->cb |
| 164 | * containing the interface index. | 160 | * containing the interface index. |
| @@ -284,7 +280,6 @@ static int raw_notifier(struct notifier_block *nb, | |||
| 284 | return NOTIFY_DONE; | 280 | return NOTIFY_DONE; |
| 285 | 281 | ||
| 286 | switch (msg) { | 282 | switch (msg) { |
| 287 | |||
| 288 | case NETDEV_UNREGISTER: | 283 | case NETDEV_UNREGISTER: |
| 289 | lock_sock(sk); | 284 | lock_sock(sk); |
| 290 | /* remove current filters & unregister */ | 285 | /* remove current filters & unregister */ |
| @@ -370,8 +365,9 @@ static int raw_release(struct socket *sock) | |||
| 370 | raw_disable_allfilters(dev_net(dev), dev, sk); | 365 | raw_disable_allfilters(dev_net(dev), dev, sk); |
| 371 | dev_put(dev); | 366 | dev_put(dev); |
| 372 | } | 367 | } |
| 373 | } else | 368 | } else { |
| 374 | raw_disable_allfilters(sock_net(sk), NULL, sk); | 369 | raw_disable_allfilters(sock_net(sk), NULL, sk); |
| 370 | } | ||
| 375 | } | 371 | } |
| 376 | 372 | ||
| 377 | if (ro->count > 1) | 373 | if (ro->count > 1) |
| @@ -451,8 +447,9 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len) | |||
| 451 | dev, sk); | 447 | dev, sk); |
| 452 | dev_put(dev); | 448 | dev_put(dev); |
| 453 | } | 449 | } |
| 454 | } else | 450 | } else { |
| 455 | raw_disable_allfilters(sock_net(sk), NULL, sk); | 451 | raw_disable_allfilters(sock_net(sk), NULL, sk); |
| 452 | } | ||
| 456 | } | 453 | } |
| 457 | ro->ifindex = ifindex; | 454 | ro->ifindex = ifindex; |
| 458 | ro->bound = 1; | 455 | ro->bound = 1; |
| @@ -503,7 +500,6 @@ static int raw_setsockopt(struct socket *sock, int level, int optname, | |||
| 503 | return -EINVAL; | 500 | return -EINVAL; |
| 504 | 501 | ||
| 505 | switch (optname) { | 502 | switch (optname) { |
| 506 | |||
| 507 | case CAN_RAW_FILTER: | 503 | case CAN_RAW_FILTER: |
| 508 | if (optlen % sizeof(struct can_filter) != 0) | 504 | if (optlen % sizeof(struct can_filter) != 0) |
| 509 | return -EINVAL; | 505 | return -EINVAL; |
| @@ -666,17 +662,18 @@ static int raw_getsockopt(struct socket *sock, int level, int optname, | |||
| 666 | return -EINVAL; | 662 | return -EINVAL; |
| 667 | 663 | ||
| 668 | switch (optname) { | 664 | switch (optname) { |
| 669 | |||
| 670 | case CAN_RAW_FILTER: | 665 | case CAN_RAW_FILTER: |
| 671 | lock_sock(sk); | 666 | lock_sock(sk); |
| 672 | if (ro->count > 0) { | 667 | if (ro->count > 0) { |
| 673 | int fsize = ro->count * sizeof(struct can_filter); | 668 | int fsize = ro->count * sizeof(struct can_filter); |
| 669 | |||
| 674 | if (len > fsize) | 670 | if (len > fsize) |
| 675 | len = fsize; | 671 | len = fsize; |
| 676 | if (copy_to_user(optval, ro->filter, len)) | 672 | if (copy_to_user(optval, ro->filter, len)) |
| 677 | err = -EFAULT; | 673 | err = -EFAULT; |
| 678 | } else | 674 | } else { |
| 679 | len = 0; | 675 | len = 0; |
| 676 | } | ||
| 680 | release_sock(sk); | 677 | release_sock(sk); |
| 681 | 678 | ||
| 682 | if (!err) | 679 | if (!err) |
| @@ -743,8 +740,9 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) | |||
| 743 | return -EINVAL; | 740 | return -EINVAL; |
| 744 | 741 | ||
| 745 | ifindex = addr->can_ifindex; | 742 | ifindex = addr->can_ifindex; |
| 746 | } else | 743 | } else { |
| 747 | ifindex = ro->ifindex; | 744 | ifindex = ro->ifindex; |
| 745 | } | ||
| 748 | 746 | ||
| 749 | dev = dev_get_by_index(sock_net(sk), ifindex); | 747 | dev = dev_get_by_index(sock_net(sk), ifindex); |
| 750 | if (!dev) | 748 | if (!dev) |
| @@ -837,8 +835,8 @@ static int raw_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, | |||
| 837 | return size; | 835 | return size; |
| 838 | } | 836 | } |
| 839 | 837 | ||
| 840 | int raw_sock_no_ioctlcmd(struct socket *sock, unsigned int cmd, | 838 | static int raw_sock_no_ioctlcmd(struct socket *sock, unsigned int cmd, |
| 841 | unsigned long arg) | 839 | unsigned long arg) |
| 842 | { | 840 | { |
| 843 | /* no ioctls for socket layer -> hand it down to NIC layer */ | 841 | /* no ioctls for socket layer -> hand it down to NIC layer */ |
| 844 | return -ENOIOCTLCMD; | 842 | return -ENOIOCTLCMD; |
| @@ -887,7 +885,7 @@ static __init int raw_module_init(void) | |||
| 887 | 885 | ||
| 888 | err = can_proto_register(&raw_can_proto); | 886 | err = can_proto_register(&raw_can_proto); |
| 889 | if (err < 0) | 887 | if (err < 0) |
| 890 | printk(KERN_ERR "can: registration of raw protocol failed\n"); | 888 | pr_err("can: registration of raw protocol failed\n"); |
| 891 | 889 | ||
| 892 | return err; | 890 | return err; |
| 893 | } | 891 | } |
