Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable misra-c2012-2.3 & misra-c2012-2.4 #1801

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion board/can_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const uint8_t PANDA_BUS_CNT = 4U;
#define CANPACKET_DATA_SIZE_MAX 8U
#endif

typedef struct {
// cppcheck-suppress [misra-c2012-2.3, misra-c2012-2.4]
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, why do we have to do this here but not for health.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah it was a bit tricky to understand for me in the beginning too.

if you try to run my code, cppcheck is flagging misra-c2012 2.3 at the board/pedal/main.c file only not the other two test of board/main.c. I'm not entirely sure of the implementation of cppcheck, but I read through the code base and see that they would read through all of the include header files. For instance to check for misra_2.3 it would look through all of the typedef struct definition of the main file as well as the included files. In the board/pedal/main.c, if you follow the trail then it would include some header files that include the can_definitions.h file, while the pedal/main.c file doesn't use any header file that has health.h file in it.

I also did one experiment and put #include health.h in the board/pedal/main.c file and get this.

/home/openpilot/panda/board/health.h:35:1: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.3]
typedef struct __attribute__((packed)) {
^
/home/openpilot/panda/board/health.h:4:41: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.4]
struct __attribute__((packed)) health_t {

So I think it is a false positive of cppcheck.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's not necessary, I just reverted it. please be more careful with changes like this in the future

typedef struct {
unsigned char reserved : 1;
unsigned char bus : 3;
unsigned char data_len_code : 4; // lookup length with dlc_to_len
Expand Down
12 changes: 6 additions & 6 deletions board/stm32fx/llusb.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
typedef struct
{
__IO uint32_t HPRT;
}
USB_OTG_HostPortTypeDef;
//typedef struct
//{
// __IO uint32_t HPRT;
//}
//USB_OTG_HostPortTypeDef;

bongbui321 marked this conversation as resolved.
Show resolved Hide resolved
USB_OTG_GlobalTypeDef *USBx = USB_OTG_FS;

#define USBx_HOST ((USB_OTG_HostTypeDef *)((uint32_t)USBx + USB_OTG_HOST_BASE))
#define USBx_HOST_PORT ((USB_OTG_HostPortTypeDef *)((uint32_t)USBx + USB_OTG_HOST_PORT_BASE))
//#define USBx_HOST_PORT ((USB_OTG_HostPortTypeDef *)((uint32_t)USBx + USB_OTG_HOST_PORT_BASE))
#define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)((uint32_t)USBx + USB_OTG_DEVICE_BASE))
#define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)((uint32_t)USBx + USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
#define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)((uint32_t)USBx + USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
Expand Down
12 changes: 6 additions & 6 deletions board/stm32h7/llusb.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
typedef struct
{
__IO uint32_t HPRT;
}
USB_OTG_HostPortTypeDef;
//typedef struct
//{
// __IO uint32_t HPRT;
//}
//USB_OTG_HostPortTypeDef;

USB_OTG_GlobalTypeDef *USBx = USB_OTG_HS;

#define USBx_HOST ((USB_OTG_HostTypeDef *)((uint32_t)USBx + USB_OTG_HOST_BASE))
#define USBx_HOST_PORT ((USB_OTG_HostPortTypeDef *)((uint32_t)USBx + USB_OTG_HOST_PORT_BASE))
//#define USBx_HOST_PORT ((USB_OTG_HostPortTypeDef *)((uint32_t)USBx + USB_OTG_HOST_PORT_BASE))
#define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)((uint32_t)USBx + USB_OTG_DEVICE_BASE))
#define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)((uint32_t)USBx + USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
#define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)((uint32_t)USBx + USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
Expand Down
2 changes: 0 additions & 2 deletions tests/misra/suppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ knownConditionTrueFalse

misra-config
misra-c2012-1.2 # this is from the extensions (e.g. __typeof__) used in the MIN, MAX, ABS, and CLAMP macros
misra-c2012-2.3
misra-c2012-2.4
misra-c2012-2.5
misra-c2012-2.7
misra-c2012-8.7
Expand Down
Loading