diff options
author | Leon Romanovsky <leonro@mellanox.com> | 2019-01-30 11:49:11 +0100 |
---|---|---|
committer | Jason Gunthorpe <jgg@mellanox.com> | 2019-01-30 23:52:30 +0100 |
commit | 459cc69fa4c17caf21de596693d8a07170820a58 (patch) | |
tree | c1ffe44d059b43b9507c5926873c3c56a4dd8bb3 /include/rdma | |
parent | IB/mlx5: Remove set but not used variable (diff) | |
download | linux-459cc69fa4c17caf21de596693d8a07170820a58.tar.xz linux-459cc69fa4c17caf21de596693d8a07170820a58.zip |
RDMA: Provide safe ib_alloc_device() function
All callers to ib_alloc_device() provide a larger size than struct
ib_device and rely on the fact that struct ib_device is embedded in their
driver specific structure as the first member.
Provide a safer variant of ib_alloc_device() that checks and enforces this
approach to make sure the drivers are using it right.
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Diffstat (limited to 'include/rdma')
-rw-r--r-- | include/rdma/ib_verbs.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 71ea144ec823..a1a1e710642c 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -2621,7 +2621,13 @@ struct ib_client { struct list_head list; }; -struct ib_device *ib_alloc_device(size_t size); +struct ib_device *_ib_alloc_device(size_t size); +#define ib_alloc_device(drv_struct, member) \ + container_of(_ib_alloc_device(sizeof(struct drv_struct) + \ + BUILD_BUG_ON_ZERO(offsetof( \ + struct drv_struct, member))), \ + struct drv_struct, member) + void ib_dealloc_device(struct ib_device *device); void ib_get_device_fw_str(struct ib_device *device, char *str); |