Skip to content

Commit

Permalink
(almost) enable cppcheck unusedFunction (#1875)
Browse files Browse the repository at this point in the history
* remove some unused

* more

* kinda works

* rest are false positives

* disable for now

* add back exhaustive
  • Loading branch information
adeebshihadeh authored Feb 17, 2024
1 parent 997b075 commit 6eed036
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 132 deletions.
4 changes: 0 additions & 4 deletions board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ bool dos_check_ignition(void){
return harness_check_ignition();
}

void dos_set_usb_switch(bool phone){
set_gpio_output(GPIOB, 3, phone);
}

void dos_set_ir_power(uint8_t percentage){
pwm_set(TIM4, 2, percentage);
}
Expand Down
4 changes: 0 additions & 4 deletions board/boards/unused_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ void unused_set_siren(bool enabled) {
UNUSED(enabled);
}

uint32_t unused_read_voltage(void) {
return 0U;
}

uint32_t unused_read_current(void) {
return 0U;
}
Expand Down
1 change: 1 addition & 0 deletions board/bootstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "obj/gitversion.h"
#include "flasher.h"

// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
void __initialize_hardware_early(void) {
early_initialization();
}
Expand Down
26 changes: 0 additions & 26 deletions board/drivers/gmlan_alt.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,32 +147,6 @@ int inverted_bit_to_send = GMLAN_HIGH;
int gmlan_switch_below_timeout = -1;
int gmlan_switch_timeout_enable = 0;

void gmlan_switch_init(int timeout_enable) {
gmlan_switch_timeout_enable = timeout_enable;
gmlan_alt_mode = GPIO_SWITCH;
gmlan_switch_below_timeout = 1;
set_gpio_mode(GPIOB, 13, MODE_OUTPUT);

setup_timer();

inverted_bit_to_send = GMLAN_LOW; //We got initialized, set the output low
}

void set_gmlan_digital_output(int to_set) {
inverted_bit_to_send = to_set;
/*
print("Writing ");
puth(inverted_bit_to_send);
print("\n");
*/
}

void reset_gmlan_switch_timeout(void) {
can_timeout_counter = GMLAN_TICKS_PER_SECOND;
gmlan_switch_below_timeout = 1;
gmlan_alt_mode = GPIO_SWITCH;
}

void set_bitbanged_gmlan(int val) {
if (val != 0) {
register_set_bits(&(GPIOB->ODR), (1UL << 13));
Expand Down
2 changes: 1 addition & 1 deletion board/drivers/interrupts.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void interrupt_timer_handler(void) {

// Calculate interrupt load
// The bootstub does not have the FPU enabled, so can't do float operations.
#if !defined(PEDAL) && !defined(BOOTSTUB)
#if !defined(BOOTSTUB)
interrupt_load = ((busy_time + idle_time) > 0U) ? ((float) busy_time) / (busy_time + idle_time) : 0.0f;
#endif
idle_time = 0U;
Expand Down
15 changes: 0 additions & 15 deletions board/drivers/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,6 @@ bool put_char(uart_ring *q, char elem) {
return ret;
}

// Seems dangerous to use (might lock CPU if called with interrupts disabled f.e.)
// TODO: Remove? Not used anyways
void uart_flush(const uart_ring *q) {
while (q->w_ptr_tx != q->r_ptr_tx) {
__WFI();
}
}

void uart_flush_sync(uart_ring *q) {
// empty the TX buffer
while (q->w_ptr_tx != q->r_ptr_tx) {
uart_tx_ring(q);
}
}

void clear_uart_buff(uart_ring *q) {
ENTER_CRITICAL();
q->w_ptr_tx = 0;
Expand Down
27 changes: 0 additions & 27 deletions board/flasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ bool unlocked = false;

void spi_init(void);

#ifdef uart_ring
void debug_ring_callback(uart_ring *ring) {}
#endif

int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
int resp_len = 0;

Expand Down Expand Up @@ -120,29 +116,6 @@ void comms_endpoint2_write(const uint8_t *data, uint32_t len) {
}


int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
UNUSED(len);
ControlPacket_t control_req;

int resp_len = 0;
switch (data[0]) {
case 0:
// control transfer
control_req.request = ((USB_Setup_TypeDef *)(data+4))->b.bRequest;
control_req.param1 = ((USB_Setup_TypeDef *)(data+4))->b.wValue.w;
control_req.param2 = ((USB_Setup_TypeDef *)(data+4))->b.wIndex.w;
control_req.length = ((USB_Setup_TypeDef *)(data+4))->b.wLength.w;

resp_len = comms_control_handler(&control_req, data_out);
break;
case 2:
// ep 2, flash!
comms_endpoint2_write(data+4, data[2]);
break;
}
return resp_len;
}

void soft_flasher_start(void) {
print("\n\n\n************************ FLASHER START ************************\n");

Expand Down
6 changes: 0 additions & 6 deletions board/provision.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,3 @@ void get_provision_chunk(uint8_t *resp) {
(void)memcpy(resp, "unprovisioned\x00\x00\x00testing123\x00\x00\xa3\xa6\x99\xec", 0x20);
}
}

uint8_t chunk[PROVISION_CHUNK_LEN];
bool is_provisioned(void) {
(void)memcpy(chunk, (uint8_t *)PROVISION_CHUNK_ADDRESS, PROVISION_CHUNK_LEN);
return (memcmp(chunk, unprovisioned_text, 0x20) != 0);
}
29 changes: 0 additions & 29 deletions board/stm32fx/lluart.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,3 @@ void USART2_IRQ_Handler(void) { uart_interrupt_handler(&uart_ring_debug); }
void uart_set_baud(USART_TypeDef *u, unsigned int baud) {
u->BRR = USART_BRR_(APB1_FREQ*1000000U, baud);
}

void uart_init(uart_ring *q, int baud) {
if(q->uart != NULL){
// Register interrupts (max data rate: 115200 baud)
if (q->uart == USART2){
REGISTER_INTERRUPT(USART2_IRQn, USART2_IRQ_Handler, 150000U, FAULT_INTERRUPT_RATE_UART_2)
} else {
// UART not used. Skip registering interrupts
}

// Set baud and enable peripheral with TX and RX mode
uart_set_baud(q->uart, baud);
q->uart->CR1 = USART_CR1_UE | USART_CR1_TE | USART_CR1_RE;
if ((q->uart == USART2) || (q->uart == USART3) || (q->uart == UART5)) {
q->uart->CR1 |= USART_CR1_RXNEIE;
}

// Enable UART interrupts
if (q->uart == USART2){
NVIC_EnableIRQ(USART2_IRQn);
} else if (q->uart == USART3){
NVIC_EnableIRQ(USART3_IRQn);
} else if (q->uart == UART5){
NVIC_EnableIRQ(UART5_IRQn);
} else {
// UART not used. Skip enabling interrupts
}
}
}
10 changes: 0 additions & 10 deletions tests/libpanda/safety_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,3 @@ void init_tests(void){
valid_steer_req_count = 0;
invalid_steer_req_count = 0;
}

void set_gmlan_digital_output(int to_set){
}

void reset_gmlan_switch_timeout(void){
}

void gmlan_switch_init(int timeout_enable){
}

6 changes: 3 additions & 3 deletions tests/misra/suppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ misra-c2012-20.10
# needed since not all of these suppressions are applicable to all builds
unmatchedSuppression

# All interrupt handlers are defined, including ones we don't use
unusedFunction:*/interrupt_handlers*.h

# all of the below suppressions are from new checks introduced after updating
# cppcheck from 2.5 -> 2.13. they are listed here to separate the update from
# fixing the violations and all are intended to be removed soon after

unusedFunction

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.5
Expand Down
21 changes: 14 additions & 7 deletions tests/misra/test_misra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PANDA_DIR=$DIR/../../
PANDA_DIR=$(realpath $DIR/../../)

GREEN="\e[1;32m"
NC='\033[0m'
Expand Down Expand Up @@ -31,23 +31,30 @@ fi
cppcheck() {
# note that cppcheck build cache results in inconsistent results as of v2.13.0
OUTPUT=$DIR/.output.log
$CPPCHECK_DIR/cppcheck --enable=all --force --inline-suppr -I $PANDA_DIR/board/ \
$CPPCHECK_DIR/cppcheck --force --inline-suppr -I $PANDA_DIR/board/ \
-I $gcc_inc "$(arm-none-eabi-gcc -print-file-name=include)" \
--suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \
--suppress=*:*include/* --error-exitcode=2 --addon=misra \
--check-level=exhaustive "$@" |& tee $OUTPUT
--suppress=*:*include/* --error-exitcode=2 --check-level=exhaustive \
"$@" |& tee $OUTPUT

# cppcheck bug: some MISRA errors won't result in the error exit code,
# so check the output (https://trac.cppcheck.net/ticket/12440#no1)
if grep -e "misra violation" -e "error" $OUTPUT > /dev/null; then
if grep -e "misra violation" -e "error" -e "style: " $OUTPUT > /dev/null; then
exit 1
fi
}

PANDA_OPTS="--enable=all --disable=unusedFunction -DPANDA --addon=misra"

printf "\n${GREEN}** PANDA F4 CODE **${NC}\n"
cppcheck -DPANDA -DSTM32F4 -DUID_BASE $PANDA_DIR/board/main.c
cppcheck $PANDA_OPTS -DSTM32F4 -DUID_BASE $PANDA_DIR/board/main.c

printf "\n${GREEN}** PANDA H7 CODE **${NC}\n"
cppcheck -DPANDA -DSTM32H7 -DUID_BASE $PANDA_DIR/board/main.c
cppcheck $PANDA_OPTS -DSTM32H7 -DUID_BASE $PANDA_DIR/board/main.c

# unused needs to run globally
#printf "\n${GREEN}** UNUSED ALL CODE **${NC}\n"
#cppcheck --enable=unusedFunction --quiet $PANDA_DIR/board/

printf "\n${GREEN}Success!${NC} took $SECONDS seconds\n"

0 comments on commit 6eed036

Please sign in to comment.