Re: [PATCH rdma-next] RDMA: Provide safe ib_alloc_device() function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1/28/19 6:14 AM, Leon Romanovsky wrote:
-struct ib_device *ib_alloc_device(size_t size);
+void *_ib_alloc_device(size_t size);
+#define ib_alloc_device(drv_struct, member)                                    \
+	(BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)) +              \
+	 BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(                      \
+		 typeof(((struct drv_struct *)NULL)->member),                  \
+		 struct ib_device)) +                                          \
+	 _ib_alloc_device(sizeof(struct drv_struct)))
+

Hi Leon,

Have you considered to use a comma expression and BUILD_BUG_ON() instead of adding the BUILD_BUG_ON_ZERO() results to the _ib_alloc_device() return value? I think that would result in slightly easier to read code and also in code that reflects the intent better.

Thanks,

Bart.



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux