[Ksummit-discuss] [CORE TOPIC] More useful types in the linux kernel
Josh Triplett
josh at joshtriplett.org
Fri Aug 12 04:01:55 UTC 2016
On Thu, Aug 11, 2016 at 11:51:52PM -0400, Matthew Wilcox wrote:
> On Aug 11, 2016 8:44 AM, "Dan Carpenter" <dan.carpenter at oracle.com> wrote:
> > I need these manual fixes when not knowing the error code causes
> > problems because a function does this:
> > if (ret)
> > return ret;
> > But the caller does:
> > if (ret < 0)
> > return ret;
> > There is a mismatch because Smatch thinks any non-zero is an error but
> > the caller knows only negatives are errors.
>
> Can we introduce types for this? We have a number of different return type
> conventions in the kernel:
>
> bool
> errno_t (-4095 to 0 are valid)
> count_t (-4095 to INT_MAX)
> long_count_t (-4095 to LONG_MAX)
> ulong_count_t (-4095 to -4096)
> struct foo _err*
>
> I think this is good programmer documentation in addition to being
> potentially useful to smatch.
I'd love to see an explicit type distinct from "int" for "potentially an
errno". And if any code uses "potentially an errno *or* a non-errno
non-zero return value", that should ideally use a distinct type as well.
More information about the Ksummit-discuss
mailing list