Commit 5a8eeec4 authored by Anish Bhatt's avatar Anish Bhatt Committed by David S. Miller

cxgb4: Fix incorrect 'c' suffix to %pI4, use %pISc instead

Issue caught by 0-day kernel test infrastructure. Code changed to use sockaddr
members so that %pISc can be used instead.

Fixes: b5a02f50 ('cxgb4 : Update ipv6 address handling api')
Signed-off-by: default avatarAnish Bhatt <anish@chelsio.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 65e9256c
...@@ -35,10 +35,10 @@ static inline unsigned int ipv6_clip_hash(struct clip_tbl *d, const u32 *key) ...@@ -35,10 +35,10 @@ static inline unsigned int ipv6_clip_hash(struct clip_tbl *d, const u32 *key)
} }
static unsigned int clip_addr_hash(struct clip_tbl *ctbl, const u32 *addr, static unsigned int clip_addr_hash(struct clip_tbl *ctbl, const u32 *addr,
int addr_len) u8 v6)
{ {
return addr_len == 4 ? ipv4_clip_hash(ctbl, addr) : return v6 ? ipv6_clip_hash(ctbl, addr) :
ipv6_clip_hash(ctbl, addr); ipv4_clip_hash(ctbl, addr);
} }
static int clip6_get_mbox(const struct net_device *dev, static int clip6_get_mbox(const struct net_device *dev,
...@@ -78,23 +78,22 @@ int cxgb4_clip_get(const struct net_device *dev, const u32 *lip, u8 v6) ...@@ -78,23 +78,22 @@ int cxgb4_clip_get(const struct net_device *dev, const u32 *lip, u8 v6)
struct clip_entry *ce, *cte; struct clip_entry *ce, *cte;
u32 *addr = (u32 *)lip; u32 *addr = (u32 *)lip;
int hash; int hash;
int addr_len; int ret = -1;
int ret = 0;
if (!ctbl) if (!ctbl)
return 0; return 0;
if (v6) hash = clip_addr_hash(ctbl, addr, v6);
addr_len = 16;
else
addr_len = 4;
hash = clip_addr_hash(ctbl, addr, addr_len);
read_lock_bh(&ctbl->lock); read_lock_bh(&ctbl->lock);
list_for_each_entry(cte, &ctbl->hash_list[hash], list) { list_for_each_entry(cte, &ctbl->hash_list[hash], list) {
if (addr_len == cte->addr_len && if (cte->addr6.sin6_family == AF_INET6 && v6)
memcmp(lip, cte->addr, cte->addr_len) == 0) { ret = memcmp(lip, cte->addr6.sin6_addr.s6_addr,
sizeof(struct in6_addr));
else if (cte->addr.sin_family == AF_INET && !v6)
ret = memcmp(lip, (char *)(&cte->addr.sin_addr),
sizeof(struct in_addr));
if (!ret) {
ce = cte; ce = cte;
read_unlock_bh(&ctbl->lock); read_unlock_bh(&ctbl->lock);
goto found; goto found;
...@@ -111,15 +110,20 @@ int cxgb4_clip_get(const struct net_device *dev, const u32 *lip, u8 v6) ...@@ -111,15 +110,20 @@ int cxgb4_clip_get(const struct net_device *dev, const u32 *lip, u8 v6)
spin_lock_init(&ce->lock); spin_lock_init(&ce->lock);
atomic_set(&ce->refcnt, 0); atomic_set(&ce->refcnt, 0);
atomic_dec(&ctbl->nfree); atomic_dec(&ctbl->nfree);
ce->addr_len = addr_len;
memcpy(ce->addr, lip, addr_len);
list_add_tail(&ce->list, &ctbl->hash_list[hash]); list_add_tail(&ce->list, &ctbl->hash_list[hash]);
if (v6) { if (v6) {
ce->addr6.sin6_family = AF_INET6;
memcpy(ce->addr6.sin6_addr.s6_addr,
lip, sizeof(struct in6_addr));
ret = clip6_get_mbox(dev, (const struct in6_addr *)lip); ret = clip6_get_mbox(dev, (const struct in6_addr *)lip);
if (ret) { if (ret) {
write_unlock_bh(&ctbl->lock); write_unlock_bh(&ctbl->lock);
return ret; return ret;
} }
} else {
ce->addr.sin_family = AF_INET;
memcpy((char *)(&ce->addr.sin_addr), lip,
sizeof(struct in_addr));
} }
} else { } else {
write_unlock_bh(&ctbl->lock); write_unlock_bh(&ctbl->lock);
...@@ -140,19 +144,19 @@ void cxgb4_clip_release(const struct net_device *dev, const u32 *lip, u8 v6) ...@@ -140,19 +144,19 @@ void cxgb4_clip_release(const struct net_device *dev, const u32 *lip, u8 v6)
struct clip_entry *ce, *cte; struct clip_entry *ce, *cte;
u32 *addr = (u32 *)lip; u32 *addr = (u32 *)lip;
int hash; int hash;
int addr_len; int ret = -1;
if (v6)
addr_len = 16;
else
addr_len = 4;
hash = clip_addr_hash(ctbl, addr, addr_len); hash = clip_addr_hash(ctbl, addr, v6);
read_lock_bh(&ctbl->lock); read_lock_bh(&ctbl->lock);
list_for_each_entry(cte, &ctbl->hash_list[hash], list) { list_for_each_entry(cte, &ctbl->hash_list[hash], list) {
if (addr_len == cte->addr_len && if (cte->addr6.sin6_family == AF_INET6 && v6)
memcmp(lip, cte->addr, cte->addr_len) == 0) { ret = memcmp(lip, cte->addr6.sin6_addr.s6_addr,
sizeof(struct in6_addr));
else if (cte->addr.sin_family == AF_INET && !v6)
ret = memcmp(lip, (char *)(&cte->addr.sin_addr),
sizeof(struct in_addr));
if (!ret) {
ce = cte; ce = cte;
read_unlock_bh(&ctbl->lock); read_unlock_bh(&ctbl->lock);
goto found; goto found;
...@@ -249,10 +253,7 @@ int clip_tbl_show(struct seq_file *seq, void *v) ...@@ -249,10 +253,7 @@ int clip_tbl_show(struct seq_file *seq, void *v)
for (i = 0 ; i < ctbl->clipt_size; ++i) { for (i = 0 ; i < ctbl->clipt_size; ++i) {
list_for_each_entry(ce, &ctbl->hash_list[i], list) { list_for_each_entry(ce, &ctbl->hash_list[i], list) {
ip[0] = '\0'; ip[0] = '\0';
if (ce->addr_len == 16) sprintf(ip, "%pISc", &ce->addr);
sprintf(ip, "%pI6c", ce->addr);
else
sprintf(ip, "%pI4c", ce->addr);
seq_printf(seq, "%-25s %u\n", ip, seq_printf(seq, "%-25s %u\n", ip,
atomic_read(&ce->refcnt)); atomic_read(&ce->refcnt));
} }
......
...@@ -14,8 +14,10 @@ struct clip_entry { ...@@ -14,8 +14,10 @@ struct clip_entry {
spinlock_t lock; /* Hold while modifying clip reference */ spinlock_t lock; /* Hold while modifying clip reference */
atomic_t refcnt; atomic_t refcnt;
struct list_head list; struct list_head list;
u32 addr[4]; union {
int addr_len; struct sockaddr_in addr;
struct sockaddr_in6 addr6;
};
}; };
struct clip_tbl { struct clip_tbl {
......
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