From: Jan Beulich <jbeulich@suse.com>
To: Nicola Vetrini <nicola.vetrini@bugseng.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
Stefano Stabellini <stefano.stabellini@amd.com>,
Michal Orzel <michal.orzel@amd.com>,
xenia.ragiadakou@amd.com, Ayan Kumar Halder <ayankuma@amd.com>,
consulting@bugseng.com, Andrew Cooper <andrew.cooper3@citrix.com>,
Julien Grall <julien@xen.org>,
George Dunlap <george.dunlap@citrix.com>, Wei Liu <wl@xen.org>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: Address MISRA C:2012 Rule 8.4
Date: Mon, 7 Aug 2023 09:34:12 +0200 [thread overview]
Message-ID: <ce365fcb-2a9c-dd41-6abb-e7ecee53d7ff@suse.com> (raw)
In-Reply-To: <a44369bc5e64277cab6dedb636986dd3@bugseng.com>
On 04.08.2023 16:00, Nicola Vetrini wrote:
>>
>> Upon further examination, I identified the following patterns:
>>
>> 1. Functions defined in .c called only from asm code (e.g., the
>> already mentioned __start_xen)
>> 2. Functions/variables declared in a .h, defined in a .c that does not
>> include the .h with the declaration
>> (e.g., 'fill_console_start_info' is defined in 'xen/drivers/vga.c',
>> declared in 'xen/include/xen/console.h' which is not visible when
>> compiling the .c).
>> 3. Variables that are either extern or not, such as 'acpi_gbl_FADT' in
>> 'xen/include/acpi/acglobal.h', depending on
>> DEFINE_ACPI_GLOBALS
>>
>> Below are the proposed resolution strategies:
>>
>> 1. I would advise to add the declaration in the relative .h, to
>> support automatic consistency checks with the
>> implementation and a quick reference when touching the asm.
>> 2. To comply with the rule, the header with the declaration should be
>> included. Also note that there are some
>> corner cases, such as 'get_sec', which is used in 'cper.h' without
>> including 'time.h' (which should gain a
>> declaration for it).
>> 3. One possible resolution pattern is including 'acglobal.h' twice
>> (either directly or indirectly trough acpi.h, if
>> the latter does not cause other issues) like so:
>>
>> (assuming DEFINE_ACPI_GLOBALS is undefined here)
>> #include "acglobal.h"
>> #define DEFINE_ACPI_GLOBALS
>> #include "acglobal.h"
>>
>> this way, the rule is followed properly, though it's not the
>> prettiest pattern and also clashes with the objectives
>> of D4.10 ("Precautions shall be taken in order to prevent the
>> contents of a header file being included
>> more than once"), but then a motivated exception is allowed there.
>
> One further question is whether functions under
> 'xen/common/coverage/gcov_base.c' should gain
> a declaration in 'gcov.h' or not, as they exist just for the purpose of
> being referenced
> by autogenerated profiling code. I see no reason why they shouldn't, but
> they can also be safely deviated,
> since they are not called by Xen code.
Imo it should be the compiler to provide a prototype for these (much
like it does for builtins), thus ensuring that an implementation
actually matches the compiler's expectations. Yet afaics it doesn't.
Jan
next prev parent reply other threads:[~2023-08-07 7:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 9:20 Address MISRA C:2012 Rule 8.4 Nicola Vetrini
2023-08-04 0:35 ` Stefano Stabellini
2023-08-04 9:47 ` Nicola Vetrini
2023-08-04 11:39 ` Jan Beulich
2023-08-04 14:09 ` Nicola Vetrini
2023-08-07 7:26 ` Jan Beulich
2023-08-04 20:40 ` Stefano Stabellini
2023-08-04 14:00 ` Nicola Vetrini
2023-08-07 7:34 ` Jan Beulich [this message]
2023-08-07 10:40 ` Nicola Vetrini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ce365fcb-2a9c-dd41-6abb-e7ecee53d7ff@suse.com \
--to=jbeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=ayankuma@amd.com \
--cc=consulting@bugseng.com \
--cc=george.dunlap@citrix.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=nicola.vetrini@bugseng.com \
--cc=sstabellini@kernel.org \
--cc=stefano.stabellini@amd.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
--cc=xenia.ragiadakou@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.