All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] d80211: clean up those huge else if statements
@ 2006-08-30  8:41 Johannes Berg
  2006-09-21 19:25 ` [PATCH] d80211: clean up those huge else if statements; use BUILD_BUG_ON Jiri Benc
  0 siblings, 1 reply; 2+ messages in thread
From: Johannes Berg @ 2006-08-30  8:41 UTC (permalink / raw)
  To: John W. Linville; +Cc: netdev, Jiri Benc, Jouni Malinen

This patch replaces the if (...) else if (...) else if (...) ...
statements I complained about earlier with switches.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>

--- wireless-dev.orig/net/d80211/ieee80211_ioctl.c	2006-08-25 22:49:45.518728753 +0200
+++ wireless-dev/net/d80211/ieee80211_ioctl.c	2006-08-25 22:59:28.838728753 +0200
@@ -1000,11 +1000,13 @@ static int ieee80211_ioctl_add_if(struct
         int left = param_len - ((u8 *) pos - (u8 *) param);
 	struct net_device *new_dev;
 	int res;
+	struct hostapd_if_wds *wds;
+	struct hostapd_if_bss *bss;
 
 	printk(KERN_WARNING "PRISM2_HOSTAPD_ADD_IF ioctl is deprecated!");
-        if (param->u.if_info.type == HOSTAP_IF_WDS) {
-                struct hostapd_if_wds *wds =
-			(struct hostapd_if_wds *) param->u.if_info.data;
+	switch (param->u.if_info.type) {
+	case HOSTAP_IF_WDS:
+		wds = (struct hostapd_if_wds *) param->u.if_info.data;
 
                 if (left < sizeof(struct hostapd_if_wds))
                         return -EPROTO;
@@ -1018,7 +1020,7 @@ static int ieee80211_ioctl_add_if(struct
 			__ieee80211_if_del(dev->ieee80211_ptr,
 					   IEEE80211_DEV_TO_SUB_IF(new_dev));
 		return res;
-	} else if (param->u.if_info.type == HOSTAP_IF_VLAN) {
+	case HOSTAP_IF_VLAN:
 		if (left < sizeof(struct hostapd_if_vlan))
 			return -EPROTO;
 
@@ -1033,9 +1035,8 @@ static int ieee80211_ioctl_add_if(struct
 					   IEEE80211_DEV_TO_SUB_IF(new_dev));
 #endif
 		return res;
-        } else if (param->u.if_info.type == HOSTAP_IF_BSS) {
-                struct hostapd_if_bss *bss =
-			(struct hostapd_if_bss *) param->u.if_info.data;
+	case HOSTAP_IF_BSS:
+		bss = (struct hostapd_if_bss *) param->u.if_info.data;
 
                 if (left < sizeof(struct hostapd_if_bss))
                         return -EPROTO;
@@ -1046,12 +1047,7 @@ static int ieee80211_ioctl_add_if(struct
 		ieee80211_if_set_type(new_dev, IEEE80211_IF_TYPE_AP);
 		memcpy(new_dev->dev_addr, bss->bssid, ETH_ALEN);
 		return 0;
-        } else if (param->u.if_info.type == HOSTAP_IF_STA) {
-#if 0
-                struct hostapd_if_sta *sta =
-			(struct hostapd_if_sta *) param->u.if_info.data;
-#endif
-
+	case HOSTAP_IF_STA:
                 if (left < sizeof(struct hostapd_if_sta))
                         return -EPROTO;
 
@@ -1060,34 +1056,38 @@ static int ieee80211_ioctl_add_if(struct
 			return res;
 		ieee80211_if_set_type(new_dev, IEEE80211_IF_TYPE_STA);
 		return 0;
-	} else
-                return -EINVAL;
+	default:
+		return -EINVAL;
+	}
 
 	return 0;
 }
 
-
 static int ieee80211_ioctl_remove_if(struct net_device *dev,
 				     struct prism2_hostapd_param *param)
 {
 	unsigned int type;
 
-	if (param->u.if_info.type == HOSTAP_IF_WDS) {
+	switch (param->u.if_info.type) {
+	case HOSTAP_IF_WDS:
 		type = IEEE80211_IF_TYPE_WDS;
-	} else if (param->u.if_info.type == HOSTAP_IF_VLAN) {
+		break;
+	case HOSTAP_IF_VLAN:
 		type = IEEE80211_IF_TYPE_VLAN;
-	} else if (param->u.if_info.type == HOSTAP_IF_BSS) {
+		break;
+	case HOSTAP_IF_BSS:
 		type = IEEE80211_IF_TYPE_AP;
-	} else if (param->u.if_info.type == HOSTAP_IF_STA) {
+		break;
+	case HOSTAP_IF_STA:
 		type = IEEE80211_IF_TYPE_STA;
-	} else {
+		break;
+	default:
 		return -EINVAL;
 	}
 
 	return ieee80211_if_remove(dev, param->u.if_info.name, type);
 }
 
-
 static int ieee80211_ioctl_update_if(struct net_device *dev,
 				     struct prism2_hostapd_param *param,
 				     int param_len)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] d80211: clean up those huge else if statements; use BUILD_BUG_ON
  2006-08-30  8:41 [PATCH] d80211: clean up those huge else if statements Johannes Berg
@ 2006-09-21 19:25 ` Jiri Benc
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Benc @ 2006-09-21 19:25 UTC (permalink / raw)
  To: Johannes Berg; +Cc: John W. Linville, netdev, Jouni Malinen

On Wed, 30 Aug 2006 10:41:00 +0200, Johannes Berg wrote:
> This patch replaces the if (...) else if (...) else if (...) ...
> statements I complained about earlier with switches.

On Wed, 30 Aug 2006 10:39:30 +0200, Johannes Berg wrote:
> This patch makes d80211 use BUILD_BUG_ON instead of checking at module
> initialisation time. This check really is only interesting while you
> hack since if the module was built, then it's either an 'always true' or
> 'always false' comparison, hence useless to do it at runtime.

Both patches applied to my tree. Thanks!

 Jiri

-- 
Jiri Benc
SUSE Labs

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-09-21 19:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-30  8:41 [PATCH] d80211: clean up those huge else if statements Johannes Berg
2006-09-21 19:25 ` [PATCH] d80211: clean up those huge else if statements; use BUILD_BUG_ON Jiri Benc

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.