Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6cf070d2 authored by Sergio Paracuellos's avatar Sergio Paracuellos Committed by Greg Kroah-Hartman
Browse files

staging: ks7010: refactor ks_wlan_set_encode function



This commit refactors ks_wlan_set_encode function to improve
readability. It just removes level indentation in some paths
as well as removes not needed conditions paths which was
checked before. Changes are as follows:

 - (dwrq->length > MAX_KEY_SIZE) check has been moved to the top.
 - extra check about (dwrq->length > 0) inside an if block where
   that was the condition to enter inside it has been removed.
 - (dwrq->flags & IW_ENCODE_NOKEY) check has been turned to avoid
   one level indentation.
 - extra check (index >= 0) && (index < 4) has been removed. In
   the top of the file invalid index values are being checked
   so it has no sense to check that again.
 - remove commented line.

Signed-off-by: default avatarSergio Paracuellos <sergio.paracuellos@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fffe8bec
Loading
Loading
Loading
Loading
+31 −53
Original line number Original line Diff line number Diff line
@@ -819,64 +819,48 @@ static int ks_wlan_set_encode(struct net_device *dev,
			      struct iw_point *dwrq, char *extra)
			      struct iw_point *dwrq, char *extra)
{
{
	struct ks_wlan_private *priv = netdev_priv(dev);
	struct ks_wlan_private *priv = netdev_priv(dev);

	struct wep_key key;
	struct wep_key key;
	int index = (dwrq->flags & IW_ENCODE_INDEX);
	int index = (dwrq->flags & IW_ENCODE_INDEX);
	int current_index = priv->reg.wep_index;
	int i;


	if (priv->sleep_mode == SLP_SLEEP)
	if (priv->sleep_mode == SLP_SLEEP)
		return -EPERM;
		return -EPERM;


	if (dwrq->length > MAX_KEY_SIZE)
		return -EINVAL;

	/* for SLEEP MODE */
	/* for SLEEP MODE */
	/* index check */
	if ((index < 0) || (index > 4))
	if ((index < 0) || (index > 4))
		return -EINVAL;
		return -EINVAL;
	else if (index == 0)

		index = current_index;
	index = (index == 0) ? priv->reg.wep_index : (index - 1);
	else
		index--;


	/* Is WEP supported ? */
	/* Is WEP supported ? */
	/* Basic checking: do we have a key to set ? */
	/* Basic checking: do we have a key to set ? */
	if (dwrq->length > 0) {
	if (dwrq->length > 0) {
		if (dwrq->length > MAX_KEY_SIZE) {	/* Check the size of the key */
		key.len = (dwrq->length > MIN_KEY_SIZE) ?
			return -EINVAL;
			   MAX_KEY_SIZE : MIN_KEY_SIZE;
		}
		if (dwrq->length > MIN_KEY_SIZE) {	/* Set the length */
			key.len = MAX_KEY_SIZE;
			priv->reg.privacy_invoked = 0x01;
			priv->need_commit |= SME_WEP_FLAG;
			wep_on_off = WEP_ON_128BIT;
		} else {
			if (dwrq->length > 0) {
				key.len = MIN_KEY_SIZE;
		priv->reg.privacy_invoked = 0x01;
		priv->reg.privacy_invoked = 0x01;
		priv->need_commit |= SME_WEP_FLAG;
		priv->need_commit |= SME_WEP_FLAG;
				wep_on_off = WEP_ON_64BIT;
		wep_on_off = (dwrq->length > MIN_KEY_SIZE) ?
			} else {	/* Disable the key */
			      WEP_ON_128BIT : WEP_ON_64BIT;
				key.len = 0;
			}
		}
		/* Check if the key is not marked as invalid */
		/* Check if the key is not marked as invalid */
		if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
		if (dwrq->flags & IW_ENCODE_NOKEY)
			return 0;

		/* Cleanup */
		/* Cleanup */
		memset(key.key, 0, MAX_KEY_SIZE);
		memset(key.key, 0, MAX_KEY_SIZE);
		/* Copy the key in the driver */
		/* Copy the key in the driver */
			if (copy_from_user
		if (copy_from_user(key.key, dwrq->pointer, dwrq->length)) {
			    (key.key, dwrq->pointer, dwrq->length)) {
			key.len = 0;
			key.len = 0;
			return -EFAULT;
			return -EFAULT;
		}
		}
		/* Send the key to the card */
		/* Send the key to the card */
		priv->reg.wep_key[index].size = key.len;
		priv->reg.wep_key[index].size = key.len;
			for (i = 0; i < (priv->reg.wep_key[index].size); i++)
		memcpy(&priv->reg.wep_key[index].val[0], &key.key[0],
				priv->reg.wep_key[index].val[i] = key.key[i];
		       priv->reg.wep_key[index].size);

		priv->need_commit |= (SME_WEP_VAL1 << index);
		priv->need_commit |= (SME_WEP_VAL1 << index);
		priv->reg.wep_index = index;
		priv->reg.wep_index = index;
		priv->need_commit |= SME_WEP_INDEX;
		priv->need_commit |= SME_WEP_INDEX;
		}
	} else {
	} else {
		if (dwrq->flags & IW_ENCODE_DISABLED) {
		if (dwrq->flags & IW_ENCODE_DISABLED) {
			priv->reg.wep_key[0].size = 0;
			priv->reg.wep_key[0].size = 0;
@@ -891,16 +875,11 @@ static int ks_wlan_set_encode(struct net_device *dev,
			wep_on_off = WEP_OFF;
			wep_on_off = WEP_OFF;
			priv->need_commit |= SME_WEP_FLAG;
			priv->need_commit |= SME_WEP_FLAG;
		} else {
		} else {
			/* Do we want to just set the transmit key index ? */
			if ((index >= 0) && (index < 4)) {
			/* set_wep_key(priv, index, 0, 0, 1);   xxx */
			/* set_wep_key(priv, index, 0, 0, 1);   xxx */
				if (priv->reg.wep_key[index].size != 0) {
			if (priv->reg.wep_key[index].size == 0)
				return -EINVAL;
			priv->reg.wep_index = index;
			priv->reg.wep_index = index;
			priv->need_commit |= SME_WEP_INDEX;
			priv->need_commit |= SME_WEP_INDEX;
				} else {
					return -EINVAL;
				}
			}
		}
		}
	}
	}


@@ -919,7 +898,6 @@ static int ks_wlan_set_encode(struct net_device *dev,


		priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
		priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
	}
	}
//      return -EINPROGRESS;            /* Call commit handler */
	if (priv->need_commit) {
	if (priv->need_commit) {
		ks_wlan_setup_parameter(priv, priv->need_commit);
		ks_wlan_setup_parameter(priv, priv->need_commit);
		priv->need_commit = 0;
		priv->need_commit = 0;