Skip to content

Conversation

@alfred2g
Copy link
Contributor

Fix Remaining Misra violations

Description

Fix Remaining and new misra violations

Test Steps

Misra checker + unit tests

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@alfred2g alfred2g requested a review from a team as a code owner July 29, 2022 00:16
@alfred2g alfred2g marked this pull request as draft July 29, 2022 00:16
@alfred2g alfred2g force-pushed the misra_remaining branch 2 times, most recently from 8d2dcf3 to 2b59b8a Compare July 29, 2022 18:59
@alfred2g alfred2g marked this pull request as ready for review August 1, 2022 22:01
@alfred2g alfred2g changed the title Misra remaining Misra fix remaining violations Aug 1, 2022
@alfred2g alfred2g changed the title Misra fix remaining violations Misra fix or suppress remaining violations Aug 2, 2022
aws-afr-bot
aws-afr-bot previously approved these changes Aug 3, 2022
#define ipconfigNETWORK_MTU 1500
#else
/* A sanity check to avoid a possible overflow of size_t. */
#if ipconfigNETWORK_MTU > ( SIZE_MAX >> 1 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just trigger a #error.

@aws-afr-bot aws-afr-bot dismissed their stale review August 3, 2022 18:32

wrong user

Co-authored-by: Aniruddha Kanhere <[email protected]>
@alfred2g alfred2g requested a review from paulbartell August 3, 2022 18:57
#### Rule 8.13
_Ref 8.13.1_

- MISRA C-2012 Rule 8.13 Parameter passed is never used, should be declared as
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be re-worded to be more generic. Something like:

MISRA C-2012 Rule 8.13 encourages the use of const-qualified types whenever possible. However, the FreeRTOS API requires that all task entry functions conform to the same function signature (TaskFunction_t) which includes a single void * pointer argument. Due to this restriction, it is not possible to use a const qualifier for the entry point function to any FreeRTOS task.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was fixed with this commit: 81e90d8

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO: It's too specific to the particular instance. We're likely to run into this exact violation quite frequently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is ok to be specific might be even desirable, we do support multiple References for specific cases

alfred2g and others added 5 commits August 3, 2022 12:55
#### Rule 21.6
_Ref 21.6.1_

- MISRA C-2012 Rule 21.6 warns about the use of standard library input/output
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This justification should mention how we prevent misuse of printf-style functions. Mentioning "-Wformat-security" and/or specific Wformat options that are used when building unit tests would be helpful here.


#### Rule 11.3
_Ref 11.3.1_

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about for 64-bit targets that do not allow 32-bit aligned access?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently do not support any hardware with that feature/drawback the only 64 bit we currently support is RiscV and they do support unaligned access (if i am not mistaken)
when we support more 64bit hardware we will have to add code to cover that case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulbartell wrote:

What about for 64-bit targets that do not allow 32-bit aligned access?

A 64-bit target that do not allow 32-bit aligned access? I am not sure what you mean here.

@Alfred2 wrote:

We currently do not support any hardware with that feature/drawback the only 64 bit we currently support is RiscV

As for FreeRTOS+TCP, we also support the 64-bit UltraScale platform with a Cortex-A53.

I have never seen alignment problems with the casting of types.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Cortex-A53 is only strict about alignment when configured such in the SCTLR. It's pretty common to configure it to allow unaligned access.

In contrast, a Cortex-M0 (ARMv6-M) will always fail unaligned accesses.. but is 4-byte aligned.

SPARC and MIPS are both example of a 64bit architectures that do not support unaligned access... So de-referencing a 32-bit aligned pointer as a 64bit type could cause a fault at runtime.

In the case of FR+TCP, we're unlikely to run into this problem in particular.

@alfred2g alfred2g requested a review from paulbartell August 4, 2022 22:05
Copy link
Contributor

@htibosch htibosch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alfred2g It sounds like the MISRA checks are almost all ready!
I only have two comments, mostly about 64-bit platforms.
I approve it, thanks


#### Rule 11.3
_Ref 11.3.1_

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulbartell wrote:

What about for 64-bit targets that do not allow 32-bit aligned access?

A 64-bit target that do not allow 32-bit aligned access? I am not sure what you mean here.

@Alfred2 wrote:

We currently do not support any hardware with that feature/drawback the only 64 bit we currently support is RiscV

As for FreeRTOS+TCP, we also support the 64-bit UltraScale platform with a Cortex-A53.

I have never seen alignment problems with the casting of types.

/* MISRA Ref 11.3.1 [Misaligned access] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
*( ( NetworkBufferDescriptor_t ** ) ( pxReturn->pucEthernetBuffer ) ) = pxReturn;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*( ( NetworkBufferDescriptor_t ** ) ( pxReturn->pucEthernetBuffer ) ) = pxReturn;

In other places in the library, I have put asserts before assuming that a pointer can be written at a byte address. In this case, the character pointer was returned by pvPortMalloc(), and it is assumed that it is 4-byte aligned.

On my Xilinx UltraScale, the size of a pointer is 8 and pvPortMalloc() will make sure that only 64-bit aligned pointers are returned, see the portBYTE_ALIGNMENT macros for ARM_CA53_64_BIT:

#define portBYTE_ALIGNMENT         16
#define portBYTE_ALIGNMENT_MASK    0x000f 

In case of a 64-bit platform, the macro ipconfigBUFFER_PADDING will be checked with asserts: it must be at least 14, and it must be a multiple of 4 plus 2 bytes:

    /* This is a 64-bit platform, make sure there is enough space in
     * pucEthernetBuffer to store a pointer. */
    configASSERT( ( sizeof( uintptr_t ) != 8U ) || ( ipconfigBUFFER_PADDING >= 14 ) );

    /* But it must have this strange alignment: */
    configASSERT( ( sizeof( uintptr_t ) != 8U ) || ( ( ( ( ipconfigBUFFER_PADDING ) + 2 ) % 4 ) == 0 ) );

When ipconfigBUFFER_PADDING is defined, it will be assigned to ipBUFFER_PADDING.

@AniruddhaKanhere AniruddhaKanhere merged commit 4ac10c8 into FreeRTOS:main Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants