Re: [RFC PATCH 5/4] tracing: Simplify the ftrace_event_fielditeration in f_next/f_show

From: Oleg Nesterov
Date: Wed Jul 17 2013 - 15:42:25 EST


On 07/17, Oleg Nesterov wrote:
>
> f_next() looks overcomplicated, and it is not strictly correct
> even if this doesn't matter.

Honestly, I do not know what the changelog can say to explain
this patch except "make the code simpler/cleaner".

To simplify the review, please see f_next/f_start with this patch
applied below. f_show() does field = list_entry(v, ...).

Probably makes sense anyway, I even tried to test it. So I would
not mind if you apply it as a separate cleanup ;)

Oleg.

static void *f_next(struct seq_file *m, void *v, loff_t *pos)
{
struct ftrace_event_call *call = m->private;
struct list_head *common_head = &ftrace_common_fields;
struct list_head *head = trace_get_fields(call);
struct list_head *node = v;

(*pos)++;

switch ((unsigned long)v) {
case FORMAT_HEADER:
node = common_head;
break;

case FORMAT_FIELD_SEPERATOR:
node = head;
break;

case FORMAT_PRINTFMT:
/* all done */
return NULL;
}

node = node->prev;
if (node == common_head)
return (void *)FORMAT_FIELD_SEPERATOR;
else if (node == head)
return (void *)FORMAT_PRINTFMT;
else
return node;
}

static void *f_start(struct seq_file *m, loff_t *pos)
{
void *p = (void *)FORMAT_HEADER;
loff_t l = 0;

while (p && l < *pos)
p = f_next(m, p, &l);

return p;
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/