65dc2f1a44
The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99: struct foo { int stuff; struct boo array[]; }; By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on. Also, notice that, dynamic memory allocations won't be affected by this change: "Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1] This issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] https://github.com/KSPP/linux/issues/21 [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Signed-off-by: David S. Miller <davem@davemloft.net>
46 lines
1.3 KiB
C
46 lines
1.3 KiB
C
/*
|
|
* This file is part of the Chelsio T4 Ethernet driver for Linux.
|
|
* Copyright (C) 2003-2014 Chelsio Communications. All rights reserved.
|
|
*
|
|
* Written by Deepak (deepak.s@chelsio.com)
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE file included in this
|
|
* release for licensing terms and conditions.
|
|
*/
|
|
|
|
#include <linux/refcount.h>
|
|
|
|
struct clip_entry {
|
|
spinlock_t lock; /* Hold while modifying clip reference */
|
|
refcount_t refcnt;
|
|
struct list_head list;
|
|
union {
|
|
struct sockaddr_in addr;
|
|
struct sockaddr_in6 addr6;
|
|
};
|
|
};
|
|
|
|
struct clip_tbl {
|
|
unsigned int clipt_start;
|
|
unsigned int clipt_size;
|
|
rwlock_t lock;
|
|
atomic_t nfree;
|
|
struct list_head ce_free_head;
|
|
void *cl_list;
|
|
struct list_head hash_list[];
|
|
};
|
|
|
|
enum {
|
|
CLIPT_MIN_HASH_BUCKETS = 2,
|
|
};
|
|
|
|
struct clip_tbl *t4_init_clip_tbl(unsigned int clipt_start,
|
|
unsigned int clipt_end);
|
|
int cxgb4_clip_get(const struct net_device *dev, const u32 *lip, u8 v6);
|
|
void cxgb4_clip_release(const struct net_device *dev, const u32 *lip, u8 v6);
|
|
int clip_tbl_show(struct seq_file *seq, void *v);
|
|
int cxgb4_update_root_dev_clip(struct net_device *dev);
|
|
void t4_cleanup_clip_tbl(struct adapter *adap);
|