[PATCH v8 10/22] counter: Standardize to ERANGE for limit exceeded errors

William Breathitt Gray vilhelm.gray at gmail.com
Mon Feb 15 20:26:52 EST 2021


On Sun, Feb 14, 2021 at 05:10:21PM +0000, Jonathan Cameron wrote:
> On Fri, 12 Feb 2021 21:13:34 +0900
> William Breathitt Gray <vilhelm.gray at gmail.com> wrote:
> 
> > ERANGE is a semantically better error code to return when an argument
> > value falls outside the supported limit range of a device.
> 
> #define	ERANGE		34	/* Math result not representable */
> 
> Not generally applicable to a parameter being out of range
> despite the name.
> #define	EINVAL		22	/* Invalid argument */
> Is probably closer to what we want to describe here.
> 
> Jonathan

The comment for ERANGE in error-base.h may be terse to a fault. I
believe there's a connotation here provided by ERANGE that is absent
from EINVAL: primarily that the device buffer is incapable of supporting
the desired value (i.e. there is a hardware limitation).

This is why strtoul() returns ERANGE if the correct value is outside the
range of representable values: the result of the operation is valid in
theory (it would be an unsigned integer), but it cannot be returned to
the user due to a limitation of the hardware to support that value (e.g.
32-bit registers) [1].

The changes in this patch follow the same logic: these are arguments
that are valid in theory (e.g. they are unsigned integers), but the
underlying devices are incapable of processing such a value (e.g. the
104-QUAD-8 can only handle 24-bit values).

[1] https://stackoverflow.com/a/34981398/1806289

William Breathitt Gray
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20210216/6cca8184/attachment.sig>


More information about the linux-arm-kernel mailing list