Skip to contentSkip to conversation

mac-hwsim: support destroying radio by name.

PATCH In review [email protected] 2 participants 2 messages Sep 25, 2014 – Oct 6, 2014 Networking drivers (wireless)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mac-hwsim: support destroying radio by name.

From: Ben Greear <[email protected]>

It is not always convenient to have to know the device-id, so allow deleting by name as well.

---

v2: Protect against bad input.

 drivers/net/wireless/mac80211_hwsim.c | 22 +++++++++++++++++-----
 drivers/net/wireless/mac80211_hwsim.h |  2 ++
 2 files changed, 19 insertions(+), 5 deletions(-)
drivers/net/wireless/mac80211_hwsim.c +17 -5
index 43435c0..b755920 100644
@@ -2535,16 +2535,28 @@ static int hwsim_create_radio_nl(struct sk_buff *msg, struct genl_info *info)
 static int hwsim_destroy_radio_nl(struct sk_buff *msg, struct genl_info *info)
 {
 	struct mac80211_hwsim_data *data;
-	int idx;
+	int idx = -1;
+	const char *hwname = NULL;
 
-	if (!info->attrs[HWSIM_ATTR_RADIO_ID])
+	if (info->attrs[HWSIM_ATTR_RADIO_ID])
+		idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
+	else if (info->attrs[HWSIM_ATTR_RADIO_NAME])
+		hwname = (void *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]);
+	else
 		return -EINVAL;
-	idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
 
 	spin_lock_bh(&hwsim_radio_lock);
 	list_for_each_entry(data, &hwsim_radios, list) {
-		if (data->idx != idx)
-			continue;
+		if (idx >= 0) {
+			if (data->idx != idx)
+				continue;
+		} else {
+			if (hwname &&
+			    strcmp(hwname,
+				   dev_name(&data->hw->wiphy->dev)) != 0)
+				continue;
+		}
+
 		list_del(&data->list);
 		spin_unlock_bh(&hwsim_radio_lock);
 		mac80211_hwsim_destroy_radio(data);
drivers/net/wireless/mac80211_hwsim.h +2 -0
index c9d0315..37c040b 100644
@@ -111,6 +111,7 @@ enum {
  * @HWSIM_ATTR_USE_CHANCTX: used with the %HWSIM_CMD_CREATE_RADIO
  *	command to force use of channel contexts even when only a
  *	single channel is supported
+ * @HWSIM_ATTR_RADIO_NAME: Name of radio, ie phy666
  * @__HWSIM_ATTR_MAX: enum limit
  */
 
@@ -132,6 +133,7 @@ enum {
 	HWSIM_ATTR_REG_STRICT_REG,
 	HWSIM_ATTR_SUPPORT_P2P_DEVICE,
 	HWSIM_ATTR_USE_CHANCTX,
+	HWSIM_ATTR_RADIO_NAME,
 	__HWSIM_ATTR_MAX,
 };
 #define HWSIM_ATTR_MAX (__HWSIM_ATTR_MAX - 1)
Signature · 1 line
1.7.11.7
maintainer
#1 lore raw
Quoted 19 lines · On Thu, 2014-09-25 at 15:58 -0700, [email protected] wrote:

From: Ben Greear <[email protected]>

It is not always convenient to have to know the device-id, so allow deleting by name as well.

---

v2: Protect against bad input.

 drivers/net/wireless/mac80211_hwsim.c | 22 +++++++++++++++++-----
 drivers/net/wireless/mac80211_hwsim.h |  2 ++
 2 files changed, 19 insertions(+), 5 deletions(-)
drivers/net/wireless/mac80211_hwsim.c +0 -0
index 43435c0..b755920 100644

drivers/net/wireless/mac80211_hwsim.c static int hwsim_create_radio_nl(struct sk_buff *msg, struct genl_info *info) · line 2538

Quoted 5 lines
drivers/net/wireless/mac80211_hwsim.c +1 -1
@@ -2535,16 +2535,28 @@ static int hwsim_create_radio_nl(struct sk_buff *msg, struct genl_info *info)
 static int hwsim_destroy_radio_nl(struct sk_buff *msg, struct genl_info *info)
 {
 	struct mac80211_hwsim_data *data;
-	int idx;
+	int idx = -1;

you might have to make this an s64?

drivers/net/wireless/mac80211_hwsim.c static int hwsim_create_radio_nl(struct sk_buff *msg, struct genl_info *info) · line 2539

Quoted 1 line
drivers/net/wireless/mac80211_hwsim.c +1 -0
+ * @HWSIM_ATTR_RADIO_NAME: Name of radio, ie phy666

e.g., not i.e.

johannes