diff options
author | Arnd Bergmann <arnd@arndb.de> | 2019-04-17 16:51:48 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-04-19 17:07:40 -0400 |
commit | c7cbdbf29f488a19982cd9f4a109887f18028bbb (patch) | |
tree | 74b39321c14b93411eda0939683dc9b8b713717b /net/can | |
parent | 1ab839281cf72476988901a2606378d76530f99c (diff) |
net: rework SIOCGSTAMP ioctl handling
The SIOCGSTAMP/SIOCGSTAMPNS ioctl commands are implemented by many
socket protocol handlers, and all of those end up calling the same
sock_get_timestamp()/sock_get_timestampns() helper functions, which
results in a lot of duplicate code.
With the introduction of 64-bit time_t on 32-bit architectures, this
gets worse, as we then need four different ioctl commands in each
socket protocol implementation.
To simplify that, let's add a new .gettstamp() operation in
struct proto_ops, and move ioctl implementation into the common
sock_ioctl()/compat_sock_ioctl_trans() functions that these all go
through.
We can reuse the sock_get_timestamp() implementation, but generalize
it so it can deal with both native and compat mode, as well as
timeval and timespec structures.
Acked-by: Stefan Schmidt <stefan@datenfreihafen.org>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>
Link: https://lore.kernel.org/lkml/CAK8P3a038aDQQotzua_QtKGhq8O9n+rdiz2=WDCp82ys8eUT+A@mail.gmail.com/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/can')
-rw-r--r-- | net/can/af_can.c | 6 | ||||
-rw-r--r-- | net/can/bcm.c | 1 | ||||
-rw-r--r-- | net/can/raw.c | 1 |
3 files changed, 2 insertions, 6 deletions
diff --git a/net/can/af_can.c b/net/can/af_can.c index 1684ba5b51eb..e8fd5dc1780a 100644 --- a/net/can/af_can.c +++ b/net/can/af_can.c | |||
@@ -89,13 +89,7 @@ static atomic_t skbcounter = ATOMIC_INIT(0); | |||
89 | 89 | ||
90 | int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) | 90 | int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) |
91 | { | 91 | { |
92 | struct sock *sk = sock->sk; | ||
93 | |||
94 | switch (cmd) { | 92 | switch (cmd) { |
95 | |||
96 | case SIOCGSTAMP: | ||
97 | return sock_get_timestamp(sk, (struct timeval __user *)arg); | ||
98 | |||
99 | default: | 93 | default: |
100 | return -ENOIOCTLCMD; | 94 | return -ENOIOCTLCMD; |
101 | } | 95 | } |
diff --git a/net/can/bcm.c b/net/can/bcm.c index 79bb8afa9c0c..a34ee52f19ea 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c | |||
@@ -1689,6 +1689,7 @@ static const struct proto_ops bcm_ops = { | |||
1689 | .getname = sock_no_getname, | 1689 | .getname = sock_no_getname, |
1690 | .poll = datagram_poll, | 1690 | .poll = datagram_poll, |
1691 | .ioctl = can_ioctl, /* use can_ioctl() from af_can.c */ | 1691 | .ioctl = can_ioctl, /* use can_ioctl() from af_can.c */ |
1692 | .gettstamp = sock_gettstamp, | ||
1692 | .listen = sock_no_listen, | 1693 | .listen = sock_no_listen, |
1693 | .shutdown = sock_no_shutdown, | 1694 | .shutdown = sock_no_shutdown, |
1694 | .setsockopt = sock_no_setsockopt, | 1695 | .setsockopt = sock_no_setsockopt, |
diff --git a/net/can/raw.c b/net/can/raw.c index c70207537488..afcbff063a67 100644 --- a/net/can/raw.c +++ b/net/can/raw.c | |||
@@ -846,6 +846,7 @@ static const struct proto_ops raw_ops = { | |||
846 | .getname = raw_getname, | 846 | .getname = raw_getname, |
847 | .poll = datagram_poll, | 847 | .poll = datagram_poll, |
848 | .ioctl = can_ioctl, /* use can_ioctl() from af_can.c */ | 848 | .ioctl = can_ioctl, /* use can_ioctl() from af_can.c */ |
849 | .gettstamp = sock_gettstamp, | ||
849 | .listen = sock_no_listen, | 850 | .listen = sock_no_listen, |
850 | .shutdown = sock_no_shutdown, | 851 | .shutdown = sock_no_shutdown, |
851 | .setsockopt = raw_setsockopt, | 852 | .setsockopt = raw_setsockopt, |