replace if with min
Subsystems (3)
PATCH 1/1 replace if with min
Replace if with min in order to make code more clean.
--- drivers/crypto/nx/nx-842.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/crypto/nx/nx-842.c +1 -2
@@ -134,8 +134,7 @@ EXPORT_SYMBOL_GPL(nx842_crypto_exit);static void check_constraints (struct nx842_constraints *c) {/* limit maximum, to always have enough bounce buffer to decompress */ -if (c->maximum >BOUNCE_BUFFER_SIZE ) - c->maximum =BOUNCE_BUFFER_SIZE ; + c->maximum =min (c->maximum,BOUNCE_BUFFER_SIZE ); }static int nx842_crypto_add_header (struct nx842_crypto_header *hdr,u8 *buf)
Signature · 1 line
2.25.1
Salah Triki <[email protected]> a écrit :
Quoted 12 lines
Replace if with min in order to make code more clean.
Signed-off-by Salah Triki <[email protected]>--- drivers/crypto/nx/nx-842.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/crypto/nx/nx-842.c +0
-0
drivers/crypto/nx/nx-842.c EXPORT_SYMBOL_GPL(nx842_crypto_exit); · line 137
Quoted 6 lines
drivers/crypto/nx/nx-842.c +1
-2@@ -134,8 +134,7 @@ EXPORT_SYMBOL_GPL(nx842_crypto_exit);static void check_constraints (struct nx842_constraints *c) {/* limit maximum, to always have enough bounce buffer to decompress */ -if (c->maximum >BOUNCE_BUFFER_SIZE ) - c->maximum =BOUNCE_BUFFER_SIZE ; + c->maximum =min (c->maximum,BOUNCE_BUFFER_SIZE );
For me the code is less clear with this change, and in addition it slightly changes the behaviour. Before, the write was done only when the value was changing. Now you rewrite the value always, even when it doesn't change.
Quoted 5 lines
drivers/crypto/nx/nx-842.c +0
-1}static int nx842_crypto_add_header (struct nx842_crypto_header *hdr,u8 *buf) --2.25.1
Quoted 18 lines · Christophe Leroy
Salah Triki <[email protected]> a écrit :
drivers/crypto/nx/nx-842.c EXPORT_SYMBOL_GPL(nx842_crypto_exit); · line 138
Quoted 12 lines
Replace if with min in order to make code more clean.
drivers/crypto/nx/nx-842.c +1
-2@@ -134,8 +134,7 @@ EXPORT_SYMBOL_GPL(nx842_crypto_exit);static void check_constraints (struct nx842_constraints *c) {/* limit maximum, to always have enough bounce buffer to decompress */ -if (c->maximum >BOUNCE_BUFFER_SIZE ) - c->maximum =BOUNCE_BUFFER_SIZE ; + c->maximum =min (c->maximum,BOUNCE_BUFFER_SIZE );For me the code is less clear with this change, and in addition it slightly changes the behaviour. Before, the write was done only when the value was changing. Now you rewrite the value always, even when it doesn't change.
In both cases the compiler can decide to either write it more often than strictly needed, depending on what it thinks best (and it usually has better estimates than the programmer). The behaviour is identical (and the generated machine code is as well, in my testing).
The field name "maximum" is not the best choice, which makes the code read a bit funny ("the min of max"), but the comment makes things pretty clear.
Segher