OSDN Git Service

s390/qeth: remove open-coded inet_make_mask()
authorJulian Wiedmann <jwi@linux.ibm.com>
Wed, 18 Dec 2019 16:34:46 +0000 (17:34 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 18 Dec 2019 20:34:56 +0000 (12:34 -0800)
Use inet_make_mask() to replace some complicated bit-fiddling.

Also use the right data types to replace some raw memcpy calls with
proper assignments.

Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/s390/net/qeth_core_mpc.h
drivers/s390/net/qeth_l3.h
drivers/s390/net/qeth_l3_main.c

index 88f4dc1..f13225b 100644 (file)
@@ -338,14 +338,14 @@ enum qeth_card_info_port_speed {
 
 /* (SET)DELIP(M) IPA stuff ***************************************************/
 struct qeth_ipacmd_setdelip4 {
-       __u8   ip_addr[4];
-       __u8   mask[4];
+       __be32 addr;
+       __be32 mask;
        __u32  flags;
 } __attribute__ ((packed));
 
 struct qeth_ipacmd_setdelip6 {
-       __u8   ip_addr[16];
-       __u8   mask[16];
+       struct in6_addr addr;
+       struct in6_addr prefix;
        __u32  flags;
 } __attribute__ ((packed));
 
index 2383ffa..89fb91d 100644 (file)
@@ -35,7 +35,7 @@ struct qeth_ipaddr {
        union {
                struct {
                        __be32 addr;
-                       unsigned int mask;
+                       __be32 mask;
                } a4;
                struct {
                        struct in6_addr addr;
index 8db5483..bd2273f 100644 (file)
@@ -369,17 +369,16 @@ static int qeth_l3_send_setdelmc(struct qeth_card *card,
        return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL);
 }
 
-static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
+static void qeth_l3_set_ipv6_prefix(struct in6_addr *prefix, unsigned int len)
 {
-       int i, j;
-       for (i = 0; i < 16; i++) {
-               j = (len) - (i * 8);
-               if (j >= 8)
-                       netmask[i] = 0xff;
-               else if (j > 0)
-                       netmask[i] = (u8)(0xFF00 >> j);
-               else
-                       netmask[i] = 0;
+       unsigned int i = 0;
+
+       while (len && i < 4) {
+               int mask_len = min_t(int, len, 32);
+
+               prefix->s6_addr32[i] = inet_make_mask(mask_len);
+               len -= mask_len;
+               i++;
        }
 }
 
@@ -402,7 +401,6 @@ static int qeth_l3_send_setdelip(struct qeth_card *card,
 {
        struct qeth_cmd_buffer *iob;
        struct qeth_ipa_cmd *cmd;
-       __u8 netmask[16];
        u32 flags;
 
        QETH_CARD_TEXT(card, 4, "setdelip");
@@ -417,15 +415,13 @@ static int qeth_l3_send_setdelip(struct qeth_card *card,
        QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
 
        if (addr->proto == QETH_PROT_IPV6) {
-               memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
-                      sizeof(struct in6_addr));
-               qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
-               memcpy(cmd->data.setdelip6.mask, netmask,
-                      sizeof(struct in6_addr));
+               cmd->data.setdelip6.addr = addr->u.a6.addr;
+               qeth_l3_set_ipv6_prefix(&cmd->data.setdelip6.prefix,
+                                       addr->u.a6.pfxlen);
                cmd->data.setdelip6.flags = flags;
        } else {
-               memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
-               memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
+               cmd->data.setdelip4.addr = addr->u.a4.addr;
+               cmd->data.setdelip4.mask = addr->u.a4.mask;
                cmd->data.setdelip4.flags = flags;
        }
 
@@ -2436,7 +2432,7 @@ static int qeth_l3_ip_event(struct notifier_block *this,
 
        qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4);
        addr.u.a4.addr = ifa->ifa_address;
-       addr.u.a4.mask = be32_to_cpu(ifa->ifa_mask);
+       addr.u.a4.mask = ifa->ifa_mask;
 
        return qeth_l3_handle_ip_event(card, &addr, event);
 }