amt: Use BIT macros instead of open codes
Subsystems (3)
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
@@ -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
@@ -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
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
Signed-off-by Juhee Kang <[email protected]>--- drivers/net/amt.c | 2 +- include/net/amt.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)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 +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
Paolo Abeni
maintainerHello,
Quoted 27 lines · Juhee Kang
Replace open code related to bit operation with BIT macros, which kernel provided. This patch provides no functional change.
Signed-off-by Juhee Kang <[email protected]>--- drivers/net/amt.c | 2 +- include/net/amt.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)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
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
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 1Even 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?
Taehee Yoo
maintainer2022. 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 1Even 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_cntis 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
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
-0spin_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 1Even 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_cntis 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 YooQuoted 2 lines
Signature · 2 lines
Best regards, Juhee Kang