lkml.org 
[lkml]   [2008]   [Sep]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: A style question: repeated return value check

* Pekka Paalanen <pq@iki.fi> wrote:

> > kernel/trace/trace.c | 77 ++++++++++++++++++++++++++-----------------------
> > kernel/trace/trace.h | 10 ++++++-
> > 2 files changed, 50 insertions(+), 37 deletions(-)
> >
> > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> > index 6ada059..61f33da 100644
> > --- a/kernel/trace/trace.c
> > +++ b/kernel/trace/trace.c
> [...]
> > @@ -1633,24 +1633,24 @@ static int print_trace_fmt(struct trace_iterator *iter)
> >
> > ret = trace_seq_printf(s, "%16s-%-5d ", comm, field->pid);
> > if (!ret)
> > - return 0;
> > + return TRACE_TYPE_PARTIAL_LINE;
> > ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
> > if (!ret)
> > - return 0;
> > + return TRACE_TYPE_PARTIAL_LINE;
> > ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
> > if (!ret)
> > - return 0;
> > + return TRACE_TYPE_PARTIAL_LINE;
>
> Off-thread style question: Would it be better or worse to write the
> above as
>
> ret = trace_seq_printf(s, "%16s-%-5d ", comm, field->pid);
> ret = ret && trace_seq_printf(s, "[%03d] ", iter->cpu);
> ret = ret && trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
> if (!ret)
> return TRACE_TYPE_PARTIAL_LINE;
>
> which would do exactly the same, but is more compact.
> Good or bad style?

in this particular case it's marginally worse style i think, even
considering that it makes the code more compact. The reason is that it
makes the code a tiny bit less obvious: the flow looks a bit unusual and
when skimming it i'd have to look once more to understand its purpose.
With the returns its more verbose but also plain obvious. YMMV.

Ingo


\
 
 \ /
  Last update: 2008-09-30 10:37    [W:3.733 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site