From: Vladislav Valtchev <vladislav.valtchev@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: y.karadz@gmail.com, linux-trace-devel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/3] trace-cmd: Make read_proc() to return int status via OUT arg
Date: Tue, 16 Jan 2018 20:49:22 +0200 [thread overview]
Message-ID: <1516128562.4042.12.camel@gmail.com> (raw)
In-Reply-To: <20180116112710.283b90f4@gandalf.local.home>
On Tue, 2018-01-16 at 11:27 -0500, Steven Rostedt wrote:
>
>
> :-) That was totally lost in translation. :-)
>
> No, I didn't mean to have a comment literally saying "why would strtol
> return zero and this not be an error", I meant for the comment to
> explain it.
>
> Actually, looking at the man page which states:
>
Yep, I got it.
Sometimes I interpret words too literally. My fault :-)
> I say we simply remove the comment. Or say what the man page example
> says:
>
> /* Check for various possible errors */
>
> and leave it at that.
Sure, "Check for various possible errors" sounds good to me.
>
> Sure it could be negative. The point was, you don't want it to be if
> you do:
>
> buf[0] = new_status + '0';
>
> As that will break if new_status is negative or greater than 9.
>
> Also, whether you use unsigned, or do the above, they both have the
> same result. A negative produces a warning. Which is fine. As long as
> it doesn't kill the program. It's only an implementation detail.
>
> That is, using unsigned char as new_status, and checking
>
> if (new_status > 9)
>
> Is no different than using int and checking
>
> if (new_status < 0 || new_status > 9)
>
> except that you use more instructions to accomplish the same thing.
>
Sure, using two checks with 'int' is less efficient then using the 'unsigned trick',
but my point is that such a function (at interface level) should accept exactly
the same type 'returned' (via OUT param) by read_proc(). It should be symmetric,
as if instead of 'int/unsigned' we used an opaque type 'value_t' for which we cannot
make assumptions. Clearly, the implementation may in practice accept a subset of the values
allowed by the parameter type.
What about accepting 'int' but doing the check this way:
if ((unsigned)new_status > 9) {
warning(...);
return;
}
This way, we'll keep the interface symmetric (with read_proc()) but, at the same time,
we use a more efficient check.
--
Vladislav Valtchev
VMware Open Source Technology Center
next prev parent reply other threads:[~2018-01-16 18:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-21 15:25 [PATCH v2 0/3] trace-cmd: Integrate stack tracer status in 'stat' Vladislav Valtchev (VMware)
2017-12-21 15:25 ` [PATCH v2 1/3] trace-cmd: Make read_proc() to return int status via OUT arg Vladislav Valtchev (VMware)
2018-01-12 15:13 ` Steven Rostedt
2018-01-16 14:47 ` Vladislav Valtchev
2018-01-16 16:27 ` Steven Rostedt
2018-01-16 18:49 ` Vladislav Valtchev [this message]
2018-01-16 19:34 ` Steven Rostedt
2017-12-21 15:25 ` [PATCH v2 2/3] trace-cmd: Remove the die() call from read_proc() Vladislav Valtchev (VMware)
2018-01-12 15:43 ` Steven Rostedt
2018-01-16 15:04 ` Vladislav Valtchev
2017-12-21 15:25 ` [PATCH v2 3/3] trace-cmd: Making stat to report when the stack tracer is ON Vladislav Valtchev (VMware)
2018-01-12 15:47 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1516128562.4042.12.camel@gmail.com \
--to=vladislav.valtchev@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=y.karadz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).