Skip to content

Commit

Permalink
lib/lzo/lzo1x_compress.c: replace ternary operator with min() and min…
Browse files Browse the repository at this point in the history
…_t()

Fix the following coccicheck warning:

lib/lzo/lzo1x_compress.c:54: WARNING opportunity for min().
lib/lzo/lzo1x_compress.c:329: WARNING opportunity for min().

min() and min_t() macro is defined in include/linux/minmax.h.  It avoids
multiple evaluations of the arguments when non-constant and performs
strict type-checking.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Jiangshan Yi <[email protected]>
Tested-by: Dave Rodgman <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Jiangshan Yi authored and akpm00 committed Jul 30, 2022
1 parent b09a7a0 commit a10c9ed
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/lzo/lzo1x_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ lzo1x_1_do_compress(const unsigned char *in, size_t in_len,

if (dv == 0 && bitstream_version) {
const unsigned char *ir = ip + 4;
const unsigned char *limit = ip_end
< (ip + MAX_ZERO_RUN_LENGTH + 1)
? ip_end : ip + MAX_ZERO_RUN_LENGTH + 1;
const unsigned char *limit = min(ip_end, ip + MAX_ZERO_RUN_LENGTH + 1);
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && \
defined(LZO_FAST_64BIT_MEMORY_ACCESS)
u64 dv64;
Expand Down Expand Up @@ -326,7 +324,7 @@ static int lzogeneric1x_1_compress(const unsigned char *in, size_t in_len,
data_start = op;

while (l > 20) {
size_t ll = l <= (m4_max_offset + 1) ? l : (m4_max_offset + 1);
size_t ll = min_t(size_t, l, m4_max_offset + 1);
uintptr_t ll_end = (uintptr_t) ip + ll;
if ((ll_end + ((t + ll) >> 5)) <= ll_end)
break;
Expand Down

0 comments on commit a10c9ed

Please sign in to comment.