Skip to content

Commit b09dc68

Browse files
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 87540df commit b09dc68

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
@@ -613,7 +613,7 @@ static size_t copy_value(char *buf, size_t buflen, const char *value)
613613
/* Remove trailing " */
614614
val_len = strcspn(value, "\"");
615615

616-
memcpy(buf, value, MIN(val_len, buflen-1));
616+
memcpy(buf, value, min(val_len, buflen-1));
617617

618618
return val_len;
619619
}
@@ -684,7 +684,7 @@ size_t get_entity_version(char *buffer, size_t bufsz)
684684
if (name_len) {
685685
/* Append a space */
686686
buffer[num_bytes++] = ' ';
687-
name_len = MIN(name_len, bufsz);
687+
name_len = min(name_len, bufsz);
688688
memcpy(&buffer[num_bytes], name, name_len);
689689
bufsz -= name_len;
690690
num_bytes += name_len;
@@ -693,7 +693,7 @@ size_t get_entity_version(char *buffer, size_t bufsz)
693693
if (ver_id_len) {
694694
/* Append a space */
695695
buffer[num_bytes++] = ' ';
696-
ver_id_len = MIN(ver_id_len, bufsz);
696+
ver_id_len = min(ver_id_len, bufsz);
697697
memcpy(&buffer[num_bytes], ver_id, ver_id_len);
698698
bufsz -= ver_id_len;
699699
num_bytes += ver_id_len;

0 commit comments

Comments
 (0)