Skip to content

Commit 1bd9284

Browse files
authored
Misra 17.7: the value returned by a function having non-void return shall be used (commaai#237)
* Fixed Misra 17.7 violations except for can_push
1 parent 18c9e88 commit 1bd9284

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

board/drivers/can.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
7272
return ret;
7373
}
7474

75-
int can_push(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
76-
int ret = 0;
75+
bool can_push(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
76+
bool ret = false;
7777
uint32_t next_w_ptr;
7878

7979
enter_critical_section();
@@ -82,10 +82,10 @@ int can_push(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
8282
if (next_w_ptr != q->r_ptr) {
8383
q->elems[q->w_ptr] = *elem;
8484
q->w_ptr = next_w_ptr;
85-
ret = 1;
85+
ret = true;
8686
}
8787
exit_critical_section();
88-
if (ret == 0) {
88+
if (!ret) {
8989
can_overflow_cnt++;
9090
#ifdef DEBUG
9191
puts("can_push failed!\n");

board/drivers/spi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ uint8_t spi_tx_buf[0x44];
8585
// SPI RX
8686
void DMA2_Stream2_IRQHandler(void) {
8787
int *resp_len = (int*)spi_tx_buf;
88-
memset(spi_tx_buf, 0xaa, 0x44);
88+
(void)memset(spi_tx_buf, 0xaa, 0x44);
8989
*resp_len = spi_cb_rx(spi_buf, 0x14, spi_tx_buf+4);
9090
#ifdef DEBUG_SPI
9191
puts("SPI write: ");

board/drivers/usb.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ void usb_irqhandler(void) {
807807
if (((rxst & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_DATA_UPDT) {
808808
int endpoint = (rxst & USB_OTG_GRXSTSP_EPNUM);
809809
int len = (rxst & USB_OTG_GRXSTSP_BCNT) >> 4;
810-
USB_ReadPacket(&usbdata, len);
810+
(void)USB_ReadPacket(&usbdata, len);
811811
#ifdef DEBUG_USB
812812
puts(" data ");
813813
puth(len);
@@ -823,7 +823,7 @@ void usb_irqhandler(void) {
823823
usb_cb_ep3_out(usbdata, len, 1);
824824
}
825825
} else if (((rxst & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_SETUP_UPDT) {
826-
USB_ReadPacket(&setup, 8);
826+
(void)USB_ReadPacket(&setup, 8);
827827
#ifdef DEBUG_USB
828828
puts(" setup ");
829829
hexdump(&setup, 8);

board/main.c

+27-23
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
void debug_ring_callback(uart_ring *ring) {
3434
char rcv;
3535
while (getc(ring, &rcv)) {
36-
putc(ring, rcv);
36+
(void)putc(ring, rcv); // misra-c2012-17.7: cast to void is ok: debug function
3737

3838
// jump to DFU flash
3939
if (rcv == 'z') {
@@ -212,7 +212,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
212212
case 0xd0:
213213
// addresses are OTP
214214
if (setup->b.wValue.w == 1) {
215-
memcpy(resp, (void *)0x1fff79c0, 0x10);
215+
(void)memcpy(resp, (void *)0x1fff79c0, 0x10);
216216
resp_len = 0x10;
217217
} else {
218218
get_provision_chunk(resp);
@@ -248,7 +248,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
248248
// **** 0xd6: get version
249249
case 0xd6:
250250
COMPILE_TIME_ASSERT(sizeof(gitversion) <= MAX_RESP_LEN);
251-
memcpy(resp, gitversion, sizeof(gitversion));
251+
(void)memcpy(resp, gitversion, sizeof(gitversion));
252252
resp_len = sizeof(gitversion)-1;
253253
break;
254254
// **** 0xd8: reset ST
@@ -296,27 +296,31 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
296296
// and it's blocked over WiFi
297297
// Allow ELM security mode to be set over wifi.
298298
if (hardwired || (setup->b.wValue.w == SAFETY_NOOUTPUT) || (setup->b.wValue.w == SAFETY_ELM327)) {
299-
safety_set_mode(setup->b.wValue.w, (int16_t)setup->b.wIndex.w);
300-
if (safety_ignition_hook() != -1) {
301-
// if the ignition hook depends on something other than the started GPIO
302-
// we have to disable power savings (fix for GM and Tesla)
303-
set_power_save_state(POWER_SAVE_STATUS_DISABLED);
304-
}
305-
#ifndef EON
306-
// always LIVE on EON
307-
switch (setup->b.wValue.w) {
308-
case SAFETY_NOOUTPUT:
309-
can_silent = ALL_CAN_SILENT;
310-
break;
311-
case SAFETY_ELM327:
312-
can_silent = ALL_CAN_BUT_MAIN_SILENT;
313-
break;
314-
default:
315-
can_silent = ALL_CAN_LIVE;
316-
break;
299+
int err = safety_set_mode(setup->b.wValue.w, (int16_t)setup->b.wIndex.w);
300+
if (err == -1) {
301+
puts("Error: safety set mode failed\n");
302+
} else {
303+
#ifndef EON
304+
// always LIVE on EON
305+
switch (setup->b.wValue.w) {
306+
case SAFETY_NOOUTPUT:
307+
can_silent = ALL_CAN_SILENT;
308+
break;
309+
case SAFETY_ELM327:
310+
can_silent = ALL_CAN_BUT_MAIN_SILENT;
311+
break;
312+
default:
313+
can_silent = ALL_CAN_LIVE;
314+
break;
315+
}
316+
#endif
317+
if (safety_ignition_hook() != -1) {
318+
// if the ignition hook depends on something other than the started GPIO
319+
// we have to disable power savings (fix for GM and Tesla)
320+
set_power_save_state(POWER_SAVE_STATUS_DISABLED);
317321
}
318-
#endif
319-
can_init_all();
322+
can_init_all();
323+
}
320324
}
321325
break;
322326
// **** 0xdd: enable can forwarding

board/provision.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// SHA1 checksum = 0x1C - 0x20
66

77
void get_provision_chunk(uint8_t *resp) {
8-
memcpy(resp, (void *)0x1fff79e0, PROVISION_CHUNK_LEN);
8+
(void)memcpy(resp, (void *)0x1fff79e0, PROVISION_CHUNK_LEN);
99
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) {
10-
memcpy(resp, "unprovisioned\x00\x00\x00testing123\x00\x00\xa3\xa6\x99\xec", 0x20);
10+
(void)memcpy(resp, "unprovisioned\x00\x00\x00testing123\x00\x00\xa3\xa6\x99\xec", 0x20);
1111
}
1212
}
1313

0 commit comments

Comments
 (0)