[PATCH net-next 1/1] net: sock: Use USEC_PER_SEC macro instead of literal 1000000
From: Gao Feng The USEC_PER_SEC is used once in sock_set_timeout as the max value of tv_usec. But there are other similar codes which use the literal 100 in this file. It is minor cleanup to keep consitent. Signed-off-by: Gao Feng --- net/core/sock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/core/sock.c b/net/core/sock.c index 8b35debf..fa47dd7 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -367,7 +367,7 @@ static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen) if (tv.tv_sec == 0 && tv.tv_usec == 0) return 0; if (tv.tv_sec < (MAX_SCHEDULE_TIMEOUT/HZ - 1)) - *timeo_p = tv.tv_sec*HZ + (tv.tv_usec+(100/HZ-1))/(100/HZ); + *timeo_p = tv.tv_sec * HZ + (tv.tv_usec + (USEC_PER_SEC / HZ - 1)) / (USEC_PER_SEC / HZ); return 0; } @@ -1145,7 +1145,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname, v.tm.tv_usec = 0; } else { v.tm.tv_sec = sk->sk_rcvtimeo / HZ; - v.tm.tv_usec = ((sk->sk_rcvtimeo % HZ) * 100) / HZ; + v.tm.tv_usec = ((sk->sk_rcvtimeo % HZ) * USEC_PER_SEC) / HZ; } break; @@ -1156,7 +1156,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname, v.tm.tv_usec = 0; } else { v.tm.tv_sec = sk->sk_sndtimeo / HZ; - v.tm.tv_usec = ((sk->sk_sndtimeo % HZ) * 100) / HZ; + v.tm.tv_usec = ((sk->sk_sndtimeo % HZ) * USEC_PER_SEC) / HZ; } break; -- 1.9.1
Re: [PATCH net-next 1/1] net: sock: Use USEC_PER_SEC macro instead of literal 1000000
On Mon, 2017-02-20 at 22:33 +0800, f...@ikuai8.com wrote: > From: Gao Feng > > The USEC_PER_SEC is used once in sock_set_timeout as the max value of > tv_usec. But there are other similar codes which use the literal > 100 in this file. > It is minor cleanup to keep consitent. [] > diff --git a/net/core/sock.c b/net/core/sock.c [] > @@ -367,7 +367,7 @@ static int sock_set_timeout(long *timeo_p, char __user > *optval, int optlen) > if (tv.tv_sec == 0 && tv.tv_usec == 0) > return 0; > if (tv.tv_sec < (MAX_SCHEDULE_TIMEOUT/HZ - 1)) > - *timeo_p = tv.tv_sec*HZ + > (tv.tv_usec+(100/HZ-1))/(100/HZ); > + *timeo_p = tv.tv_sec * HZ + (tv.tv_usec + (USEC_PER_SEC / HZ - > 1)) / (USEC_PER_SEC / HZ); Maybe convert this to DIV_ROUND_UP one day too? *timeo_p = tv.tv_sec * HZ + DIV_ROUND_UP(tv.tv_usec, USEC_PER_SEC / HZ);
Re: [PATCH net-next 1/1] net: sock: Use USEC_PER_SEC macro instead of literal 1000000
On Tue, Feb 21, 2017 at 3:13 PM, Joe Perches wrote: > On Mon, 2017-02-20 at 22:33 +0800, f...@ikuai8.com wrote: >> From: Gao Feng >> >> The USEC_PER_SEC is used once in sock_set_timeout as the max value of >> tv_usec. But there are other similar codes which use the literal >> 100 in this file. >> It is minor cleanup to keep consitent. > [] >> diff --git a/net/core/sock.c b/net/core/sock.c > [] >> @@ -367,7 +367,7 @@ static int sock_set_timeout(long *timeo_p, char __user >> *optval, int optlen) >> if (tv.tv_sec == 0 && tv.tv_usec == 0) >> return 0; >> if (tv.tv_sec < (MAX_SCHEDULE_TIMEOUT/HZ - 1)) >> - *timeo_p = tv.tv_sec*HZ + >> (tv.tv_usec+(100/HZ-1))/(100/HZ); >> + *timeo_p = tv.tv_sec * HZ + (tv.tv_usec + (USEC_PER_SEC / HZ - >> 1)) / (USEC_PER_SEC / HZ); > > Maybe convert this to DIV_ROUND_UP one day too? > > *timeo_p = tv.tv_sec * HZ + DIV_ROUND_UP(tv.tv_usec, USEC_PER_SEC / > HZ); > Good idea, thanks. I would send v2 update. Regards Feng