Skip to contentSkip to conversation

staging: gpib: Fix inadvertent negative shift

PATCH In review Dave Penkler 2 participants 3 messages Jan 16, 2025 – Jan 17, 2025 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: gpib: Fix inadvertent negative shift

During the initial checkpatch cleanup, when removing blanks after open parentheses, a minus sign in the argument of a shift operation was deleted by mistake. This transformed a pre-decrement operation into a negation.

The result of a negative shift is undefined and a warning was signalled by sparse.

Restore the pre-decrement operation.

Fixes 6c52d5e3cde2 ("staging: gpib: Add common include files for GPIB drivers")
---
 drivers/staging/gpib/include/amcc5920.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gpib/include/amcc5920.h +1 -1
index 766b3799223f..7a88bd282feb 100644
@@ -22,7 +22,7 @@ static const int bits_per_region = 8;
 
 static inline uint32_t amcc_wait_state_bits(unsigned int region, unsigned int num_wait_states)
 {
-	return (num_wait_states & 0x7) << (-region * bits_per_region);
+	return (num_wait_states & 0x7) << (--region * bits_per_region);
 };
 
 enum amcc_prefetch_bits {
Signature · 1 line
2.47.1
#1 lore raw
Quoted 21 lines · On Thu, 16 Jan 2025 12:00:14 +0100 Dave Penkler <[email protected]> wrote:

During the initial checkpatch cleanup, when removing blanks after open parentheses, a minus sign in the argument of a shift operation was deleted by mistake. This transformed a pre-decrement operation into a negation.

The result of a negative shift is undefined and a warning was signalled by sparse.

Restore the pre-decrement operation.

Fixes 6c52d5e3cde2 ("staging: gpib: Add common include files for GPIB drivers")
---
 drivers/staging/gpib/include/amcc5920.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gpib/include/amcc5920.h +0 -0
index 766b3799223f..7a88bd282feb 100644

drivers/staging/gpib/include/amcc5920.h static const int bits_per_region = 8; · line 25

Quoted 5 lines
drivers/staging/gpib/include/amcc5920.h +1 -1
@@ -22,7 +22,7 @@ static const int bits_per_region = 8;
 
 static inline uint32_t amcc_wait_state_bits(unsigned int region, unsigned int num_wait_states)
 {
-	return (num_wait_states & 0x7) << (-region * bits_per_region);
+	return (num_wait_states & 0x7) << (--region * bits_per_region);

It would be much better to use (region - 1).

David

Quoted 3 lines
drivers/staging/gpib/include/amcc5920.h +0 -0
 };
 
 enum amcc_prefetch_bits {
#2 lore raw
Quoted 25 lines · David Laight
Quoted 22 lines · On Thu, 16 Jan 2025 12:00:14 +0100 Dave Penkler <[email protected]> wrote:

During the initial checkpatch cleanup, when removing blanks after open parentheses, a minus sign in the argument of a shift operation was deleted by mistake. This transformed a pre-decrement operation into a negation.

The result of a negative shift is undefined and a warning was signalled by sparse.

Restore the pre-decrement operation.

Fixes 6c52d5e3cde2 ("staging: gpib: Add common include files for GPIB drivers")
---
 drivers/staging/gpib/include/amcc5920.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gpib/include/amcc5920.h +0 -0
index 766b3799223f..7a88bd282feb 100644
@@ -22,7 +22,7 @@ static const int bits_per_region = 8;
 
Quoted 6 lines

drivers/staging/gpib/include/amcc5920.h static const int bits_per_region = 8; · line 25

Quoted 4 lines
drivers/staging/gpib/include/amcc5920.h +1 -1
 static inline uint32_t amcc_wait_state_bits(unsigned int region, unsigned int num_wait_states)
 {
-	return (num_wait_states & 0x7) << (-region * bits_per_region);
+	return (num_wait_states & 0x7) << (--region * bits_per_region);

It would be much better to use (region - 1).

Hi,
You are right. I will send a separate patch to change this instance and all the others in the file.
cheers,
-dave