Skip to contentSkip to conversation

amt: Use BIT macros instead of open codes

PATCH In review Juhee Kang 4 participants 6 messages Apr 30, 2022 – May 3, 2022

Subsystems (3)
lore
Share & tools
lore

Juhee Kang

author
#0 lore raw

PATCH 1/1 amt: Use BIT macros instead of open codes

Replace open code related to bit operation with BIT macros, which kernel provided. This patch provides no functional change.

---
 drivers/net/amt.c | 2 +-
 include/net/amt.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/amt.c +1 -1
index 10455c9b9da0..76c1969a03f5 100644
@@ -959,7 +959,7 @@ static void amt_req_work(struct work_struct *work)
 	amt_update_gw_status(amt, AMT_STATUS_SENT_REQUEST, true);
 	spin_lock_bh(&amt->lock);
 out:
-	exp = min_t(u32, (1 * (1 << amt->req_cnt)), AMT_MAX_REQ_TIMEOUT);
+	exp = min_t(u32, (1 * BIT(amt->req_cnt)), AMT_MAX_REQ_TIMEOUT);
 	mod_delayed_work(amt_wq, &amt->req_wq, msecs_to_jiffies(exp * 1000));
 	spin_unlock_bh(&amt->lock);
 }
include/net/amt.h +1 -1
index 7a4db8b903ee..d2fd76b0a424 100644
@@ -354,7 +354,7 @@ struct amt_dev {
 #define AMT_MAX_GROUP		32
 #define AMT_MAX_SOURCE		128
 #define AMT_HSIZE_SHIFT		8
-#define AMT_HSIZE		(1 << AMT_HSIZE_SHIFT)
+#define AMT_HSIZE		BIT(AMT_HSIZE_SHIFT)
 
 #define AMT_DISCOVERY_TIMEOUT	5000
 #define AMT_INIT_REQ_TIMEOUT	1
Signature · 1 line
2.25.1
maintainer Reviewed-by Tested-by on v1 1/1
#1 lore raw

On 4/30/22 22:56, Juhee Kang wrote:

Hi Juhee,
Thanks a lot for this work!

Quoted 3 lines

Replace open code related to bit operation with BIT macros, which kernel provided. This patch provides no functional change.

Thanks,
Taehee Yoo

Quoted 32 lines
---
  drivers/net/amt.c | 2 +-
  include/net/amt.h | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/amt.c +1 -1
index 10455c9b9da0..76c1969a03f5 100644
@@ -959,7 +959,7 @@ static void amt_req_work(struct work_struct *work)
  	amt_update_gw_status(amt, AMT_STATUS_SENT_REQUEST, true);
  	spin_lock_bh(&amt->lock);
  out:
-	exp = min_t(u32, (1 * (1 << amt->req_cnt)), AMT_MAX_REQ_TIMEOUT);
+	exp = min_t(u32, (1 * BIT(amt->req_cnt)), AMT_MAX_REQ_TIMEOUT);
  	mod_delayed_work(amt_wq, &amt->req_wq, msecs_to_jiffies(exp * 1000));
  	spin_unlock_bh(&amt->lock);
  }
include/net/amt.h +1 -1
index 7a4db8b903ee..d2fd76b0a424 100644
@@ -354,7 +354,7 @@ struct amt_dev {
  #define AMT_MAX_GROUP		32
  #define AMT_MAX_SOURCE		128
  #define AMT_HSIZE_SHIFT		8
-#define AMT_HSIZE		(1 << AMT_HSIZE_SHIFT)
+#define AMT_HSIZE		BIT(AMT_HSIZE_SHIFT)
 
  #define AMT_DISCOVERY_TIMEOUT	5000
  #define AMT_INIT_REQ_TIMEOUT	1
maintainer
#2 lore raw
In reply to Juhee Kang

Hello,

Quoted 27 lines · Juhee Kang

Replace open code related to bit operation with BIT macros, which kernel provided. This patch provides no functional change.

---
 drivers/net/amt.c | 2 +-
 include/net/amt.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/amt.c +1 -1
index 10455c9b9da0..76c1969a03f5 100644
@@ -959,7 +959,7 @@ static void amt_req_work(struct work_struct *work)
 	amt_update_gw_status(amt, AMT_STATUS_SENT_REQUEST, true);
 	spin_lock_bh(&amt->lock);
 out:
-	exp = min_t(u32, (1 * (1 << amt->req_cnt)), AMT_MAX_REQ_TIMEOUT);
+	exp = min_t(u32, (1 * BIT(amt->req_cnt)), AMT_MAX_REQ_TIMEOUT);
 	mod_delayed_work(amt_wq, &amt->req_wq, msecs_to_jiffies(exp * 1000));
 	spin_unlock_bh(&amt->lock);
 }
include/net/amt.h +0 -0
index 7a4db8b903ee..d2fd76b0a424 100644

include/net/amt.h struct amt_dev { · line 360

Quoted 8 lines
include/net/amt.h +1 -1
@@ -354,7 +354,7 @@ struct amt_dev {
 #define AMT_MAX_GROUP		32
 #define AMT_MAX_SOURCE		128
 #define AMT_HSIZE_SHIFT		8
-#define AMT_HSIZE		(1 << AMT_HSIZE_SHIFT)
+#define AMT_HSIZE		BIT(AMT_HSIZE_SHIFT)
 
 #define AMT_DISCOVERY_TIMEOUT	5000
 #define AMT_INIT_REQ_TIMEOUT	1

Even if the 2 replaced statements use shift operations, they do not look like bit manipulation: the first one is an exponential timeout, the 2nd one is an (hash) size. I think using the BIT() macro here will be confusing.

Cheers,

Paolo

#3 lore raw
Quoted 3 lines · Paolo Abeni
Quoted 2 lines · Juhee Kang

Replace open code related to bit operation with BIT macros, which kernel provided. This patch provides no functional change.

[]

Quoted 1 line

drivers/net/amt.c

Quoted 1 line
drivers/net/amt.c +0 -0

[]

Quoted 10 lines

include/net/amt.h

Quoted 10 lines
drivers/net/amt.c +1 -1
@@ -959,7 +959,7 @@ static void amt_req_work(struct work_struct *work)
 	amt_update_gw_status(amt, AMT_STATUS_SENT_REQUEST, true);
 	spin_lock_bh(&amt->lock);
 out:
-	exp = min_t(u32, (1 * (1 << amt->req_cnt)), AMT_MAX_REQ_TIMEOUT);
+	exp = min_t(u32, (1 * BIT(amt->req_cnt)), AMT_MAX_REQ_TIMEOUT);
 	mod_delayed_work(amt_wq, &amt->req_wq, msecs_to_jiffies(exp * 1000));
 	spin_unlock_bh(&amt->lock);
 }
include/net/amt.h +0 -0

[]

Quoted 7 lines
Quoted 7 lines
include/net/amt.h +1 -1
@@ -354,7 +354,7 @@ struct amt_dev {
 #define AMT_MAX_GROUP		32
 #define AMT_MAX_SOURCE		128
 #define AMT_HSIZE_SHIFT		8
-#define AMT_HSIZE		(1 << AMT_HSIZE_SHIFT)
+#define AMT_HSIZE		BIT(AMT_HSIZE_SHIFT)
 
Quoted 7 lines

include/net/amt.h struct amt_dev { · line 360

Quoted 2 lines
include/net/amt.h +0 -0
 #define AMT_DISCOVERY_TIMEOUT	5000
 #define AMT_INIT_REQ_TIMEOUT	1

Even if the 2 replaced statements use shift operations, they do not look like bit manipulation: the first one is an exponential timeout, the 2nd one is an (hash) size. I think using the BIT() macro here will be confusing.

I agree.

I also believe one of the uses of amt->req_cnt is error prone.

	drivers/net/amt.c:946:  if (amt->req_cnt++ > AMT_MAX_REQ_COUNT) {

Combining a test and post increment is not a great style IMO. Is this really the intended behavior?

maintainer
#4 lore raw

2022. 5. 3. 오전 2:19에 Joe Perches 이(가) 쓴 글:

Quoted 1 line · Paolo Abeni

Hi Paolo and Joe,
Thanks a lot for the reviews!

Quoted 32 lines
Quoted 3 lines · Juhee Kang
Quoted 2 lines

Replace open code related to bit operation with BIT macros, which kernel provided. This patch provides no functional change.

[]

Quoted 1 line

drivers/net/amt.c

Quoted 1 line
drivers/net/amt.c +0 -0

[]

Quoted 10 lines

include/net/amt.h

Quoted 10 lines
drivers/net/amt.c +1 -1
@@ -959,7 +959,7 @@ static void amt_req_work(struct work_struct *work)
  	amt_update_gw_status(amt, AMT_STATUS_SENT_REQUEST, true);
  	spin_lock_bh(&amt->lock);
  out:
-	exp = min_t(u32, (1 * (1 << amt->req_cnt)), AMT_MAX_REQ_TIMEOUT);
+	exp = min_t(u32, (1 * BIT(amt->req_cnt)), AMT_MAX_REQ_TIMEOUT);
  	mod_delayed_work(amt_wq, &amt->req_wq, msecs_to_jiffies(exp * 1000));
  	spin_unlock_bh(&amt->lock);
  }
include/net/amt.h +0 -0

[]

Quoted 7 lines
Quoted 7 lines
include/net/amt.h +1 -1
@@ -354,7 +354,7 @@ struct amt_dev {
  #define AMT_MAX_GROUP		32
  #define AMT_MAX_SOURCE		128
  #define AMT_HSIZE_SHIFT		8
-#define AMT_HSIZE		(1 << AMT_HSIZE_SHIFT)
+#define AMT_HSIZE		BIT(AMT_HSIZE_SHIFT)
 
Quoted 7 lines

include/net/amt.h struct amt_dev { · line 360

Quoted 2 lines
include/net/amt.h +0 -0
  #define AMT_DISCOVERY_TIMEOUT	5000
  #define AMT_INIT_REQ_TIMEOUT	1

Even if the 2 replaced statements use shift operations, they do not look like bit manipulation: the first one is an exponential timeout, the 2nd one is an (hash) size. I think using the BIT() macro here will be confusing.

Quoted 8 lines

I agree.

I also believe one of the uses of amt->req_cnt is error prone.

	drivers/net/amt.c:946:  if (amt->req_cnt++ > AMT_MAX_REQ_COUNT) {

Combining a test and post increment is not a great style IMO. Is this really the intended behavior?

I agree that it would be better to avoid that style. I will send a patch for that after some bugfix.

Thanks a lot,
Taehee Yoo

Quoted 2 lines
author
#5 lore raw

Hello Paolo and Joe,

Thanks for the reviews!

Quoted 58 lines · Taehee Yoo

2022. 5. 3. 오전 2:19에 Joe Perches 이(가) 쓴 글:

Quoted 1 line · Paolo Abeni

Hi Paolo and Joe,
Thanks a lot for the reviews!

Quoted 2 lines
Quoted 2 lines · Juhee Kang
Quoted 1 line

Replace open code related to bit operation with BIT macros, which

kernel

Quoted 11 lines
Quoted 1 line
Quoted 1 line

provided. This patch provides no functional change.

[]

Quoted 1 line

drivers/net/amt.c

Quoted 1 line
drivers/net/amt.c +0 -0

[]

Quoted 7 lines

drivers/net/amt.c static void amt_req_work(struct work_struct *work) · line 963

Quoted 7 lines
drivers/net/amt.c +1 -1
@@ -959,7 +959,7 @@ static void amt_req_work(struct work_struct *work)
   amt_update_gw_status(amt, AMT_STATUS_SENT_REQUEST, true);
   spin_lock_bh(&amt->lock);
  out:
-  exp = min_t(u32, (1 * (1 << amt->req_cnt)), AMT_MAX_REQ_TIMEOUT);
+  exp = min_t(u32, (1 * BIT(amt->req_cnt)), AMT_MAX_REQ_TIMEOUT);
   mod_delayed_work(amt_wq, &amt->req_wq, msecs_to_jiffies(exp *

1000));

Quoted 19 lines
Quoted 3 lines

include/net/amt.h

Quoted 3 lines
drivers/net/amt.c +0 -0
   spin_unlock_bh(&amt->lock);
  }
include/net/amt.h +0 -0

[]

Quoted 7 lines
Quoted 7 lines
include/net/amt.h +1 -1
@@ -354,7 +354,7 @@ struct amt_dev {
  #define AMT_MAX_GROUP            32
  #define AMT_MAX_SOURCE           128
  #define AMT_HSIZE_SHIFT          8
-#define AMT_HSIZE         (1 << AMT_HSIZE_SHIFT)
+#define AMT_HSIZE         BIT(AMT_HSIZE_SHIFT)
 
Quoted 7 lines

include/net/amt.h struct amt_dev { · line 360

Quoted 2 lines
include/net/amt.h +0 -0
  #define AMT_DISCOVERY_TIMEOUT    5000
  #define AMT_INIT_REQ_TIMEOUT     1

Even if the 2 replaced statements use shift operations, they do not look like bit manipulation: the first one is an exponential timeout, the 2nd one is an (hash) size. I think using the BIT() macro here will be confusing.

Quoted 8 lines

I agree.

I also believe one of the uses of amt->req_cnt is error prone.

     drivers/net/amt.c:946:  if (amt->req_cnt++ > AMT_MAX_REQ_COUNT) {

Combining a test and post increment is not a great style IMO. Is this really the intended behavior?

I agree that it would be better to avoid that style. I will send a patch for that after some bugfix.

Thanks a lot,
Taehee Yoo

Quoted 2 lines
Signature · 2 lines
Best regards,
Juhee Kang