[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [XEN PATCH] xen/types: address Rule 10.1 for macro BITS_TO_LONGS
On 08.09.2023 17:09, Nicola Vetrini wrote: > On 08/09/2023 16:53, Nicola Vetrini wrote: >> On 08/09/2023 13:59, Jan Beulich wrote: >>> On 08.09.2023 13:57, Jan Beulich wrote: >>>> On 08.09.2023 10:48, Nicola Vetrini wrote: >>>>> There is a build error due to -Werror because of a pointer >>>>> comparison at >>>>> line 469 of common/numa.c: >>>>> i = min(PADDR_BITS, BITS_PER_LONG - 1); >>>>> where >>>>> #define PADDR_BITS 52 >>>>> >>>>> I guess PADDR_BITS can become unsigned or gain a cast >>>> >>>> While generally converting constants to unsigned comes with a certain >>>> risk, I think for this (and its siblings) this ought to be okay. As >>>> to >>>> the alternative of a cast - before considering that, please consider >>>> e.g. adding 0u (as we do elsewhere in the code base to deal with such >>>> cases). >>> >>> And just after sending I realized that this would still be disliked by >>> Misra's type system. (Much like then aiui the 1 above will need to >>> become 1u. Which is all pretty horrible.) >> >> I have a proposal: in our tests we enabled an ECLAIR configuration >> that allows to bypass the >> constraint imposed by Rule 10.4 that warrants the 1U iff the value is >> constant and both types >> can represent it correctly (in this case BITS_PER_LONG -1). This would >> allow using the proposed >> solution and documenting why it's ok not to respect R10.4. What do you >> think? I'd definitely prefer us using such a model, yes. > And perhaps also use min_t instead of min, so that the typecheck can be > avoided. Already the wording you use suggests a problem: min() is using a type check for a reason (and that check is actually guaranteeing that some other of the Misra rules isn't violated, aiui), so we would better not try to "avoid" its use. There are certainly rare cases where using min() / max() would be unwieldy, hence why we have min_t() / max_t(), but imo wherever reasonably possible we ought to use the type-checking variants. Jan
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |