Skip to content

Commit 09dce4c

Browse files
bgoing-micron-ossigaw
authored andcommitted
min: Cleaned up usage of MIN in favor of safer CCAN min.
Libnvme's util.c uses a combination of CCAN's min from minmax.h and the MIN defined in param.h. The CCAN implementation has typechecking and is more portable, whereas the param.h definition of MIN only exists on Linux. - Updating util.c to use CCAN's min implementation consistently. - Removing unused MIN definition in nbft.c. Signed-off-by: Broc Going <[email protected]>
1 parent cf0707a commit 09dce4c

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

libnvme/src/nvme/nbft.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include "private.h"
2020
#include "compiler-attributes.h"
2121

22-
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
23-
2422
static __u8 csum(const __u8 *buffer, ssize_t length)
2523
{
2624
int n;

libnvme/src/nvme/util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ static size_t copy_value(char *buf, size_t buflen, const char *value)
623623
/* Remove trailing " */
624624
val_len = strcspn(value, "\"");
625625

626-
memcpy(buf, value, MIN(val_len, buflen-1));
626+
memcpy(buf, value, min(val_len, buflen-1));
627627

628628
return val_len;
629629
}
@@ -694,7 +694,7 @@ size_t get_entity_version(char *buffer, size_t bufsz)
694694
if (name_len) {
695695
/* Append a space */
696696
buffer[num_bytes++] = ' ';
697-
name_len = MIN(name_len, bufsz);
697+
name_len = min(name_len, bufsz);
698698
memcpy(&buffer[num_bytes], name, name_len);
699699
bufsz -= name_len;
700700
num_bytes += name_len;
@@ -703,7 +703,7 @@ size_t get_entity_version(char *buffer, size_t bufsz)
703703
if (ver_id_len) {
704704
/* Append a space */
705705
buffer[num_bytes++] = ' ';
706-
ver_id_len = MIN(ver_id_len, bufsz);
706+
ver_id_len = min(ver_id_len, bufsz);
707707
memcpy(&buffer[num_bytes], ver_id, ver_id_len);
708708
bufsz -= ver_id_len;
709709
num_bytes += ver_id_len;

0 commit comments

Comments
 (0)