lkml.org 
[lkml]   [2020]   [Apr]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 3/8] objtool: Rework allocating stack_ops on decode
On Thu, Apr 23, 2020 at 05:40:38PM +0200, Alexandre Chartre wrote:
>
> On 4/23/20 2:47 PM, Peter Zijlstra wrote:
> > Wrap each stack_op in a macro that allocates and adds it to the list.
> > This simplifies trying to figure out what to do with the pre-allocated
> > stack_op at the end.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > ---
> > tools/objtool/arch/x86/decode.c | 257 +++++++++++++++++++++++-----------------
> > 1 file changed, 153 insertions(+), 104 deletions(-)
> >
> > --- a/tools/objtool/arch/x86/decode.c
> > +++ b/tools/objtool/arch/x86/decode.c
> > @@ -77,6 +77,17 @@ unsigned long arch_jump_destination(stru
> > return insn->offset + insn->len + insn->immediate;
> > }
> > +#define PUSH_OP(op) \
> > +({ \
> > + list_add_tail(&op->list, ops_list); \
> > + NULL; \
> > +})
> > +
> > +#define ADD_OP(op) \
> > + if (!(op = calloc(1, sizeof(*op)))) \
> > + return -1; \
> > + else for (; op; op = PUSH_OP(op))
> > +
>
> I would better have a function to alloc+add op instead of weird macros,
> for example:

I know it'll not make you feel (much) better, but we can write it
shorter:

+#define ADD_OP(op) \
+ if (!(op = calloc(1, sizeof(*op)))) \
+ return -1; \
+ else for (list_add_tail(&op->list, ops_list); op; op = NULL)

Also, the kernel is full of funny macros like this ;-)

\
 
 \ /
  Last update: 2020-04-23 18:18    [W:0.058 / U:1.132 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site