Skip to content

Commit 2390166

Browse files
julianwiedmanndavem330
authored andcommitted
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: Julian Wiedmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e6b1b7d commit 2390166

File tree

2 files changed

+33
-85
lines changed

2 files changed

+33
-85
lines changed

drivers/s390/net/qeth_l3_main.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ int qeth_l3_add_ipato_entry(struct qeth_card *card,
571571

572572
QETH_CARD_TEXT(card, 2, "addipato");
573573

574+
mutex_lock(&card->conf_mutex);
574575
mutex_lock(&card->ip_lock);
575576

576577
list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
@@ -590,6 +591,7 @@ int qeth_l3_add_ipato_entry(struct qeth_card *card,
590591
}
591592

592593
mutex_unlock(&card->ip_lock);
594+
mutex_unlock(&card->conf_mutex);
593595

594596
return rc;
595597
}
@@ -603,6 +605,7 @@ int qeth_l3_del_ipato_entry(struct qeth_card *card,
603605

604606
QETH_CARD_TEXT(card, 2, "delipato");
605607

608+
mutex_lock(&card->conf_mutex);
606609
mutex_lock(&card->ip_lock);
607610

608611
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,
619622
}
620623

621624
mutex_unlock(&card->ip_lock);
625+
mutex_unlock(&card->conf_mutex);
626+
622627
return rc;
623628
}
624629

@@ -627,14 +632,19 @@ int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
627632
enum qeth_prot_versions proto)
628633
{
629634
struct qeth_ipaddr addr;
635+
int rc;
630636

631637
qeth_l3_init_ipaddr(&addr, type, proto);
632638
if (proto == QETH_PROT_IPV4)
633639
memcpy(&addr.u.a4.addr, ip, 4);
634640
else
635641
memcpy(&addr.u.a6.addr, ip, 16);
636642

637-
return qeth_l3_modify_ip(card, &addr, add);
643+
mutex_lock(&card->conf_mutex);
644+
rc = qeth_l3_modify_ip(card, &addr, add);
645+
mutex_unlock(&card->conf_mutex);
646+
647+
return rc;
638648
}
639649

640650
int qeth_l3_modify_hsuid(struct qeth_card *card, bool add)

drivers/s390/net/qeth_l3_sys.c

Lines changed: 22 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -460,25 +460,22 @@ static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
460460
int mask_bits;
461461
int rc = 0;
462462

463-
mutex_lock(&card->conf_mutex);
464463
rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
465464
if (rc)
466-
goto out;
465+
return rc;
467466

468467
ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
469-
if (!ipatoe) {
470-
rc = -ENOMEM;
471-
goto out;
472-
}
468+
if (!ipatoe)
469+
return -ENOMEM;
470+
473471
ipatoe->proto = proto;
474472
memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
475473
ipatoe->mask_bits = mask_bits;
476474

477475
rc = qeth_l3_add_ipato_entry(card, ipatoe);
478476
if (rc)
479477
kfree(ipatoe);
480-
out:
481-
mutex_unlock(&card->conf_mutex);
478+
482479
return rc ? rc : count;
483480
}
484481

@@ -501,11 +498,9 @@ static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
501498
int mask_bits;
502499
int rc = 0;
503500

504-
mutex_lock(&card->conf_mutex);
505501
rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
506502
if (!rc)
507503
rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
508-
mutex_unlock(&card->conf_mutex);
509504
return rc ? rc : count;
510505
}
511506

@@ -650,63 +645,34 @@ static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
650645
QETH_IP_TYPE_VIPA);
651646
}
652647

653-
static int qeth_l3_parse_vipae(const char *buf, enum qeth_prot_versions proto,
654-
u8 *addr)
655-
{
656-
if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
657-
return -EINVAL;
658-
}
659-
return 0;
660-
}
661-
662-
static ssize_t qeth_l3_dev_vipa_add_store(const char *buf, size_t count,
663-
struct qeth_card *card, enum qeth_prot_versions proto)
648+
static ssize_t qeth_l3_vipa_store(struct device *dev, const char *buf, bool add,
649+
size_t count, enum qeth_prot_versions proto)
664650
{
651+
struct qeth_card *card = dev_get_drvdata(dev);
665652
u8 addr[16] = {0, };
666653
int rc;
667654

668-
mutex_lock(&card->conf_mutex);
669-
rc = qeth_l3_parse_vipae(buf, proto, addr);
655+
rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
670656
if (!rc)
671-
rc = qeth_l3_modify_rxip_vipa(card, true, addr,
657+
rc = qeth_l3_modify_rxip_vipa(card, add, addr,
672658
QETH_IP_TYPE_VIPA, proto);
673-
mutex_unlock(&card->conf_mutex);
674659
return rc ? rc : count;
675660
}
676661

677662
static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
678663
struct device_attribute *attr, const char *buf, size_t count)
679664
{
680-
struct qeth_card *card = dev_get_drvdata(dev);
681-
682-
return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
665+
return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4);
683666
}
684667

685668
static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
686669
qeth_l3_dev_vipa_add4_show,
687670
qeth_l3_dev_vipa_add4_store);
688671

689-
static ssize_t qeth_l3_dev_vipa_del_store(const char *buf, size_t count,
690-
struct qeth_card *card, enum qeth_prot_versions proto)
691-
{
692-
u8 addr[16];
693-
int rc;
694-
695-
mutex_lock(&card->conf_mutex);
696-
rc = qeth_l3_parse_vipae(buf, proto, addr);
697-
if (!rc)
698-
rc = qeth_l3_modify_rxip_vipa(card, false, addr,
699-
QETH_IP_TYPE_VIPA, proto);
700-
mutex_unlock(&card->conf_mutex);
701-
return rc ? rc : count;
702-
}
703-
704672
static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
705673
struct device_attribute *attr, const char *buf, size_t count)
706674
{
707-
struct qeth_card *card = dev_get_drvdata(dev);
708-
709-
return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
675+
return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4);
710676
}
711677

712678
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,
723689
static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
724690
struct device_attribute *attr, const char *buf, size_t count)
725691
{
726-
struct qeth_card *card = dev_get_drvdata(dev);
727-
728-
return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
692+
return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV6);
729693
}
730694

731695
static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
@@ -735,9 +699,7 @@ static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
735699
static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
736700
struct device_attribute *attr, const char *buf, size_t count)
737701
{
738-
struct qeth_card *card = dev_get_drvdata(dev);
739-
740-
return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
702+
return qeth_l3_vipa_store(dev, buf, false, count, QETH_PROT_IPV6);
741703
}
742704

743705
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,
790752
return 0;
791753
}
792754

793-
static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count,
794-
struct qeth_card *card, enum qeth_prot_versions proto)
755+
static ssize_t qeth_l3_rxip_store(struct device *dev, const char *buf, bool add,
756+
size_t count, enum qeth_prot_versions proto)
795757
{
758+
struct qeth_card *card = dev_get_drvdata(dev);
796759
u8 addr[16] = {0, };
797760
int rc;
798761

799-
mutex_lock(&card->conf_mutex);
800762
rc = qeth_l3_parse_rxipe(buf, proto, addr);
801763
if (!rc)
802-
rc = qeth_l3_modify_rxip_vipa(card, true, addr,
764+
rc = qeth_l3_modify_rxip_vipa(card, add, addr,
803765
QETH_IP_TYPE_RXIP, proto);
804-
mutex_unlock(&card->conf_mutex);
805766
return rc ? rc : count;
806767
}
807768

808769
static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
809770
struct device_attribute *attr, const char *buf, size_t count)
810771
{
811-
struct qeth_card *card = dev_get_drvdata(dev);
812-
813-
return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
772+
return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV4);
814773
}
815774

816775
static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
817776
qeth_l3_dev_rxip_add4_show,
818777
qeth_l3_dev_rxip_add4_store);
819778

820-
static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
821-
struct qeth_card *card, enum qeth_prot_versions proto)
822-
{
823-
u8 addr[16];
824-
int rc;
825-
826-
mutex_lock(&card->conf_mutex);
827-
rc = qeth_l3_parse_rxipe(buf, proto, addr);
828-
if (!rc)
829-
rc = qeth_l3_modify_rxip_vipa(card, false, addr,
830-
QETH_IP_TYPE_RXIP, proto);
831-
mutex_unlock(&card->conf_mutex);
832-
return rc ? rc : count;
833-
}
834-
835779
static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
836780
struct device_attribute *attr, const char *buf, size_t count)
837781
{
838-
struct qeth_card *card = dev_get_drvdata(dev);
839-
840-
return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
782+
return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV4);
841783
}
842784

843785
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,
854796
static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
855797
struct device_attribute *attr, const char *buf, size_t count)
856798
{
857-
struct qeth_card *card = dev_get_drvdata(dev);
858-
859-
return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
799+
return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV6);
860800
}
861801

862802
static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
@@ -866,9 +806,7 @@ static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
866806
static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
867807
struct device_attribute *attr, const char *buf, size_t count)
868808
{
869-
struct qeth_card *card = dev_get_drvdata(dev);
870-
871-
return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
809+
return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV6);
872810
}
873811

874812
static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,

0 commit comments

Comments
 (0)