Browse Source

[infiniband] Use generic base16 functions for SRP

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
d6f79d6b6e
1 changed files with 7 additions and 9 deletions
  1. 7
    9
      src/net/infiniband/ib_srp.c

+ 7
- 9
src/net/infiniband/ib_srp.c View File

32
 
32
 
33
 #include <stdlib.h>
33
 #include <stdlib.h>
34
 #include <errno.h>
34
 #include <errno.h>
35
+#include <ipxe/base16.h>
35
 #include <ipxe/srp.h>
36
 #include <ipxe/srp.h>
36
 #include <ipxe/infiniband.h>
37
 #include <ipxe/infiniband.h>
37
 #include <ipxe/ib_cmrc.h>
38
 #include <ipxe/ib_cmrc.h>
78
 				      unsigned int size_flags ) {
79
 				      unsigned int size_flags ) {
79
 	size_t size = ( size_flags & ~IB_SRP_PARSE_FLAG_MASK );
80
 	size_t size = ( size_flags & ~IB_SRP_PARSE_FLAG_MASK );
80
 	size_t rp_comp_len = strlen ( rp_comp );
81
 	size_t rp_comp_len = strlen ( rp_comp );
81
-	char buf[3];
82
-	char *buf_end;
82
+	int decoded_size;
83
 
83
 
84
 	/* Allow optional components to be empty */
84
 	/* Allow optional components to be empty */
85
 	if ( ( rp_comp_len == 0 ) &&
85
 	if ( ( rp_comp_len == 0 ) &&
91
 		return -EINVAL_BYTE_STRING_LEN;
91
 		return -EINVAL_BYTE_STRING_LEN;
92
 
92
 
93
 	/* Parse byte string */
93
 	/* Parse byte string */
94
-	for ( ; size ; size--, rp_comp += 2, bytes++ ) {
95
-		memcpy ( buf, rp_comp, 2 );
96
-		buf[2] = '\0';
97
-		*bytes = strtoul ( buf, &buf_end, 16 );
98
-		if ( buf_end != &buf[2] )
99
-			return -EINVAL_BYTE_STRING;
100
-	}
94
+	decoded_size = base16_decode ( rp_comp, bytes );
95
+	if ( decoded_size < 0 )
96
+		return decoded_size;
97
+	assert ( decoded_size == size );
98
+
101
 	return 0;
99
 	return 0;
102
 }
100
 }
103
 
101
 

Loading…
Cancel
Save