Commit 2390166a authored by Julian Wiedmann's avatar Julian Wiedmann Committed by David S. Miller

s390/qeth: clean up L3 sysfs code

Consolidate some duplicated code for adding RXIP/VIPA addresses, and
move the locking to where it's actually needed.
Signed-off-by: default avatarJulian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e6b1b7da
...@@ -571,6 +571,7 @@ int qeth_l3_add_ipato_entry(struct qeth_card *card, ...@@ -571,6 +571,7 @@ int qeth_l3_add_ipato_entry(struct qeth_card *card,
QETH_CARD_TEXT(card, 2, "addipato"); QETH_CARD_TEXT(card, 2, "addipato");
mutex_lock(&card->conf_mutex);
mutex_lock(&card->ip_lock); mutex_lock(&card->ip_lock);
list_for_each_entry(ipatoe, &card->ipato.entries, entry) { list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
...@@ -590,6 +591,7 @@ int qeth_l3_add_ipato_entry(struct qeth_card *card, ...@@ -590,6 +591,7 @@ int qeth_l3_add_ipato_entry(struct qeth_card *card,
} }
mutex_unlock(&card->ip_lock); mutex_unlock(&card->ip_lock);
mutex_unlock(&card->conf_mutex);
return rc; return rc;
} }
...@@ -603,6 +605,7 @@ int qeth_l3_del_ipato_entry(struct qeth_card *card, ...@@ -603,6 +605,7 @@ int qeth_l3_del_ipato_entry(struct qeth_card *card,
QETH_CARD_TEXT(card, 2, "delipato"); QETH_CARD_TEXT(card, 2, "delipato");
mutex_lock(&card->conf_mutex);
mutex_lock(&card->ip_lock); mutex_lock(&card->ip_lock);
list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) { list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
...@@ -619,6 +622,8 @@ int qeth_l3_del_ipato_entry(struct qeth_card *card, ...@@ -619,6 +622,8 @@ int qeth_l3_del_ipato_entry(struct qeth_card *card,
} }
mutex_unlock(&card->ip_lock); mutex_unlock(&card->ip_lock);
mutex_unlock(&card->conf_mutex);
return rc; return rc;
} }
...@@ -627,6 +632,7 @@ int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip, ...@@ -627,6 +632,7 @@ int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
enum qeth_prot_versions proto) enum qeth_prot_versions proto)
{ {
struct qeth_ipaddr addr; struct qeth_ipaddr addr;
int rc;
qeth_l3_init_ipaddr(&addr, type, proto); qeth_l3_init_ipaddr(&addr, type, proto);
if (proto == QETH_PROT_IPV4) if (proto == QETH_PROT_IPV4)
...@@ -634,7 +640,11 @@ int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip, ...@@ -634,7 +640,11 @@ int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
else else
memcpy(&addr.u.a6.addr, ip, 16); memcpy(&addr.u.a6.addr, ip, 16);
return qeth_l3_modify_ip(card, &addr, add); mutex_lock(&card->conf_mutex);
rc = qeth_l3_modify_ip(card, &addr, add);
mutex_unlock(&card->conf_mutex);
return rc;
} }
int qeth_l3_modify_hsuid(struct qeth_card *card, bool add) int qeth_l3_modify_hsuid(struct qeth_card *card, bool add)
......
...@@ -460,16 +460,14 @@ static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count, ...@@ -460,16 +460,14 @@ static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
int mask_bits; int mask_bits;
int rc = 0; int rc = 0;
mutex_lock(&card->conf_mutex);
rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits); rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
if (rc) if (rc)
goto out; return rc;
ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL); ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
if (!ipatoe) { if (!ipatoe)
rc = -ENOMEM; return -ENOMEM;
goto out;
}
ipatoe->proto = proto; ipatoe->proto = proto;
memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16); memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
ipatoe->mask_bits = mask_bits; ipatoe->mask_bits = mask_bits;
...@@ -477,8 +475,7 @@ static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count, ...@@ -477,8 +475,7 @@ static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
rc = qeth_l3_add_ipato_entry(card, ipatoe); rc = qeth_l3_add_ipato_entry(card, ipatoe);
if (rc) if (rc)
kfree(ipatoe); kfree(ipatoe);
out:
mutex_unlock(&card->conf_mutex);
return rc ? rc : count; return rc ? rc : count;
} }
...@@ -501,11 +498,9 @@ static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count, ...@@ -501,11 +498,9 @@ static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
int mask_bits; int mask_bits;
int rc = 0; int rc = 0;
mutex_lock(&card->conf_mutex);
rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits); rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
if (!rc) if (!rc)
rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits); rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
mutex_unlock(&card->conf_mutex);
return rc ? rc : count; return rc ? rc : count;
} }
...@@ -650,63 +645,34 @@ static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev, ...@@ -650,63 +645,34 @@ static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
QETH_IP_TYPE_VIPA); QETH_IP_TYPE_VIPA);
} }
static int qeth_l3_parse_vipae(const char *buf, enum qeth_prot_versions proto, static ssize_t qeth_l3_vipa_store(struct device *dev, const char *buf, bool add,
u8 *addr) size_t count, enum qeth_prot_versions proto)
{
if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
return -EINVAL;
}
return 0;
}
static ssize_t qeth_l3_dev_vipa_add_store(const char *buf, size_t count,
struct qeth_card *card, enum qeth_prot_versions proto)
{ {
struct qeth_card *card = dev_get_drvdata(dev);
u8 addr[16] = {0, }; u8 addr[16] = {0, };
int rc; int rc;
mutex_lock(&card->conf_mutex); rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
rc = qeth_l3_parse_vipae(buf, proto, addr);
if (!rc) if (!rc)
rc = qeth_l3_modify_rxip_vipa(card, true, addr, rc = qeth_l3_modify_rxip_vipa(card, add, addr,
QETH_IP_TYPE_VIPA, proto); QETH_IP_TYPE_VIPA, proto);
mutex_unlock(&card->conf_mutex);
return rc ? rc : count; return rc ? rc : count;
} }
static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev, static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct qeth_card *card = dev_get_drvdata(dev); return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4);
return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
} }
static QETH_DEVICE_ATTR(vipa_add4, add4, 0644, static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
qeth_l3_dev_vipa_add4_show, qeth_l3_dev_vipa_add4_show,
qeth_l3_dev_vipa_add4_store); qeth_l3_dev_vipa_add4_store);
static ssize_t qeth_l3_dev_vipa_del_store(const char *buf, size_t count,
struct qeth_card *card, enum qeth_prot_versions proto)
{
u8 addr[16];
int rc;
mutex_lock(&card->conf_mutex);
rc = qeth_l3_parse_vipae(buf, proto, addr);
if (!rc)
rc = qeth_l3_modify_rxip_vipa(card, false, addr,
QETH_IP_TYPE_VIPA, proto);
mutex_unlock(&card->conf_mutex);
return rc ? rc : count;
}
static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev, static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct qeth_card *card = dev_get_drvdata(dev); return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4);
return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
} }
static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL, static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
...@@ -723,9 +689,7 @@ static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev, ...@@ -723,9 +689,7 @@ static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev, static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct qeth_card *card = dev_get_drvdata(dev); return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV6);
return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
} }
static QETH_DEVICE_ATTR(vipa_add6, add6, 0644, static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
...@@ -735,9 +699,7 @@ static QETH_DEVICE_ATTR(vipa_add6, add6, 0644, ...@@ -735,9 +699,7 @@ static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev, static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct qeth_card *card = dev_get_drvdata(dev); return qeth_l3_vipa_store(dev, buf, false, count, QETH_PROT_IPV6);
return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
} }
static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL, static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
...@@ -790,54 +752,34 @@ static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto, ...@@ -790,54 +752,34 @@ static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
return 0; return 0;
} }
static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count, static ssize_t qeth_l3_rxip_store(struct device *dev, const char *buf, bool add,
struct qeth_card *card, enum qeth_prot_versions proto) size_t count, enum qeth_prot_versions proto)
{ {
struct qeth_card *card = dev_get_drvdata(dev);
u8 addr[16] = {0, }; u8 addr[16] = {0, };
int rc; int rc;
mutex_lock(&card->conf_mutex);
rc = qeth_l3_parse_rxipe(buf, proto, addr); rc = qeth_l3_parse_rxipe(buf, proto, addr);
if (!rc) if (!rc)
rc = qeth_l3_modify_rxip_vipa(card, true, addr, rc = qeth_l3_modify_rxip_vipa(card, add, addr,
QETH_IP_TYPE_RXIP, proto); QETH_IP_TYPE_RXIP, proto);
mutex_unlock(&card->conf_mutex);
return rc ? rc : count; return rc ? rc : count;
} }
static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev, static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct qeth_card *card = dev_get_drvdata(dev); return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV4);
return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
} }
static QETH_DEVICE_ATTR(rxip_add4, add4, 0644, static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
qeth_l3_dev_rxip_add4_show, qeth_l3_dev_rxip_add4_show,
qeth_l3_dev_rxip_add4_store); qeth_l3_dev_rxip_add4_store);
static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
struct qeth_card *card, enum qeth_prot_versions proto)
{
u8 addr[16];
int rc;
mutex_lock(&card->conf_mutex);
rc = qeth_l3_parse_rxipe(buf, proto, addr);
if (!rc)
rc = qeth_l3_modify_rxip_vipa(card, false, addr,
QETH_IP_TYPE_RXIP, proto);
mutex_unlock(&card->conf_mutex);
return rc ? rc : count;
}
static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev, static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct qeth_card *card = dev_get_drvdata(dev); return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV4);
return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
} }
static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL, static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
...@@ -854,9 +796,7 @@ static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev, ...@@ -854,9 +796,7 @@ static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev, static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct qeth_card *card = dev_get_drvdata(dev); return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV6);
return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
} }
static QETH_DEVICE_ATTR(rxip_add6, add6, 0644, static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
...@@ -866,9 +806,7 @@ static QETH_DEVICE_ATTR(rxip_add6, add6, 0644, ...@@ -866,9 +806,7 @@ static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev, static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct qeth_card *card = dev_get_drvdata(dev); return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV6);
return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
} }
static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL, static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment