Skip to content

Commit

Permalink
cxgb4: Fix incorrect 'c' suffix to %pI4, use %pISc instead
Browse files Browse the repository at this point in the history
Issue caught by 0-day kernel test infrastructure. Code changed to use sockaddr
members so that %pISc can be used instead.

Fixes: b5a02f5 ('cxgb4 : Update ipv6 address handling api')

Signed-off-by: Anish Bhatt <anish@chelsio.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Anish Bhatt authored and David S. Miller committed Feb 20, 2015
1 parent 65e9256 commit 5a8eeec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
57 changes: 29 additions & 28 deletions drivers/net/ethernet/chelsio/cxgb4/clip_tbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
int addr_len)
u8 v6)
{
return addr_len == 4 ? ipv4_clip_hash(ctbl, addr) :
ipv6_clip_hash(ctbl, addr);
return v6 ? ipv6_clip_hash(ctbl, addr) :
ipv4_clip_hash(ctbl, addr);
}

static int clip6_get_mbox(const struct net_device *dev,
Expand Down Expand Up @@ -78,23 +78,22 @@ int cxgb4_clip_get(const struct net_device *dev, const u32 *lip, u8 v6)
struct clip_entry *ce, *cte;
u32 *addr = (u32 *)lip;
int hash;
int addr_len;
int ret = 0;
int ret = -1;

if (!ctbl)
return 0;

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);
list_for_each_entry(cte, &ctbl->hash_list[hash], list) {
if (addr_len == cte->addr_len &&
memcmp(lip, cte->addr, cte->addr_len) == 0) {
if (cte->addr6.sin6_family == AF_INET6 && v6)
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;
read_unlock_bh(&ctbl->lock);
goto found;
Expand All @@ -111,15 +110,20 @@ int cxgb4_clip_get(const struct net_device *dev, const u32 *lip, u8 v6)
spin_lock_init(&ce->lock);
atomic_set(&ce->refcnt, 0);
atomic_dec(&ctbl->nfree);
ce->addr_len = addr_len;
memcpy(ce->addr, lip, addr_len);
list_add_tail(&ce->list, &ctbl->hash_list[hash]);
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);
if (ret) {
write_unlock_bh(&ctbl->lock);
return ret;
}
} else {
ce->addr.sin_family = AF_INET;
memcpy((char *)(&ce->addr.sin_addr), lip,
sizeof(struct in_addr));
}
} else {
write_unlock_bh(&ctbl->lock);
Expand All @@ -140,19 +144,19 @@ void cxgb4_clip_release(const struct net_device *dev, const u32 *lip, u8 v6)
struct clip_entry *ce, *cte;
u32 *addr = (u32 *)lip;
int hash;
int addr_len;

if (v6)
addr_len = 16;
else
addr_len = 4;
int ret = -1;

hash = clip_addr_hash(ctbl, addr, addr_len);
hash = clip_addr_hash(ctbl, addr, v6);

read_lock_bh(&ctbl->lock);
list_for_each_entry(cte, &ctbl->hash_list[hash], list) {
if (addr_len == cte->addr_len &&
memcmp(lip, cte->addr, cte->addr_len) == 0) {
if (cte->addr6.sin6_family == AF_INET6 && v6)
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;
read_unlock_bh(&ctbl->lock);
goto found;
Expand Down Expand Up @@ -249,10 +253,7 @@ int clip_tbl_show(struct seq_file *seq, void *v)
for (i = 0 ; i < ctbl->clipt_size; ++i) {
list_for_each_entry(ce, &ctbl->hash_list[i], list) {
ip[0] = '\0';
if (ce->addr_len == 16)
sprintf(ip, "%pI6c", ce->addr);
else
sprintf(ip, "%pI4c", ce->addr);
sprintf(ip, "%pISc", &ce->addr);
seq_printf(seq, "%-25s %u\n", ip,
atomic_read(&ce->refcnt));
}
Expand Down
6 changes: 4 additions & 2 deletions drivers/net/ethernet/chelsio/cxgb4/clip_tbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ struct clip_entry {
spinlock_t lock; /* Hold while modifying clip reference */
atomic_t refcnt;
struct list_head list;
u32 addr[4];
int addr_len;
union {
struct sockaddr_in addr;
struct sockaddr_in6 addr6;
};
};

struct clip_tbl {
Expand Down

0 comments on commit 5a8eeec

Please sign in to comment.