Re: [PATCH v2 1/3] trace-cmd: Make read_proc() to return int status via OUT arg
From: Steven Rostedt
Date: Tue Jan 16 2018 - 14:34:41 EST
On Tue, 16 Jan 2018 20:49:22 +0200
Vladislav Valtchev <vladislav.valtchev@xxxxxxxxx> wrote:
> 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.
The thing is, since we only accept new_status to be 0-9, it can never
be negative. Thus we should make it unsigned. Yes read_proc() is
signed, but that's because it can be negative.
We are keeping the variables the same as the values they represent,
nothing more. One variable shouldn't affect what the other variable is,
as the ranges are indeed different.
-- Steve