From patchwork Tue Jun 13 03:44:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 13277912 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34D51C7EE29 for ; Tue, 13 Jun 2023 03:45:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.547769.855346 (Exim 4.92) (envelope-from ) id 1q8uxv-0006gh-14; Tue, 13 Jun 2023 03:45:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 547769.855346; Tue, 13 Jun 2023 03:45:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q8uxu-0006gD-U8; Tue, 13 Jun 2023 03:45:06 +0000 Received: by outflank-mailman (input) for mailman id 547769; Tue, 13 Jun 2023 03:45:05 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q8uxt-0006g7-NF for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 03:45:05 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ad06c583-099c-11ee-8611-37d641c3527e; Tue, 13 Jun 2023 05:45:02 +0200 (CEST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 47E8C61EFA; Tue, 13 Jun 2023 03:45:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AE6EC433EF; Tue, 13 Jun 2023 03:44:59 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ad06c583-099c-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686627900; bh=89/nFy+5LFW+PpOrE1HDauPVrJ/+ML/QHh6I8lgBens=; h=From:To:Cc:Subject:Date:From; b=b8BaTnDPAOZrp4qc2gelsENvkGVRWrS5V+6vcpA85OegQ+03Zh3U7WJa3sc8ZH5Tz 2xFAGEApESMYWhBYcJBskMvS2bxQTXzKsMFmPFqKEPvKVa8fOE6BnU+FAPfolOPPGA V22BeOCvStagCxiVWgNhDph29+4erKMC8Rm1NXz32Umue+6PxUmy4HHQ8oE/R5oG6h n/G7v7fIm7Ho50qVcpyvMaZk+R0GPPhrAhnKBg89nP3szwZPXHX2yqS3K8k203limT ZCKC+L7mSK/RndX+N7SH8Ww57QaABRkBXK2XURgLQ7LKv7eRgc21De68whwRAOEzTR ZmdpqcqhaCnTw== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, jbeulich@suse.com, julien@xen.org, andrew.cooper3@citrix.com, roger.pau@citrix.com, bertrand.marquis@arm.com, roberto.bagnara@bugseng.com, Stefano Stabellini Subject: [PATCH v3] docs/misra: new rules addition Date: Mon, 12 Jun 2023 20:44:56 -0700 Message-Id: <20230613034456.701654-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 From: Stefano Stabellini For Dir 1.1, a document describing all implementation-defined behaviour (i.e. gcc-specific behavior) will be added to docs/misra, also including implementation-specific (gcc-specific) appropriate types for bit-field relevant to Rule 6.1. Rule 21.21 is lacking an example on gitlab but the rule is straightforward: we don't use stdlib at all in Xen. Signed-off-by: Stefano Stabellini --- Changes in v3: - add all signed integer types to the Notes of 6.1 - clarify 7.2 in the Notes - not added: marking "inapplicable" rules, to be a separate patch Changes in v2: - drop 5.6 - specify additional appropriate types for 6.1 --- docs/misra/rules.rst | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/docs/misra/rules.rst b/docs/misra/rules.rst index d5a6ee8cb6..f72a49c9c4 100644 --- a/docs/misra/rules.rst +++ b/docs/misra/rules.rst @@ -40,6 +40,12 @@ existing codebase are work-in-progress. - Summary - Notes + * - `Dir 1.1 `_ + - Required + - Any implementation-defined behaviour on which the output of the + program depends shall be documented and understood + - + * - `Dir 2.1 `_ - Required - All source files shall compile without any compilation errors @@ -57,6 +63,13 @@ existing codebase are work-in-progress. header file being included more than once - + * - `Dir 4.11 `_ + - Required + - The validity of values passed to library functions shall be checked + - We do not have libraries in Xen (libfdt and others are not + considered libraries from MISRA C point of view as they are + imported in source form) + * - `Dir 4.14 `_ - Required - The validity of values received from external sources shall be @@ -133,6 +146,13 @@ existing codebase are work-in-progress. headers (xen/include/public/) are allowed to retain longer identifiers for backward compatibility. + * - `Rule 6.1 `_ + - Required + - Bit-fields shall only be declared with an appropriate type + - In addition to the C99 types, we also consider appropriate types: + unsigned char, unsigned short, unsigned long, unsigned long long, + enum, and all explicitly signed integer types. + * - `Rule 6.2 `_ - Required - Single-bit named bit fields shall not be of a signed type @@ -143,6 +163,32 @@ existing codebase are work-in-progress. - Octal constants shall not be used - + * - `Rule 7.2 `_ + - Required + - A "u" or "U" suffix shall be applied to all integer constants + that are represented in an unsigned type + - The rule asks that any integer literal that is implicitly + unsigned is made explicitly unsigned by using one of the + indicated suffixes. As an example, on a machine where the int + type is 32-bit wide, 0x77777777 is signed whereas 0x80000000 is + (implicitly) unsigned. In order to comply with the rule, the + latter should be rewritten as either 0x80000000u or 0x80000000U. + Consistency considerations may suggest using the same suffix even + when not required by the rule. For instance, if one has: + + Original: f(0x77777777); f(0x80000000); + + one might prefer + + Solution 1: f(0x77777777U); f(0x80000000U); + + over + + Solution 2: f(0x77777777); f(0x80000000U); + + after having ascertained that "Solution 1" is compatible with the + intended semantics. + * - `Rule 7.3 `_ - Required - The lowercase character l shall not be used in a literal suffix @@ -314,6 +360,11 @@ existing codebase are work-in-progress. used following a subsequent call to the same function - + * - Rule 21.21 + - Required + - The Standard Library function system of shall not be used + - + * - `Rule 22.2 `_ - Mandatory - A block of memory shall only be freed if it was allocated by means of a