[PATCH] fix min() warnings

Andreas Henriksson andreas at fjortis.info
Tue Jul 4 16:07:01 EDT 2006


Here's an attempt to fix the warnings introduced when converting from
MIN()/MAX() to min()/max(), by using min_t() where needed.

"warning: comparison of distinct pointer types lacks a cast"

(still not fixed: "warning: cast from pointer to integer of different size")

Please verify if it's correctly done.

Signed-off-by: Andreas Henriksson <andreas at fjortis.info>

diff --git a/drivers/net/wireless/libertas/wlan_join.c b/drivers/net/wireless/libertas/wlan_join.c
index a97c17d..75bae76 100644
--- a/drivers/net/wireless/libertas/wlan_join.c
+++ b/drivers/net/wireless/libertas/wlan_join.c
@@ -63,7 +63,7 @@ static int get_common_rates(wlan_adapter
 	int i;
 
 	memset(&tmp, 0, sizeof(tmp));
-	memcpy(&tmp, rate1, min(rate1_size, sizeof(tmp)));
+	memcpy(&tmp, rate1, min_t(size_t, rate1_size, sizeof(tmp)));
 	memset(rate1, 0, rate1_size);
 
 	/* Mask the top bit of the original values */
@@ -860,7 +860,8 @@ int wlan_cmd_802_11_associate(wlan_priva
 		goto done;
 	}
 
-	rates->Header.Len = min(strlen(rates->Rates), WLAN_SUPPORTED_RATES);
+	rates->Header.Len = min_t(u16, strlen(rates->Rates),
+			WLAN_SUPPORTED_RATES);
 	Adapter->CurBssParams.NumOfRates = rates->Header.Len;
 
 	pos += sizeof(rates->Header) + rates->Header.Len;
@@ -884,7 +885,8 @@ int wlan_cmd_802_11_associate(wlan_priva
 
 	/* Copy the infra. association rates into Current BSS state structure */
 	memcpy(&Adapter->CurBssParams.DataRates, &rates->Rates,
-	       min(sizeof(Adapter->CurBssParams.DataRates), rates->Header.Len));
+			min_t(size_t, sizeof(Adapter->CurBssParams.DataRates),
+					rates->Header.Len));
 
 	PRINTM(INFO, "ASSOC_CMD: rates->Header.Len = %d\n", rates->Header.Len);
 
diff --git a/drivers/net/wireless/libertas/wlan_scan.c b/drivers/net/wireless/libertas/wlan_scan.c
index 829bbf8..a303c9a 100644
--- a/drivers/net/wireless/libertas/wlan_scan.c
+++ b/drivers/net/wireless/libertas/wlan_scan.c
@@ -1232,9 +1232,9 @@ #define IE_ID_LEN_FIELDS_BYTES 2
 			pIe = (struct IE_WPA *)pCurrentPtr;
 
 			if (!memcmp(pIe->oui, oui01, sizeof(oui01))) {
-				pwpa_supplicant->Wpa_ie_len
-				    = min(elemLen + IE_ID_LEN_FIELDS_BYTES,
-					  sizeof(pwpa_supplicant->Wpa_ie));
+				pwpa_supplicant->Wpa_ie_len = min_t(size_t,
+						elemLen + IE_ID_LEN_FIELDS_BYTES,
+						sizeof(pwpa_supplicant->Wpa_ie));
 				memcpy(pwpa_supplicant->Wpa_ie,
 				       pCurrentPtr,
 				       pwpa_supplicant->Wpa_ie_len);
@@ -1244,9 +1244,9 @@ #define IE_ID_LEN_FIELDS_BYTES 2
 			break;
 		case WPA2_IE:
 			pIe = (struct IE_WPA *)pCurrentPtr;
-			pwpa2_supplicant->Wpa_ie_len
-			    = min(elemLen + IE_ID_LEN_FIELDS_BYTES,
-				  sizeof(pwpa2_supplicant->Wpa_ie));
+			pwpa2_supplicant->Wpa_ie_len = min_t(size_t,
+					elemLen + IE_ID_LEN_FIELDS_BYTES,
+					sizeof(pwpa2_supplicant->Wpa_ie));
 			memcpy(pwpa2_supplicant->Wpa_ie,
 			       pCurrentPtr, pwpa2_supplicant->Wpa_ie_len);
 
@@ -2067,9 +2067,9 @@ int wlan_set_user_scan_ioctl(wlan_privat
 	int retcode;
 	union iwreq_data wrqu;
 
-	if (copy_from_user(&scanReq,
-			   wrq->u.data.pointer,
-			   min(wrq->u.data.length, sizeof(scanReq))) != 0) {
+	if (copy_from_user(&scanReq, wrq->u.data.pointer,
+			min_t(unsigned, wrq->u.data.length,
+					sizeof(scanReq)))) {
 		/* copy_from_user failed  */
 		PRINTM(INFO, "SetUserScan: copy from user failed\n");
 		retcode = -EFAULT;
diff --git a/drivers/net/wireless/libertas/wlan_wext.c b/drivers/net/wireless/libertas/wlan_wext.c
index b25001d..5d8dcc4 100644
--- a/drivers/net/wireless/libertas/wlan_wext.c
+++ b/drivers/net/wireless/libertas/wlan_wext.c
@@ -1669,8 +1669,8 @@ static int wlan_get_range(struct net_dev
 	memset(rates, 0, sizeof(rates));
 	range->num_bitrates = get_active_data_rates(Adapter, rates);
 
-	for (i = 0; i < min(range->num_bitrates, IW_MAX_BITRATES) && rates[i];
-	     i++) {
+	for (i = 0; i < min_t(int, range->num_bitrates,
+			IW_MAX_BITRATES) && rates[i]; i++) {
 		range->bitrate[i] = (rates[i] & 0x7f) * 500000;
 	}
 	range->num_bitrates = i;
@@ -2585,9 +2585,9 @@ static int wlan_get_snr(wlan_private * p
 	ENTER();
 	memset(data, 0, sizeof(data));
 	if (wrq->u.data.length) {
-		if (copy_from_user
-		    (data, wrq->u.data.pointer,
-		     min(wrq->u.data.length, 4) * sizeof(int))) {
+		if (copy_from_user(data, wrq->u.data.pointer,
+				min_t(unsigned, wrq->u.data.length, 4) *
+					sizeof(int))) {
 			PRINTM(INFO, "Copy from user failed\n");
 			return -EFAULT;
 		}
@@ -3435,11 +3435,9 @@ static int wlan_get_tsf_ioctl(wlan_priva
 		PRINTM(INFO, "IOCTL: Get TSF; Command exec failed\n");
 		ret = -EFAULT;
 	} else {
-		if (copy_to_user(wrq->u.data.pointer,
-				 &tsfVal,
-				 min(wrq->u.data.length,
-				     sizeof(tsfVal))) != 0) {
-
+		if (copy_to_user(wrq->u.data.pointer, &tsfVal,
+				min_t(unsigned, wrq->u.data.length,
+					sizeof(tsfVal)))) {
 			PRINTM(INFO, "IOCTL: Get TSF; Copy to user failed\n");
 			ret = -EFAULT;
 		} else {
@@ -3675,7 +3673,7 @@ static int wlan_sleep_params_ioctl(wlan_
 	memset(&sp, 0, sizeof(sp));
 
 	if (copy_from_user(&sp, wrq->u.data.pointer,
-			   min(sizeof(sp), wrq->u.data.length))) {
+			   min_t(unsigned, sizeof(sp), wrq->u.data.length))) {
 		PRINTM(INFO, "Copy from user failed\n");
 		return -EFAULT;
 	}
@@ -3750,8 +3748,8 @@ static int wlan_scan_type_ioctl(wlan_pri
 
 	memset(buf, 0, sizeof(buf));
 
-	if (copy_from_user(buf, wrq->u.data.pointer, min(sizeof(buf),
-							 wrq->u.data.length))) {
+	if (copy_from_user(buf, wrq->u.data.pointer,
+			min_t(unsigned, sizeof(buf), wrq->u.data.length))) {
 		PRINTM(INFO, "Copy from user failed\n");
 		return -EFAULT;
 	}
@@ -3812,8 +3810,8 @@ static int wlan_scan_mode_ioctl(wlan_pri
 
 	memset(buf, 0, sizeof(buf));
 
-	if (copy_from_user(buf, wrq->u.data.pointer, min(sizeof(buf),
-							 wrq->u.data.length))) {
+	if (copy_from_user(buf, wrq->u.data.pointer,
+			min_t(unsigned, sizeof(buf), wrq->u.data.length))) {
 		PRINTM(INFO, "Copy from user failed\n");
 		return -EFAULT;
 	}
@@ -4102,7 +4100,8 @@ #define MAX_U16_VAL	65535
 		case WLAN_SET_ATIM_WINDOW:
 			Adapter->AtimWindow =
 			    *((int *)(wrq->u.name + SUBCMD_OFFSET));
-			Adapter->AtimWindow = min(Adapter->AtimWindow, 50);
+			Adapter->AtimWindow = min_t(u16,
+					Adapter->AtimWindow, 50);
 			break;
 		case WLANSETBCNAVG:
 			Adapter->bcn_avg_factor =
@@ -5161,8 +5160,9 @@ int wlan_get_essid(struct net_device *de
 
 	/* To make the driver backward compatible with WPA supplicant v0.2.4 */
 	if (dwrq->length == 32)	/* check with WPA supplicant buffer size */
-		dwrq->length = min(Adapter->CurBssParams.ssid.SsidLength,
-				   IW_ESSID_MAX_SIZE);
+		dwrq->length = min_t(u32,
+				Adapter->CurBssParams.ssid.SsidLength,
+				IW_ESSID_MAX_SIZE);
 	else
 		dwrq->length = Adapter->CurBssParams.ssid.SsidLength + 1;
 



More information about the libertas-dev mailing list