diff options
author | Amar Tumballi <amarts@redhat.com> | 2018-07-02 17:21:21 +0530 |
---|---|---|
committer | Shyamsundar Ranganathan <srangana@redhat.com> | 2018-07-03 19:12:26 +0000 |
commit | c80075466ddbf25766dbf805cd5161c736190b3e (patch) | |
tree | 3e37c8aac6d714e0860e7aa18cf1a7940ba8a363 /libglusterfs/src/stack.h | |
parent | 524c869976c837c2ef13b5ef50020e7769188e4d (diff) |
stack.h: fix the pass_through logic
while fixing the coverity issues, we made a minor mistake in the
pass through logic in STACK_WIND macro.
Also, with this patch, made the code common to reduce possible
future errors creeping in due to missing one place update.
updates: bz#1193929
Change-Id: I6fcfd156d63b0a7e6208819872e565eacf774150
Signed-off-by: Amar Tumballi <amarts@redhat.com>
Diffstat (limited to 'libglusterfs/src/stack.h')
-rw-r--r-- | libglusterfs/src/stack.h | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/libglusterfs/src/stack.h b/libglusterfs/src/stack.h index abcc2677350..212a649d42e 100644 --- a/libglusterfs/src/stack.h +++ b/libglusterfs/src/stack.h @@ -259,6 +259,18 @@ STACK_RESET (call_stack_t *stack) #define get_fop_index_from_fn(xl, fn) \ (1 + (((long)&(fn) - (long)&((xl)->fops->stat)) / sizeof (void *))) +/* NOTE: the above reason holds good here too. But notice that we are getting + the base address of the 'stat' fop, which is the first entry in the fop + structure. All we need to do is move as much as 'idx' fields, and get the + actual pointer from that field. */ + +static inline void * +get_the_pt_fop(void *base_fop, int fop_idx) +{ + void *target_addr = (base_fop + ((fop_idx - 1) * sizeof (void *))); + /* all below type casting is for not getting warning. */ + return (void *)*(unsigned long *)target_addr; +} /* make a call without switching frames */ #define STACK_WIND_TAIL(frame, obj, fn, params ...) \ @@ -286,11 +298,7 @@ STACK_RESET (call_stack_t *stack) } \ \ if (next_xl->pass_through) { \ - /* next_xl_fn = (void *)*((&next_xl->pass_through_fops->stat) + (opn - 1)); - * This assignment is changed to fix ARRAY_VS_SINGLETON coverity error. - */ \ - void *base_addr = &next_xl->pass_through_fops->stat; \ - next_xl_fn = base_addr + ((opn - 1) * sizeof(void*)); \ + next_xl_fn = get_the_pt_fop(&next_xl->pass_through_fops->stat, opn); \ } \ next_xl_fn (frame, next_xl, params); \ THIS = old_THIS; \ @@ -355,11 +363,8 @@ STACK_RESET (call_stack_t *stack) GF_ATOMIC_INC (obj->stats.total.count); \ GF_ATOMIC_INC (obj->stats.interval.count); \ } else { \ - /* next_xl_fn = (void *)*((&obj->pass_through_fops->stat) + (_new->op - 1)); - * This assignment is changed to fix ARRAY_VS_SINGLETON coverity error. - */ \ - void *base_addr = &obj->pass_through_fops->stat; \ - next_xl_fn = base_addr + ((_new->op - 1) * sizeof(void*)); \ + /* we want to get to the actual fop to call */ \ + next_xl_fn = get_the_pt_fop(&obj->pass_through_fops->stat, _new->op); \ } \ next_xl_fn (_new, obj, params); \ THIS = old_THIS; \ |