staging: qlge: Fix indentation issue under long for loop
Subsystems (3)
PATCH v3 1/1 staging: qlge: Fix indentation issue under long for loop
Fix indentation issue to adhere to Linux kernel coding style, Issue found by checkpatch. Change the long for loop into 3 lines. And optimize by avoiding the multiplication.
---
v2:
- Change the long for loop into 3 lines.
v3:
- Align page_entries in the for loop to open parenthesis.
- Optimize by avoiding the multiplication.
drivers/staging/qlge/qlge_main.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/staging/qlge/qlge_main.c +12 -8
@@ -3007,10 +3007,12 @@ static int qlge_start_rx_ring(struct qlge_adapter *qdev, struct rx_ring *rx_ring tmp = (u64 )rx_ring->lbq.base_dma; base_indirect_ptr = rx_ring->lbq.base_indirect; -for (page_entries =0 ; page_entries < -MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); page_entries++) - base_indirect_ptr[page_entries] = -cpu_to_le64 (tmp + (page_entries *DB_PAGE_SIZE )); +for (page_entries =0 ; + page_entries <MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); + page_entries++) { + base_indirect_ptr[page_entries] =cpu_to_le64 (tmp); + tmp +=DB_PAGE_SIZE ; + } cqicb->lbq_addr =cpu_to_le64 (rx_ring->lbq.base_indirect_dma); cqicb->lbq_buf_size =cpu_to_le16 (QLGE_FIT16 (qdev->lbq_buf_size));
@@ -3022,10 +3024,12 @@ static int qlge_start_rx_ring(struct qlge_adapter *qdev, struct rx_ring *rx_ring tmp = (u64 )rx_ring->sbq.base_dma; base_indirect_ptr = rx_ring->sbq.base_indirect; -for (page_entries =0 ; page_entries < -MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); page_entries++) - base_indirect_ptr[page_entries] = -cpu_to_le64 (tmp + (page_entries *DB_PAGE_SIZE )); +for (page_entries =0 ; + page_entries <MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); + page_entries++) { + base_indirect_ptr[page_entries] =cpu_to_le64 (tmp); + tmp +=DB_PAGE_SIZE ; + } cqicb->sbq_addr =cpu_to_le64 (rx_ring->sbq.base_indirect_dma); cqicb->sbq_buf_size =cpu_to_le16 (SMALL_BUFFER_SIZE );
Signature · 1 line
2.25.1
Greg Kroah-Hartman
maintainerQuoted 11 lines · Binyi Han
Fix indentation issue to adhere to Linux kernel coding style, Issue found by checkpatch. Change the long for loop into 3 lines. And optimize by avoiding the multiplication.
Signed-off-by Binyi Han <[email protected]>---
v2:
- Change the long for loop into 3 lines.
v3:
- Alignpage_entriesin the for loop to open parenthesis.
- Optimize by avoiding the multiplication.
Please do not mix coding style fixes with "optimizations" or logical changes. This should be multiple patches.
Also, did you test this change on real hardware? At first glance, it's not obvious that the code is still doing the same thing, so "proof" of that would be nice to have.
thanks,
greg k-h
Quoted 13 lines · Greg Kroah-Hartman
Quoted 11 lines · Binyi Han
Fix indentation issue to adhere to Linux kernel coding style, Issue found by checkpatch. Change the long for loop into 3 lines. And optimize by avoiding the multiplication.
Signed-off-by Binyi Han <[email protected]>---
v2:
- Change the long for loop into 3 lines.
v3:
- Alignpage_entriesin the for loop to open parenthesis.
- Optimize by avoiding the multiplication.
Quoted 6 lines
Please do not mix coding style fixes with "optimizations" or logical changes. This should be multiple patches.
Also, did you test this change on real hardware? At first glance, it's not obvious that the code is still doing the same thing, so "proof" of that would be nice to have.
I read the code and suggested the optimization. It's the same logic.
Greg Kroah-Hartman
maintainerQuoted 14 lines · Joe Perches
Quoted 13 lines · Greg Kroah-Hartman
Quoted 11 lines · Binyi Han
Fix indentation issue to adhere to Linux kernel coding style, Issue found by checkpatch. Change the long for loop into 3 lines. And optimize by avoiding the multiplication.
Signed-off-by Binyi Han <[email protected]>---
v2:
- Change the long for loop into 3 lines.
v3:
- Alignpage_entriesin the for loop to open parenthesis.
- Optimize by avoiding the multiplication.
Quoted 10 lines
Quoted 6 lines
Please do not mix coding style fixes with "optimizations" or logical changes. This should be multiple patches.
Also, did you test this change on real hardware? At first glance, it's not obvious that the code is still doing the same thing, so "proof" of that would be nice to have.
I read the code and suggested the optimization. It's the same logic.
I appreciate the review, but it looks quite different from the original so it should be 2 different patches, one for coding style changes, and the second for the "optimization".
thanks,
greg k-h
Quoted 15 lines · Greg Kroah-Hartman
Quoted 14 lines · Joe Perches
Quoted 13 lines · Greg Kroah-Hartman
Quoted 11 lines · Binyi Han
Fix indentation issue to adhere to Linux kernel coding style, Issue found by checkpatch. Change the long for loop into 3 lines. And optimize by avoiding the multiplication.
Signed-off-by Binyi Han <[email protected]>---
v2:
- Change the long for loop into 3 lines.
v3:
- Alignpage_entriesin the for loop to open parenthesis.
- Optimize by avoiding the multiplication.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Please do not mix coding style fixes with "optimizations" or logical changes. This should be multiple patches.
Also, did you test this change on real hardware? At first glance, it's not obvious that the code is still doing the same thing, so "proof" of that would be nice to have.
I don't have access to a real hardware, so can't provide a "proof" of that. I agree with Joe that's the same logic, and it compiles ok. But I understand if you don't apply this patch, it's more safe with some testing.
Quoted 5 lines
Quoted 4 lines
I read the code and suggested the optimization. It's the same logic.
Quoted 7 lines
I appreciate the review, but it looks quite different from the original so it should be 2 different patches, one for coding style changes, and the second for the "optimization".
thanks,
greg k-h
Thank you for the review. I sent a patchset, following the instruction here:
https://kernelnewbies.org/FirstKernelPatch
And I didn't find a good way to send a patchset by mutt in a single command, so I run "mutt -H PatchFile" several times to send it, and I hope that is okay.
Best,
Binyi
Quoted 3 lines · Binyi Han
Fix indentation issue to adhere to Linux kernel coding style, Issue found by checkpatch. Change the long for loop into 3 lines. And optimize by avoiding the multiplication.
There is no possible way this optimization helps benchmarks. Better to focus on readability.
Quoted 19 lines
Signed-off-by Binyi Han <[email protected]>---
v2:
- Change the long for loop into 3 lines.
v3:
- Alignpage_entriesin the for loop to open parenthesis.
- Optimize by avoiding the multiplication.drivers/staging/qlge/qlge_main.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)drivers/staging/qlge/qlge_main.c +0
-0@@ -3007,10 +3007,12 @@ static int qlge_start_rx_ring(struct qlge_adapter *qdev, struct rx_ring *rx_ring tmp = (u64 )rx_ring->lbq.base_dma; base_indirect_ptr = rx_ring->lbq.base_indirect;
drivers/staging/qlge/qlge_main.c static int qlge_start_rx_ring(struct qlge_adapter *qdev, struct rx_ring *rx_ring · line 3014
Quoted 10 lines
drivers/staging/qlge/qlge_main.c +5
-4-for (page_entries =0 ; page_entries < -MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); page_entries++) - base_indirect_ptr[page_entries] = -cpu_to_le64 (tmp + (page_entries *DB_PAGE_SIZE )); +for (page_entries =0 ; + page_entries <MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); + page_entries++) { + base_indirect_ptr[page_entries] =cpu_to_le64 (tmp); + tmp +=DB_PAGE_SIZE ;
I've previously said that using "int i;" is clearer here. You would kind of expect "page_entries" to be the number of entries, so it's kind of misleading. In other words, it's not just harmless wordiness and needless exposition, it's actively bad.
I would probably just put it on one line:
for (i = 0; i MAX_DB_PAGES_PER_BQ(QLGE_BQ_LEN); i++) base_indirect_ptr[i] = cpu_to_le64(tmp + (i * DB_PAGE_SIZE));
But if you want to break it up you could do:
for (i = 0; i MAX_DB_PAGES_PER_BQ(QLGE_BQ_LEN); i++) base_indirect_ptr[i] = cpu_to_le64(tmp + (i * DB_PAGE_SIZE));
"tmp" is kind of a bad name. Also "base_indirect_ptr" would be better as "base_indirect".
regards,
dan carpenter
Quoted 7 lines · Dan Carpenter
Quoted 3 lines · Binyi Han
Fix indentation issue to adhere to Linux kernel coding style, Issue found by checkpatch. Change the long for loop into 3 lines. And optimize by avoiding the multiplication.
There is no possible way this optimization helps benchmarks. Better to focus on readability.
I think removing the multiply _improves_ readability.
Quoted 1 line
drivers/staging/qlge/qlge_main.c
Quoted 1 line
drivers/staging/qlge/qlge_main.c +0
-0
[]
Quoted 4 lines
Quoted 4 lines
drivers/staging/qlge/qlge_main.c +0
-0@@ -3007,10 +3007,12 @@ static int qlge_start_rx_ring(struct qlge_adapter *qdev, struct rx_ring *rx_ring tmp = (u64 )rx_ring->lbq.base_dma; base_indirect_ptr = rx_ring->lbq.base_indirect;
Quoted 14 lines
drivers/staging/qlge/qlge_main.c static int qlge_start_rx_ring(struct qlge_adapter *qdev, struct rx_ring *rx_ring · line 3014
Quoted 9 lines
drivers/staging/qlge/qlge_main.c +5
-4-for (page_entries =0 ; page_entries < -MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); page_entries++) - base_indirect_ptr[page_entries] = -cpu_to_le64 (tmp + (page_entries *DB_PAGE_SIZE )); +for (page_entries =0 ; + page_entries <MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); + page_entries++) { + base_indirect_ptr[page_entries] =cpu_to_le64 (tmp); + tmp +=DB_PAGE_SIZE ;I've previously said that using "int i;" is clearer here. You would kind of expect "
page_entries" to be the number of entries, so it's kind of misleading. In other words, it's not just harmless wordiness and needless exposition, it's actively bad.
Likely true.
Quoted 5 lines
I would probably just put it on one line:
for (i = 0; i MAX_DB_PAGES_PER_BQ(QLGE_BQ_LEN); i++) base_indirect_ptr[i] = cpu_to_le64(tmp + (i * DB_PAGE_SIZE));
Quoted 8 lines
But if you want to break it up you could do:
for (i = 0; i MAX_DB_PAGES_PER_BQ(QLGE_BQ_LEN); i++) base_indirect_ptr[i] = cpu_to_le64(tmp + (i * DB_PAGE_SIZE));"tmp" is kind of a bad name. Also "
base_indirect_ptr" would be better as "base_indirect".
tmp is a poor name here. Maybe dma would be better.
MAX_DB_PAGES_PER_BQ(QLGE_BQ_LEN) is also a poorly named macro where all the existing uses are QLGE_BQ_LEN.
And there's base_indirect_ptr and base_indirect_dma in the struct so just base_indirect might not be the best.
tmp = (u64)rx_ring->lbq.base_dma; base_indirect_ptr = rx_ring->lbq.base_indirect;
And clarity is good.
Though here, clarity to value for effort though is dubious.
btw: this code got moved to staging 3 years ago.
Maybe it's getting closer to removal time.
Quoted 32 lines · Joe Perches
Quoted 7 lines · Dan Carpenter
Quoted 3 lines · Binyi Han
Fix indentation issue to adhere to Linux kernel coding style, Issue found by checkpatch. Change the long for loop into 3 lines. And optimize by avoiding the multiplication.
There is no possible way this optimization helps benchmarks. Better to focus on readability.
I think removing the multiply _improves_ readability.
Quoted 1 line
drivers/staging/qlge/qlge_main.c
Quoted 1 line
drivers/staging/qlge/qlge_main.c +0
-0[]
Quoted 4 lines
Quoted 4 lines
drivers/staging/qlge/qlge_main.c +0
-0@@ -3007,10 +3007,12 @@ static int qlge_start_rx_ring(struct qlge_adapter *qdev, struct rx_ring *rx_ring tmp = (u64 )rx_ring->lbq.base_dma; base_indirect_ptr = rx_ring->lbq.base_indirect;Quoted 14 lines
drivers/staging/qlge/qlge_main.c static int qlge_start_rx_ring(struct qlge_adapter *qdev, struct rx_ring *rx_ring · line 3014
Quoted 9 lines
drivers/staging/qlge/qlge_main.c +5
-4-for (page_entries =0 ; page_entries < -MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); page_entries++) - base_indirect_ptr[page_entries] = -cpu_to_le64 (tmp + (page_entries *DB_PAGE_SIZE )); +for (page_entries =0 ; + page_entries <MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); + page_entries++) { + base_indirect_ptr[page_entries] =cpu_to_le64 (tmp); + tmp +=DB_PAGE_SIZE ;I've previously said that using "int i;" is clearer here. You would kind of expect "
page_entries" to be the number of entries, so it's kind of misleading. In other words, it's not just harmless wordiness and needless exposition, it's actively bad.
Quoted 2 lines
Likely true.
I agree it could be misleading. But if "page_entries" is in the for loop I would assume it's some kind of index variable, and still it provides some information (page entry) for the index, probably page_entry_idx could be better name but still makes the for loop a very long one. I guess I would leave it be.
Quoted 7 lines
Quoted 7 lines
I would probably just put it on one line:
for (i = 0; i MAX_DB_PAGES_PER_BQ(QLGE_BQ_LEN); i++) base_indirect_ptr[i] = cpu_to_le64(tmp + (i * DB_PAGE_SIZE));But if you want to break it up you could do:
Quoted 9 lines
Quoted 6 lines
for (i = 0; i MAX_DB_PAGES_PER_BQ(QLGE_BQ_LEN); i++) base_indirect_ptr[i] = cpu_to_le64(tmp + (i * DB_PAGE_SIZE));"tmp" is kind of a bad name. Also "
base_indirect_ptr" would be better as "base_indirect".tmp is a poor name here. Maybe dma would be better.
Yeah, I think so.
Quoted 9 lines
MAX_DB_PAGES_PER_BQ(QLGE_BQ_LEN)is also a poorly named macro where all the existing uses areQLGE_BQ_LEN.And there's
base_indirect_ptrandbase_indirect_dmain the struct so justbase_indirectmight not be the best.tmp = (u64)rx_ring->lbq.base_dma; base_indirect_ptr = rx_ring->lbq.base_indirect;
Quoted 7 lines
And clarity is good.
Though here, clarity to value for effort though is dubious.btw: this code got moved to staging 3 years ago.
Maybe it's getting closer to removal time.
That sounds sad.
Thank you for reviewing!
Best,
Binyi
Quoted 21 lines · binyi
Quoted 20 lines · Joe Perches
Quoted 18 lines · Dan Carpenter
drivers/staging/qlge/qlge_main.c static int qlge_start_rx_ring(struct qlge_adapter *qdev, struct rx_ring *rx_ring · line 3014
Quoted 13 lines
drivers/staging/qlge/qlge_main.c +5
-4@@ -3007,10 +3007,12 @@ static int qlge_start_rx_ring(struct qlge_adapter *qdev, struct rx_ring *rx_ring tmp = (u64 )rx_ring->lbq.base_dma; base_indirect_ptr = rx_ring->lbq.base_indirect; -for (page_entries =0 ; page_entries < -MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); page_entries++) - base_indirect_ptr[page_entries] = -cpu_to_le64 (tmp + (page_entries *DB_PAGE_SIZE )); +for (page_entries =0 ; + page_entries <MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); + page_entries++) { + base_indirect_ptr[page_entries] =cpu_to_le64 (tmp); + tmp +=DB_PAGE_SIZE ;I've previously said that using "int i;" is clearer here. You would kind of expect "
page_entries" to be the number of entries, so it's kind of misleading. In other words, it's not just harmless wordiness and needless exposition, it's actively bad.
Quoted 8 lines
Quoted 2 lines
Likely true.
I agree it could be misleading. But if "
page_entries" is in the for loop I would assume it's some kind of index variable, and still it provides some information (page entry) for the index, probablypage_entry_idxcould be better name but still makes the for loop a very long one. I guess I would leave it be.
It does not "provide some information". That's what I was trying to explain. It's the opposite of information. Information is good. No information is neutral. But anti-information is bad.
Like there are so many times in life where you listen to someone and you think you are learning something but you end up stupider than before. They have done studies on TV news where it can make you less informed than people who don't watch it. And other studies say if you stop watching TV news for even a month then your brain starts to heal.
I don't really care about one line of code, but what I'm trying to say is learn to recognize anti-information and delete it. Comments for example are often useless.
regards,
dan carpenter
Quoted 31 lines · Dan Carpenter
Quoted 21 lines · binyi
Quoted 20 lines · Joe Perches
Quoted 18 lines · Dan Carpenter
drivers/staging/qlge/qlge_main.c static int qlge_start_rx_ring(struct qlge_adapter *qdev, struct rx_ring *rx_ring · line 3014
Quoted 13 lines
drivers/staging/qlge/qlge_main.c +5
-4@@ -3007,10 +3007,12 @@ static int qlge_start_rx_ring(struct qlge_adapter *qdev, struct rx_ring *rx_ring tmp = (u64 )rx_ring->lbq.base_dma; base_indirect_ptr = rx_ring->lbq.base_indirect; -for (page_entries =0 ; page_entries < -MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); page_entries++) - base_indirect_ptr[page_entries] = -cpu_to_le64 (tmp + (page_entries *DB_PAGE_SIZE )); +for (page_entries =0 ; + page_entries <MAX_DB_PAGES_PER_BQ (QLGE_BQ_LEN ); + page_entries++) { + base_indirect_ptr[page_entries] =cpu_to_le64 (tmp); + tmp +=DB_PAGE_SIZE ;I've previously said that using "int i;" is clearer here. You would kind of expect "
page_entries" to be the number of entries, so it's kind of misleading. In other words, it's not just harmless wordiness and needless exposition, it's actively bad.Quoted 8 lines
Quoted 2 lines
Likely true.
I agree it could be misleading. But if "
page_entries" is in the for loop I would assume it's some kind of index variable, and still it provides some information (page entry) for the index, probablypage_entry_idxcould be better name but still makes the for loop a very long one. I guess I would leave it be.
Quoted 3 lines
It does not "provide some information". That's what I was trying to explain. It's the opposite of information. Information is good. No information is neutral. But anti-information is bad.
I see. Indeed, being neutral is better than being bad.
Quoted 9 lines
Like there are so many times in life where you listen to someone and you think you are learning something but you end up stupider than before. They have done studies on TV news where it can make you less informed than people who don't watch it. And other studies say if you stop watching TV news for even a month then your brain starts to heal.
I don't really care about one line of code, but what I'm trying to say is learn to recognize anti-information and delete it. Comments for example are often useless.
It makes more sense to me now. Thanks for explaining!
Best,
Binyi