Re: Must check what?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Oct 04, 2006, at 15:43:10, Andrew Morton wrote:
(Or we do

	return assert_zero_or_errno(ret);

which is a bit ug, but gets us there)

I'm personally a big fan of:

  typedef int kerr_t;
  # define kreterr_t kerr_t __must_check

Then:

  kreterr_t some_device_function(void *data)
  {
  	kerr_t result;
  	if (!data)
  		return -EINVAL;
  	result = other_device_function(data + sizeof(struct foo));
  	[...]
  	return result;
  }

You could even tag __bitwise on kerr_t except that wouldn't work nicely with returning a negative error code. Is there any way to tell sparse that:

  -ESOMECODE => -((__force kerr_t)3)

is ok when kerr_t is a bitwise type, without allowing any other math operations?

Alternatively you could:

  #ifdef __KERNEL__
  # define KENOENT ((__force kerr_t) -ENOENT)
  # define KENOMEM ((__force kerr_t) -ENOMEM)
  [...]
  #endif

But that's a _lot_ of code churn for fairly minimal gain. It might be easier just to patch sparse to add an errcode type attribute with the desired behavior. There also might be some way to do it with enums but I'm not familiar enough with the exact GCC behavior to comment.

Cheers,
Kyle Moffett
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux