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

Commit 80b99899 authored by Johannes Berg's avatar Johannes Berg Committed by John W. Linville
Browse files

nl80211: make get_vlan logic more common



get_vlan() sets the output parameter even if it
returns an error, which is a bit odd. Instead,
convert it to use ERR_PTR.

Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 7c4ef712
Loading
Loading
Loading
Loading
+31 −23
Original line number Original line Diff line number Diff line
@@ -2485,26 +2485,34 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
/*
/*
 * Get vlan interface making sure it is running and on the right wiphy.
 * Get vlan interface making sure it is running and on the right wiphy.
 */
 */
static int get_vlan(struct genl_info *info,
static struct net_device *get_vlan(struct genl_info *info,
		    struct cfg80211_registered_device *rdev,
				   struct cfg80211_registered_device *rdev)
		    struct net_device **vlan)
{
{
	struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
	struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
	*vlan = NULL;
	struct net_device *v;
	int ret;


	if (vlanattr) {
	if (!vlanattr)
		*vlan = dev_get_by_index(genl_info_net(info),
		return NULL;
					 nla_get_u32(vlanattr));

		if (!*vlan)
	v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
			return -ENODEV;
	if (!v)
		if (!(*vlan)->ieee80211_ptr)
		return ERR_PTR(-ENODEV);
			return -EINVAL;

		if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
	if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
			return -EINVAL;
		ret = -EINVAL;
		if (!netif_running(*vlan))
		goto error;
			return -ENETDOWN;
	}
	}
	return 0;

	if (!netif_running(v)) {
		ret = -ENETDOWN;
		goto error;
	}

	return v;
 error:
	dev_put(v);
	return ERR_PTR(ret);
}
}


static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
@@ -2554,9 +2562,9 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
		params.plink_state =
		params.plink_state =
		    nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
		    nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);


	err = get_vlan(info, rdev, &params.vlan);
	params.vlan = get_vlan(info, rdev);
	if (err)
	if (IS_ERR(params.vlan))
		goto out;
		return PTR_ERR(params.vlan);


	/* validate settings */
	/* validate settings */
	err = 0;
	err = 0;
@@ -2724,9 +2732,9 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
	      (rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)))
	      (rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)))
		return -EINVAL;
		return -EINVAL;


	err = get_vlan(info, rdev, &params.vlan);
	params.vlan = get_vlan(info, rdev);
	if (err)
	if (IS_ERR(params.vlan))
		goto out;
		return PTR_ERR(params.vlan);


	/* validate settings */
	/* validate settings */
	err = 0;
	err = 0;