linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: avoid unnecessary sock_flag() check when enable timestamp
@ 2018-08-06  3:57 Yafang Shao
  2018-08-06 17:43 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Yafang Shao @ 2018-08-06  3:57 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-kernel, Yafang Shao

The sock_flag() check is alreay inside sock_enable_timestamp(), so it is
unnecessary checking it in the caller.

    void sock_enable_timestamp(struct sock *sk, int flag)
    {
        if (!sock_flag(sk, flag)) {
            ...
        }
    }

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 net/compat.c    | 6 ++----
 net/core/sock.c | 8 ++++----
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/net/compat.c b/net/compat.c
index 7242cce..3b2105f 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -466,8 +466,7 @@ int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
 
 	ctv = (struct compat_timeval __user *) userstamp;
 	err = -ENOENT;
-	if (!sock_flag(sk, SOCK_TIMESTAMP))
-		sock_enable_timestamp(sk, SOCK_TIMESTAMP);
+	sock_enable_timestamp(sk, SOCK_TIMESTAMP);
 	tv = ktime_to_timeval(sk->sk_stamp);
 	if (tv.tv_sec == -1)
 		return err;
@@ -494,8 +493,7 @@ int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *usersta
 
 	ctv = (struct compat_timespec __user *) userstamp;
 	err = -ENOENT;
-	if (!sock_flag(sk, SOCK_TIMESTAMP))
-		sock_enable_timestamp(sk, SOCK_TIMESTAMP);
+	sock_enable_timestamp(sk, SOCK_TIMESTAMP);
 	ts = ktime_to_timespec(sk->sk_stamp);
 	if (ts.tv_sec == -1)
 		return err;
diff --git a/net/core/sock.c b/net/core/sock.c
index e31233f..3730eb8 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2900,8 +2900,8 @@ bool lock_sock_fast(struct sock *sk)
 int sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
 {
 	struct timeval tv;
-	if (!sock_flag(sk, SOCK_TIMESTAMP))
-		sock_enable_timestamp(sk, SOCK_TIMESTAMP);
+
+	sock_enable_timestamp(sk, SOCK_TIMESTAMP);
 	tv = ktime_to_timeval(sk->sk_stamp);
 	if (tv.tv_sec == -1)
 		return -ENOENT;
@@ -2916,8 +2916,8 @@ int sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
 int sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp)
 {
 	struct timespec ts;
-	if (!sock_flag(sk, SOCK_TIMESTAMP))
-		sock_enable_timestamp(sk, SOCK_TIMESTAMP);
+
+	sock_enable_timestamp(sk, SOCK_TIMESTAMP);
 	ts = ktime_to_timespec(sk->sk_stamp);
 	if (ts.tv_sec == -1)
 		return -ENOENT;
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] net: avoid unnecessary sock_flag() check when enable timestamp
  2018-08-06  3:57 [PATCH net-next] net: avoid unnecessary sock_flag() check when enable timestamp Yafang Shao
@ 2018-08-06 17:43 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-08-06 17:43 UTC (permalink / raw)
  To: laoar.shao; +Cc: netdev, linux-kernel

From: Yafang Shao <laoar.shao@gmail.com>
Date: Mon,  6 Aug 2018 11:57:02 +0800

> The sock_flag() check is alreay inside sock_enable_timestamp(), so it is
> unnecessary checking it in the caller.
> 
>     void sock_enable_timestamp(struct sock *sk, int flag)
>     {
>         if (!sock_flag(sk, flag)) {
>             ...
>         }
>     }
> 
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>

Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-08-06 17:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-06  3:57 [PATCH net-next] net: avoid unnecessary sock_flag() check when enable timestamp Yafang Shao
2018-08-06 17:43 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).