Browse Source

qcacmn: Perform minor cleanup of qdf_*_parse APIs

Perform the following cleanup items for qdf_*_parse() APIs:
 1) Many qdf_*_parse APIs use a custom left-trim function called
    qdf_skip_whitespace(). Recently, qdf_str_left_trim was added,
    so use this function instead.
 2) Remove 'const' from 'const char *' parameters. 'const' protects
    modification of the pointer, which is already duplicated for the
    function call. Since the qdf_*_parse() APIs modify the pointer
    parameter anyway, using const is incorrect (and should have failed
    compilation).
 3) Ensure the public qdf_*_parse APIs are properly exported.

Change-Id: I89725c68cc0d61a66fe95ef02fa2deda110411ac
CRs-Fixed: 2185978
Dustin Brown 7 years ago
parent
commit
89a217419e
2 changed files with 38 additions and 59 deletions
  1. 8 8
      qdf/inc/qdf_types.h
  2. 30 51
      qdf/src/qdf_types.c

+ 8 - 8
qdf/inc/qdf_types.h

@@ -670,7 +670,7 @@ typedef enum {
  *
  * Return: QDF_STATUS
  */
-QDF_STATUS qdf_bool_parse(const char *bool_str, bool *out_bool);
+QDF_STATUS qdf_bool_parse(char *bool_str, bool *out_bool);
 
 /**
  * qdf_int32_parse() - parse the given string as a 32-bit signed integer
@@ -683,7 +683,7 @@ QDF_STATUS qdf_bool_parse(const char *bool_str, bool *out_bool);
  *
  * Return: QDF_STATUS
  */
-QDF_STATUS qdf_int32_parse(const char *int_str, int32_t *out_int);
+QDF_STATUS qdf_int32_parse(char *int_str, int32_t *out_int);
 
 /**
  * qdf_uint32_parse() - parse the given string as a 32-bit unsigned integer
@@ -696,7 +696,7 @@ QDF_STATUS qdf_int32_parse(const char *int_str, int32_t *out_int);
  *
  * Return: QDF_STATUS
  */
-QDF_STATUS qdf_uint32_parse(const char *int_str, uint32_t *out_int);
+QDF_STATUS qdf_uint32_parse(char *int_str, uint32_t *out_int);
 
 /**
  * qdf_int64_parse() - parse the given string as a 64-bit signed integer
@@ -709,7 +709,7 @@ QDF_STATUS qdf_uint32_parse(const char *int_str, uint32_t *out_int);
  *
  * Return: QDF_STATUS
  */
-QDF_STATUS qdf_int64_parse(const char *int_str, int64_t *out_int);
+QDF_STATUS qdf_int64_parse(char *int_str, int64_t *out_int);
 
 /**
  * qdf_uint64_parse() - parse the given string as a 64-bit unsigned integer
@@ -722,7 +722,7 @@ QDF_STATUS qdf_int64_parse(const char *int_str, int64_t *out_int);
  *
  * Return: QDF_STATUS
  */
-QDF_STATUS qdf_uint64_parse(const char *int_str, uint64_t *out_int);
+QDF_STATUS qdf_uint64_parse(char *int_str, uint64_t *out_int);
 
 #define QDF_MAC_ADDR_SIZE 6
 #define QDF_MAC_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
@@ -757,7 +757,7 @@ struct qdf_mac_addr {
  *
  * Return: QDF_STATUS
  */
-QDF_STATUS qdf_mac_parse(const char *mac_str, struct qdf_mac_addr *out_addr);
+QDF_STATUS qdf_mac_parse(char *mac_str, struct qdf_mac_addr *out_addr);
 
 #define QDF_IPV4_ADDR_SIZE 4
 #define QDF_IPV4_ADDR_STR "%d.%d.%d.%d"
@@ -790,7 +790,7 @@ struct qdf_ipv4_addr {
  *
  * Return: QDF_STATUS
  */
-QDF_STATUS qdf_ipv4_parse(const char *ipv4_str, struct qdf_ipv4_addr *out_addr);
+QDF_STATUS qdf_ipv4_parse(char *ipv4_str, struct qdf_ipv4_addr *out_addr);
 
 #define QDF_IPV6_ADDR_SIZE 16
 #define QDF_IPV6_ADDR_HEXTET_COUNT 8
@@ -833,7 +833,7 @@ struct qdf_ipv6_addr {
  *
  * Return: QDF_STATUS
  */
-QDF_STATUS qdf_ipv6_parse(const char *ipv6_str, struct qdf_ipv6_addr *out_addr);
+QDF_STATUS qdf_ipv6_parse(char *ipv6_str, struct qdf_ipv6_addr *out_addr);
 
 #define QDF_MAX_NUM_CHAN   (128)
 

+ 30 - 51
qdf/src/qdf_types.c

@@ -19,10 +19,11 @@
 #include "qdf_mem.h"
 #include "qdf_module.h"
 #include "qdf_status.h"
+#include "qdf_str.h"
 #include "qdf_trace.h"
 #include "qdf_types.h"
 
-static QDF_STATUS qdf_consume_char(const char **str, char c)
+static QDF_STATUS qdf_consume_char(char **str, char c)
 {
 	if ((*str)[0] != c)
 		return QDF_STATUS_E_FAILURE;
@@ -32,32 +33,7 @@ static QDF_STATUS qdf_consume_char(const char **str, char c)
 	return QDF_STATUS_SUCCESS;
 }
 
-static QDF_STATUS qdf_consume_whitespace(const char **str, char *c)
-{
-	switch ((*str)[0]) {
-	case ' ':
-	case '\t':
-	case '\n':
-	case '\r':
-		*c = (*str)[0];
-		(*str)++;
-		return QDF_STATUS_SUCCESS;
-	default:
-		return QDF_STATUS_E_FAILURE;
-	}
-}
-
-static void qdf_skip_whitespace(const char **str)
-{
-	QDF_STATUS status;
-	char c;
-
-	do {
-		status = qdf_consume_whitespace(str, &c);
-	} while (QDF_IS_STATUS_SUCCESS(status));
-}
-
-static QDF_STATUS qdf_consume_dec(const char **str, uint8_t *out_digit)
+static QDF_STATUS qdf_consume_dec(char **str, uint8_t *out_digit)
 {
 	uint8_t c = (*str)[0];
 
@@ -71,7 +47,7 @@ static QDF_STATUS qdf_consume_dec(const char **str, uint8_t *out_digit)
 	return QDF_STATUS_SUCCESS;
 }
 
-static QDF_STATUS qdf_consume_hex(const char **str, uint8_t *out_nibble)
+static QDF_STATUS qdf_consume_hex(char **str, uint8_t *out_nibble)
 {
 	uint8_t c = (*str)[0];
 
@@ -89,7 +65,7 @@ static QDF_STATUS qdf_consume_hex(const char **str, uint8_t *out_nibble)
 	return QDF_STATUS_SUCCESS;
 }
 
-static QDF_STATUS qdf_consume_octet_dec(const char **str, uint8_t *out_octet)
+static QDF_STATUS qdf_consume_octet_dec(char **str, uint8_t *out_octet)
 {
 	uint8_t len = 0;
 	uint16_t octet = 0;
@@ -120,7 +96,7 @@ static QDF_STATUS qdf_consume_octet_dec(const char **str, uint8_t *out_octet)
 	return QDF_STATUS_SUCCESS;
 }
 
-static QDF_STATUS qdf_consume_hex_pair(const char **str, uint8_t *out_byte)
+static QDF_STATUS qdf_consume_hex_pair(char **str, uint8_t *out_byte)
 {
 	QDF_STATUS status;
 	uint8_t hi, low;
@@ -140,7 +116,7 @@ static QDF_STATUS qdf_consume_hex_pair(const char **str, uint8_t *out_byte)
 	return QDF_STATUS_SUCCESS;
 }
 
-static QDF_STATUS qdf_consume_hextet(const char **str, uint16_t *out_hextet)
+static QDF_STATUS qdf_consume_hextet(char **str, uint16_t *out_hextet)
 {
 	uint8_t len = 0;
 	uint16_t hextet = 0;
@@ -168,7 +144,7 @@ static QDF_STATUS qdf_consume_hextet(const char **str, uint16_t *out_hextet)
 	return QDF_STATUS_SUCCESS;
 }
 
-static QDF_STATUS qdf_consume_radix(const char **str, uint8_t *out_radix)
+static QDF_STATUS qdf_consume_radix(char **str, uint8_t *out_radix)
 {
 	if ((*str)[0] == '0') {
 		switch ((*str)[1]) {
@@ -201,7 +177,7 @@ static QDF_STATUS qdf_consume_radix(const char **str, uint8_t *out_radix)
 }
 
 static QDF_STATUS
-qdf_int_parse(const char *int_str, uint64_t *out_int, bool *out_negate)
+qdf_int_parse(char *int_str, uint64_t *out_int, bool *out_negate)
 {
 	QDF_STATUS status;
 	bool negate = false;
@@ -218,7 +194,7 @@ qdf_int_parse(const char *int_str, uint64_t *out_int, bool *out_negate)
 	if (!out_int)
 		return QDF_STATUS_E_INVAL;
 
-	qdf_skip_whitespace(&int_str);
+	int_str = qdf_str_left_trim(int_str);
 
 	status = qdf_consume_char(&int_str, '-');
 	if (QDF_IS_STATUS_SUCCESS(status))
@@ -241,7 +217,7 @@ qdf_int_parse(const char *int_str, uint64_t *out_int, bool *out_negate)
 		value = next_value;
 	}
 
-	qdf_skip_whitespace(&int_str);
+	int_str = qdf_str_left_trim(int_str);
 	if (int_str[0] != '\0')
 		return QDF_STATUS_E_FAILURE;
 
@@ -251,7 +227,7 @@ qdf_int_parse(const char *int_str, uint64_t *out_int, bool *out_negate)
 	return QDF_STATUS_SUCCESS;
 }
 
-QDF_STATUS qdf_int32_parse(const char *int_str, int32_t *out_int)
+QDF_STATUS qdf_int32_parse(char *int_str, int32_t *out_int)
 {
 	QDF_STATUS status;
 	int64_t value;
@@ -269,7 +245,7 @@ QDF_STATUS qdf_int32_parse(const char *int_str, int32_t *out_int)
 }
 qdf_export_symbol(qdf_int32_parse);
 
-QDF_STATUS qdf_uint32_parse(const char *int_str, uint32_t *out_int)
+QDF_STATUS qdf_uint32_parse(char *int_str, uint32_t *out_int)
 {
 	QDF_STATUS status;
 	uint64_t value;
@@ -287,7 +263,7 @@ QDF_STATUS qdf_uint32_parse(const char *int_str, uint32_t *out_int)
 }
 qdf_export_symbol(qdf_uint32_parse);
 
-QDF_STATUS qdf_int64_parse(const char *int_str, int64_t *out_int)
+QDF_STATUS qdf_int64_parse(char *int_str, int64_t *out_int)
 {
 	QDF_STATUS status;
 	bool negate;
@@ -314,7 +290,7 @@ QDF_STATUS qdf_int64_parse(const char *int_str, int64_t *out_int)
 }
 qdf_export_symbol(qdf_int64_parse);
 
-QDF_STATUS qdf_uint64_parse(const char *int_str, uint64_t *out_int)
+QDF_STATUS qdf_uint64_parse(char *int_str, uint64_t *out_int)
 {
 	QDF_STATUS status;
 	bool negate;
@@ -333,7 +309,7 @@ QDF_STATUS qdf_uint64_parse(const char *int_str, uint64_t *out_int)
 }
 qdf_export_symbol(qdf_uint64_parse);
 
-QDF_STATUS qdf_bool_parse(const char *bool_str, bool *out_bool)
+QDF_STATUS qdf_bool_parse(char *bool_str, bool *out_bool)
 {
 	bool value;
 
@@ -345,7 +321,7 @@ QDF_STATUS qdf_bool_parse(const char *bool_str, bool *out_bool)
 	if (!out_bool)
 		return QDF_STATUS_E_INVAL;
 
-	qdf_skip_whitespace(&bool_str);
+	bool_str = qdf_str_left_trim(bool_str);
 
 	switch (bool_str[0]) {
 	case '1':
@@ -362,7 +338,7 @@ QDF_STATUS qdf_bool_parse(const char *bool_str, bool *out_bool)
 		return QDF_STATUS_E_FAILURE;
 	}
 
-	qdf_skip_whitespace(&bool_str);
+	bool_str = qdf_str_left_trim(bool_str);
 	if (bool_str[0] != '\0')
 		return QDF_STATUS_E_FAILURE;
 
@@ -372,7 +348,7 @@ QDF_STATUS qdf_bool_parse(const char *bool_str, bool *out_bool)
 }
 qdf_export_symbol(qdf_bool_parse);
 
-QDF_STATUS qdf_mac_parse(const char *mac_str, struct qdf_mac_addr *out_addr)
+QDF_STATUS qdf_mac_parse(char *mac_str, struct qdf_mac_addr *out_addr)
 {
 	QDF_STATUS status;
 	struct qdf_mac_addr addr;
@@ -387,7 +363,7 @@ QDF_STATUS qdf_mac_parse(const char *mac_str, struct qdf_mac_addr *out_addr)
 	if (!out_addr)
 		return QDF_STATUS_E_INVAL;
 
-	qdf_skip_whitespace(&mac_str);
+	mac_str = qdf_str_left_trim(mac_str);
 
 	/* parse leading hex pair */
 	status = qdf_consume_hex_pair(&mac_str, &addr.bytes[0]);
@@ -411,7 +387,7 @@ QDF_STATUS qdf_mac_parse(const char *mac_str, struct qdf_mac_addr *out_addr)
 			return status;
 	}
 
-	qdf_skip_whitespace(&mac_str);
+	mac_str = qdf_str_left_trim(mac_str);
 	if (mac_str[0] != '\0')
 		return QDF_STATUS_E_FAILURE;
 
@@ -419,8 +395,9 @@ QDF_STATUS qdf_mac_parse(const char *mac_str, struct qdf_mac_addr *out_addr)
 
 	return QDF_STATUS_SUCCESS;
 }
+qdf_export_symbol(qdf_mac_parse);
 
-QDF_STATUS qdf_ipv4_parse(const char *ipv4_str, struct qdf_ipv4_addr *out_addr)
+QDF_STATUS qdf_ipv4_parse(char *ipv4_str, struct qdf_ipv4_addr *out_addr)
 {
 	QDF_STATUS status;
 	struct qdf_ipv4_addr addr;
@@ -434,7 +411,7 @@ QDF_STATUS qdf_ipv4_parse(const char *ipv4_str, struct qdf_ipv4_addr *out_addr)
 	if (!out_addr)
 		return QDF_STATUS_E_INVAL;
 
-	qdf_skip_whitespace(&ipv4_str);
+	ipv4_str = qdf_str_left_trim(ipv4_str);
 
 	/* parse leading octet */
 	status = qdf_consume_octet_dec(&ipv4_str, &addr.bytes[0]);
@@ -453,7 +430,7 @@ QDF_STATUS qdf_ipv4_parse(const char *ipv4_str, struct qdf_ipv4_addr *out_addr)
 			return status;
 	}
 
-	qdf_skip_whitespace(&ipv4_str);
+	ipv4_str = qdf_str_left_trim(ipv4_str);
 	if (ipv4_str[0] != '\0')
 		return QDF_STATUS_E_FAILURE;
 
@@ -461,8 +438,9 @@ QDF_STATUS qdf_ipv4_parse(const char *ipv4_str, struct qdf_ipv4_addr *out_addr)
 
 	return QDF_STATUS_SUCCESS;
 }
+qdf_export_symbol(qdf_ipv4_parse);
 
-QDF_STATUS qdf_ipv6_parse(const char *ipv6_str, struct qdf_ipv6_addr *out_addr)
+QDF_STATUS qdf_ipv6_parse(char *ipv6_str, struct qdf_ipv6_addr *out_addr)
 {
 	QDF_STATUS status;
 	struct qdf_ipv6_addr addr;
@@ -477,7 +455,7 @@ QDF_STATUS qdf_ipv6_parse(const char *ipv6_str, struct qdf_ipv6_addr *out_addr)
 	if (!out_addr)
 		return QDF_STATUS_E_INVAL;
 
-	qdf_skip_whitespace(&ipv6_str);
+	ipv6_str = qdf_str_left_trim(ipv6_str);
 
 	/* check for leading zero-compression ("::") */
 	status = qdf_consume_char(&ipv6_str, ':');
@@ -526,7 +504,7 @@ QDF_STATUS qdf_ipv6_parse(const char *ipv6_str, struct qdf_ipv6_addr *out_addr)
 	if (hextets_found < QDF_IPV6_ADDR_HEXTET_COUNT && zero_comp == -1)
 		return QDF_STATUS_E_FAILURE;
 
-	qdf_skip_whitespace(&ipv6_str);
+	ipv6_str = qdf_str_left_trim(ipv6_str);
 	if (ipv6_str[0] != '\0')
 		return QDF_STATUS_E_FAILURE;
 
@@ -544,4 +522,5 @@ QDF_STATUS qdf_ipv6_parse(const char *ipv6_str, struct qdf_ipv6_addr *out_addr)
 
 	return QDF_STATUS_SUCCESS;
 }
+qdf_export_symbol(qdf_ipv6_parse);