From 1bd92843726b6c3e6ad4766ee779b3d7d5a17900 Mon Sep 17 00:00:00 2001 From: rbiasini Date: Wed, 3 Jul 2019 16:01:01 -0700 Subject: [PATCH] Misra 17.7: the value returned by a function having non-void return shall be used (#237) * Fixed Misra 17.7 violations except for can_push --- board/drivers/can.h | 8 ++++---- board/drivers/spi.h | 2 +- board/drivers/usb.h | 4 ++-- board/main.c | 50 ++++++++++++++++++++++++--------------------- board/provision.h | 4 ++-- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/board/drivers/can.h b/board/drivers/can.h index bc5cdc5866de52..d1b9de1be4b5e1 100644 --- a/board/drivers/can.h +++ b/board/drivers/can.h @@ -72,8 +72,8 @@ bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) { return ret; } -int can_push(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) { - int ret = 0; +bool can_push(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) { + bool ret = false; uint32_t next_w_ptr; enter_critical_section(); @@ -82,10 +82,10 @@ int can_push(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) { if (next_w_ptr != q->r_ptr) { q->elems[q->w_ptr] = *elem; q->w_ptr = next_w_ptr; - ret = 1; + ret = true; } exit_critical_section(); - if (ret == 0) { + if (!ret) { can_overflow_cnt++; #ifdef DEBUG puts("can_push failed!\n"); diff --git a/board/drivers/spi.h b/board/drivers/spi.h index 039b5cf1aed6f9..44d618257ce902 100644 --- a/board/drivers/spi.h +++ b/board/drivers/spi.h @@ -85,7 +85,7 @@ uint8_t spi_tx_buf[0x44]; // SPI RX void DMA2_Stream2_IRQHandler(void) { int *resp_len = (int*)spi_tx_buf; - memset(spi_tx_buf, 0xaa, 0x44); + (void)memset(spi_tx_buf, 0xaa, 0x44); *resp_len = spi_cb_rx(spi_buf, 0x14, spi_tx_buf+4); #ifdef DEBUG_SPI puts("SPI write: "); diff --git a/board/drivers/usb.h b/board/drivers/usb.h index 3e22fb7382f4c8..aadd52811a10dc 100644 --- a/board/drivers/usb.h +++ b/board/drivers/usb.h @@ -807,7 +807,7 @@ void usb_irqhandler(void) { if (((rxst & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_DATA_UPDT) { int endpoint = (rxst & USB_OTG_GRXSTSP_EPNUM); int len = (rxst & USB_OTG_GRXSTSP_BCNT) >> 4; - USB_ReadPacket(&usbdata, len); + (void)USB_ReadPacket(&usbdata, len); #ifdef DEBUG_USB puts(" data "); puth(len); @@ -823,7 +823,7 @@ void usb_irqhandler(void) { usb_cb_ep3_out(usbdata, len, 1); } } else if (((rxst & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_SETUP_UPDT) { - USB_ReadPacket(&setup, 8); + (void)USB_ReadPacket(&setup, 8); #ifdef DEBUG_USB puts(" setup "); hexdump(&setup, 8); diff --git a/board/main.c b/board/main.c index da099155818e7c..3e3820e440a874 100644 --- a/board/main.c +++ b/board/main.c @@ -33,7 +33,7 @@ void debug_ring_callback(uart_ring *ring) { char rcv; while (getc(ring, &rcv)) { - putc(ring, rcv); + (void)putc(ring, rcv); // misra-c2012-17.7: cast to void is ok: debug function // jump to DFU flash if (rcv == 'z') { @@ -212,7 +212,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) case 0xd0: // addresses are OTP if (setup->b.wValue.w == 1) { - memcpy(resp, (void *)0x1fff79c0, 0x10); + (void)memcpy(resp, (void *)0x1fff79c0, 0x10); resp_len = 0x10; } else { get_provision_chunk(resp); @@ -248,7 +248,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) // **** 0xd6: get version case 0xd6: COMPILE_TIME_ASSERT(sizeof(gitversion) <= MAX_RESP_LEN); - memcpy(resp, gitversion, sizeof(gitversion)); + (void)memcpy(resp, gitversion, sizeof(gitversion)); resp_len = sizeof(gitversion)-1; break; // **** 0xd8: reset ST @@ -296,27 +296,31 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) // and it's blocked over WiFi // Allow ELM security mode to be set over wifi. if (hardwired || (setup->b.wValue.w == SAFETY_NOOUTPUT) || (setup->b.wValue.w == SAFETY_ELM327)) { - safety_set_mode(setup->b.wValue.w, (int16_t)setup->b.wIndex.w); - if (safety_ignition_hook() != -1) { - // if the ignition hook depends on something other than the started GPIO - // we have to disable power savings (fix for GM and Tesla) - set_power_save_state(POWER_SAVE_STATUS_DISABLED); - } - #ifndef EON - // always LIVE on EON - switch (setup->b.wValue.w) { - case SAFETY_NOOUTPUT: - can_silent = ALL_CAN_SILENT; - break; - case SAFETY_ELM327: - can_silent = ALL_CAN_BUT_MAIN_SILENT; - break; - default: - can_silent = ALL_CAN_LIVE; - break; + int err = safety_set_mode(setup->b.wValue.w, (int16_t)setup->b.wIndex.w); + if (err == -1) { + puts("Error: safety set mode failed\n"); + } else { + #ifndef EON + // always LIVE on EON + switch (setup->b.wValue.w) { + case SAFETY_NOOUTPUT: + can_silent = ALL_CAN_SILENT; + break; + case SAFETY_ELM327: + can_silent = ALL_CAN_BUT_MAIN_SILENT; + break; + default: + can_silent = ALL_CAN_LIVE; + break; + } + #endif + if (safety_ignition_hook() != -1) { + // if the ignition hook depends on something other than the started GPIO + // we have to disable power savings (fix for GM and Tesla) + set_power_save_state(POWER_SAVE_STATUS_DISABLED); } - #endif - can_init_all(); + can_init_all(); + } } break; // **** 0xdd: enable can forwarding diff --git a/board/provision.h b/board/provision.h index 2fad513508132d..5b0a520d7f3890 100644 --- a/board/provision.h +++ b/board/provision.h @@ -5,9 +5,9 @@ // SHA1 checksum = 0x1C - 0x20 void get_provision_chunk(uint8_t *resp) { - memcpy(resp, (void *)0x1fff79e0, PROVISION_CHUNK_LEN); + (void)memcpy(resp, (void *)0x1fff79e0, PROVISION_CHUNK_LEN); if (memcmp(resp, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 0x20) == 0) { - memcpy(resp, "unprovisioned\x00\x00\x00testing123\x00\x00\xa3\xa6\x99\xec", 0x20); + (void)memcpy(resp, "unprovisioned\x00\x00\x00testing123\x00\x00\xa3\xa6\x99\xec", 0x20); } }