copy: reduce address evaluation

Prototect against future use of ++ operators in arguments ;)
This commit is contained in:
Thomas Schoebel-Theuer 2022-02-22 05:59:51 +01:00 committed by Thomas Schoebel-Theuer
parent 44f371ca7f
commit 602d1380ec
1 changed files with 7 additions and 4 deletions

View File

@ -49,9 +49,6 @@
#define STATES_PER_PAGE (PAGE_SIZE / sizeof(struct copy_state))
#define MAX_SUB_TABLES (NR_COPY_REQUESTS / STATES_PER_PAGE + (NR_COPY_REQUESTS % STATES_PER_PAGE ? 1 : 0))
#define GET_STATE(brick,index) \
((brick)->st[(__u64)(index) / STATES_PER_PAGE][(__u64)(index) % STATES_PER_PAGE])
/* Hint: MARS prefers safety, not maximum performance.
* For safety against compiler mischief, we use *_ONCE() on state fields
* (almost anywhere), at least for now.
@ -66,7 +63,13 @@
* no relevant memory deref to high-frequency updated mem.
*/
#define _GET_STATE(brick,index) \
(&GET_STATE(brick,index))
({ \
register __u64 __index = (index); \
register __u64 __page_index = __index / STATES_PER_PAGE; \
register __u64 __state_index = __index % STATES_PER_PAGE; \
\
&((brick)->st[__page_index][__state_index]); \
})
///////////////////////// own type definitions ////////////////////////