[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [RFC PATCH 0/4] Add missing default labels to switch statements
Hi, On 25/02/2019 10:27, Oleksandr Andrushchenko wrote: From my understanding, the goal is to have Xen upstream close to be compliant with MISRA. Then the code can be consumed by company (such as yours) to fully certify Xen. The discussion here is to understand what are the pros/cons on having this rule fully implemented in Xen.On 2/23/19 1:13 AM, Julien Grall wrote:Hi, On 22/02/2019 22:34, Stefano Stabellini wrote:On Fri, 22 Feb 2019, Julien Grall wrote:Hi Stefano, On 22/02/2019 21:58, Stefano Stabellini wrote:On Fri, 22 Feb 2019, Andrew Cooper wrote:On 22/02/2019 21:00, Stefano Stabellini wrote:On Fri, 22 Feb 2019, Julien Grall wrote:That's not how it works in upstream. If you know some constructs are wrong, itBTW, I checked the series with -Wswitch-default: -Wswitch-default Warn whenever a switch statement does not have a default case.Furthermore, using BUG() is a pretty bad idea in switch.It is and not only in the switch. The reason I put BUG is that I tried to follow the existing "error handling" at those places.It is not because BUG() is been used today in some places that we need to continue to spread it.Use of BUG() itself is another topic which will also need to be addressedSo we should not add more of them...Again, I see this as a dedicated change. So, in the current series I think it is acceptable to use the existing way of error handling if any at all.is best to try to address partially the problem directly then having so you reduce the amounts of change afterwards. So please try to not introduce more BUG() in the code base.Hi Oleksandr, Julien, Julien's right that we should not introduce any more BUG()s. In fact, each of them makes the code less safe, not more safe! The purpose of MISRAC 16.4 is "defensive programming": write the code in a way that is more (not less!) resilient to failure. So, I think it is a good idea to introduce a default label because it can help us spot unexpected issues. Instead of calling BUG() in the default handler, which is detrimental, we should return an error when possible, or just print a warning.domain_crash() is almost always better than BUG(). It is very obvious if it gets hit, and wont crash Xen.That's a good suggestion.As 16.4 clearly state, even a simple comment would be enough to address the rule. We just need to explain why a default label is not needed. Such as: default: /* unreachable because blah and blah */What a simple comment doesn't do is avoid breaking -Wswitch.I don't know how to reconcile 16.4 with -Wswitch. One could argue that -Wswitch could be a good way to address 16.4, but then we introduce a compiler specific requirement. Typically gcc is not the compiler of choice for these environments, unfortunately forcing gcc is not an option.Well, you could build with GCC and then build with your custom compiler...This suggestion is problematic: as an individual interested in MISRA-C compliance, I only have the MISRA-C rules in my hands. I don't know how to deal with suggestions like this one, that don't comply to the Rules, but it tries to address the same issue in a different manner.Are you suggesting we will have to abide to all the rules even if they doesn't make things worst? I was under the impression we don't necessary need to follow a rule if we have justification for it.I cannot rule out that it wouldn't work, but also I cannot be sure that it would work. In short, I have no way to make progress or to find out how to move forward. I guess as a contributor I would be forced to go back to the MISRAC compliance experts and ask for their opinion. (One non-technical issue is who is going to pay them for spending their time on this.) But what if they say it is not acceptable for compliance?I appreciate people might want to use Xen with MISRA C. But I am not convinced we should bend to some rules in Xen Project for the sake of making MISRA happy. People could carry such patch themselves if they care about it.Good suggestion, but taking into account the number of possible changes this will finally become a fork of the existing Xen... And we all probably understand what it means to deviate from upstream... On the other hand what's wrong with the will to make the project benefit from more robust (as MISRA believes) and, yes, certified code? While I can see the benefits in some of the switch, I doubt this will help in others switch (see my answer on patch #1). I am still waiting to see a justification on why MISRA believes our code will be more robust with "default: break;" code... Cheers, -- Julien Grall _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |