lkml.org 
[lkml]   [2023]   [Jul]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 1/8] iio: core: Add opaque_struct_size() helper and use it
On Fri, Jul 21, 2023 at 08:00:15PM +0300, Andy Shevchenko wrote:
> Introduce opaque_struct_size() helper, which may be moved
> to overflow.h in the future, and use it in the IIO core.

...

> +#define opaque_struct_size(p, a, s) ({ \
> + size_t _psize = sizeof(*(p)); \
> + size_t _asize = ALIGN(_psize, (a)); \
> + size_t _ssize = s; \
> + _ssize ? size_add(_asize, _ssize) : _psize; \
> +})
> +
> +#define opaque_struct_data(p, a) \
> + ((void *)(p) + ALIGN(sizeof(*(p)), (a)))

Hmm... This can potentially evaluate p twice.

Perhaps this variant is better:

#define opaque_struct_data(p, a) ALIGN((p) + 1, (a)))

Besides, I don't think we should worry about @s evaluation in the main macro
which may be simplified to

#define opaque_struct_size(p, a, s) \
((s) ? size_add(ALIGN(sizeof(*(p)), (a)), (s)) : sizeof(*(p)))

Thoughts?

--
With Best Regards,
Andy Shevchenko


\
 
 \ /
  Last update: 2023-07-21 19:23    [W:0.165 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site