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

Commit e9763c3c authored by Johannes Berg's avatar Johannes Berg
Browse files

regulatory: clean up reg_copy_regd()



Use ERR_PTR/IS_ERR to return the result or errors,
also do some code cleanups.

Acked-by: default avatarLuis R. Rodriguez <mcgrof@do-not-panic.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 74f53cd8
Loading
Loading
Loading
Loading
+24 −26
Original line number Original line Diff line number Diff line
@@ -311,11 +311,11 @@ static bool is_user_regdom_saved(void)
	return true;
	return true;
}
}


static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd,
static const struct ieee80211_regdomain *
			 const struct ieee80211_regdomain *src_regd)
reg_copy_regd(const struct ieee80211_regdomain *src_regd)
{
{
	struct ieee80211_regdomain *regd;
	struct ieee80211_regdomain *regd;
	int size_of_regd = 0;
	int size_of_regd;
	unsigned int i;
	unsigned int i;


	size_of_regd =
	size_of_regd =
@@ -324,7 +324,7 @@ static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd,


	regd = kzalloc(size_of_regd, GFP_KERNEL);
	regd = kzalloc(size_of_regd, GFP_KERNEL);
	if (!regd)
	if (!regd)
		return -ENOMEM;
		return ERR_PTR(-ENOMEM);


	memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain));
	memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain));


@@ -332,8 +332,7 @@ static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd,
		memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i],
		memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i],
		       sizeof(struct ieee80211_reg_rule));
		       sizeof(struct ieee80211_reg_rule));


	*dst_regd = regd;
	return regd;
	return 0;
}
}


#ifdef CONFIG_CFG80211_INTERNAL_REGDB
#ifdef CONFIG_CFG80211_INTERNAL_REGDB
@@ -348,9 +347,8 @@ static DEFINE_MUTEX(reg_regdb_search_mutex);
static void reg_regdb_search(struct work_struct *work)
static void reg_regdb_search(struct work_struct *work)
{
{
	struct reg_regdb_search_request *request;
	struct reg_regdb_search_request *request;
	const struct ieee80211_regdomain *curdom, *regdom;
	const struct ieee80211_regdomain *curdom, *regdom = NULL;
	int i, r;
	int i;
	bool set_reg = false;


	mutex_lock(&cfg80211_mutex);
	mutex_lock(&cfg80211_mutex);


@@ -365,10 +363,7 @@ static void reg_regdb_search(struct work_struct *work)
			curdom = reg_regdb[i];
			curdom = reg_regdb[i];


			if (!memcmp(request->alpha2, curdom->alpha2, 2)) {
			if (!memcmp(request->alpha2, curdom->alpha2, 2)) {
				r = reg_copy_regd(&regdom, curdom);
				regdom = reg_copy_regd(curdom);
				if (r)
					break;
				set_reg = true;
				break;
				break;
			}
			}
		}
		}
@@ -377,7 +372,7 @@ static void reg_regdb_search(struct work_struct *work)
	}
	}
	mutex_unlock(&reg_regdb_search_mutex);
	mutex_unlock(&reg_regdb_search_mutex);


	if (set_reg)
	if (!IS_ERR_OR_NULL(regdom))
		set_regdom(regdom);
		set_regdom(regdom);


	mutex_unlock(&cfg80211_mutex);
	mutex_unlock(&cfg80211_mutex);
@@ -1509,6 +1504,7 @@ static void reg_set_request_processed(void)
static int __regulatory_hint(struct wiphy *wiphy,
static int __regulatory_hint(struct wiphy *wiphy,
			     struct regulatory_request *pending_request)
			     struct regulatory_request *pending_request)
{
{
	const struct ieee80211_regdomain *regd;
	bool intersect = false;
	bool intersect = false;
	int r = 0;
	int r = 0;


@@ -1519,11 +1515,12 @@ static int __regulatory_hint(struct wiphy *wiphy,
	if (r == REG_INTERSECT) {
	if (r == REG_INTERSECT) {
		if (pending_request->initiator ==
		if (pending_request->initiator ==
		    NL80211_REGDOM_SET_BY_DRIVER) {
		    NL80211_REGDOM_SET_BY_DRIVER) {
			r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain);
			regd = reg_copy_regd(cfg80211_regdomain);
			if (r) {
			if (IS_ERR(regd)) {
				kfree(pending_request);
				kfree(pending_request);
				return r;
				return PTR_ERR(regd);
			}
			}
			wiphy->regd = regd;
		}
		}
		intersect = true;
		intersect = true;
	} else if (r) {
	} else if (r) {
@@ -1535,12 +1532,13 @@ static int __regulatory_hint(struct wiphy *wiphy,
		if (r == -EALREADY &&
		if (r == -EALREADY &&
		    pending_request->initiator ==
		    pending_request->initiator ==
		    NL80211_REGDOM_SET_BY_DRIVER) {
		    NL80211_REGDOM_SET_BY_DRIVER) {
			r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain);
			regd = reg_copy_regd(cfg80211_regdomain);
			if (r) {
			if (IS_ERR(regd)) {
				kfree(pending_request);
				kfree(pending_request);
				return r;
				return PTR_ERR(regd);
			}
			}
			r = -EALREADY;
			r = -EALREADY;
			wiphy->regd = regd;
			goto new_request;
			goto new_request;
		}
		}
		kfree(pending_request);
		kfree(pending_request);
@@ -2200,6 +2198,7 @@ static void print_regdomain_info(const struct ieee80211_regdomain *rd)
/* Takes ownership of rd only if it doesn't fail */
/* Takes ownership of rd only if it doesn't fail */
static int __set_regdom(const struct ieee80211_regdomain *rd)
static int __set_regdom(const struct ieee80211_regdomain *rd)
{
{
	const struct ieee80211_regdomain *regd;
	const struct ieee80211_regdomain *intersected_rd = NULL;
	const struct ieee80211_regdomain *intersected_rd = NULL;
	struct wiphy *request_wiphy;
	struct wiphy *request_wiphy;
	/* Some basic sanity checks first */
	/* Some basic sanity checks first */
@@ -2257,8 +2256,6 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
	}
	}


	if (!last_request->intersect) {
	if (!last_request->intersect) {
		int r;

		if (last_request->initiator != NL80211_REGDOM_SET_BY_DRIVER) {
		if (last_request->initiator != NL80211_REGDOM_SET_BY_DRIVER) {
			reset_regdomains(false);
			reset_regdomains(false);
			cfg80211_regdomain = rd;
			cfg80211_regdomain = rd;
@@ -2277,10 +2274,11 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
		if (request_wiphy->regd)
		if (request_wiphy->regd)
			return -EALREADY;
			return -EALREADY;


		r = reg_copy_regd(&request_wiphy->regd, rd);
		regd = reg_copy_regd(rd);
		if (r)
		if (IS_ERR(regd))
			return r;
			return PTR_ERR(regd);


		request_wiphy->regd = regd;
		reset_regdomains(false);
		reset_regdomains(false);
		cfg80211_regdomain = rd;
		cfg80211_regdomain = rd;
		return 0;
		return 0;