Skip to content

Commit

Permalink
<Lint> Updated cppcheck flags and fixed code smells
Browse files Browse the repository at this point in the history
Issue: #209
  • Loading branch information
akashkollipara committed Jan 15, 2023
1 parent 8a562cc commit f145f98
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 29 deletions.
8 changes: 3 additions & 5 deletions mk/lint.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@

LT := $(shell which cppcheck)

LINT_FLAGS += --error-exitcode=1 --std=c11 \
--enable=warning,style,performance \
--enable=portability,information \
--enable=missingInclude -q \
LINT_FLAGS += --error-exitcode=25 --std=c11 \
--max-ctu-depth=12 --max-configs=12 \
--check-config
--enable=all -q -v \
--suppress=unusedFunction

--lint: $(DEP_SRCS)
ifeq ($(LT),)
Expand Down
3 changes: 1 addition & 2 deletions projects/demo_avr_cpp/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ void delay(unsigned long d)
asm volatile("nop");
}

static unsigned char i = 0;
EXPORT_C(void play())
{
static unsigned int i = 0;

wdog_guard(WDT_64MS, true, NULL);

/* call the toggle member of led object */
Expand Down
4 changes: 2 additions & 2 deletions src/arch/avr/8/common_5x_6/terravisor/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void arch_di_save_state(istate_t *sreg_i_backup)
arch_di();
}

void arch_ei_restore_state(istate_t *sreg_i_backup)
void arch_ei_restore_state(const istate_t *sreg_i_backup)
{
MMIO8(SREG+0x20) |= *sreg_i_backup;
}
Expand Down Expand Up @@ -113,7 +113,7 @@ static cpu_sleep_t sleep_flag;
*/
bool arch_suspended_state_was(cpu_sleep_t state)
{
assert(state != resume);
assert((unsigned)state != resume);
if(!sleep_flag)
return false;
return (sleep_flag == state);
Expand Down
2 changes: 1 addition & 1 deletion src/arch/avr/8/common_5x_6/terravisor/include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void arch_setup();
*/
void arch_wfi();
void arch_di_save_state(istate_t *);
void arch_ei_restore_state(istate_t *);
void arch_ei_restore_state(const istate_t *);

/**
* arch_panic_handler - Executes when arch error occurs
Expand Down
16 changes: 8 additions & 8 deletions src/driver/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
*/
extern device_t _driver_table_start, _driver_table_end;

static status_t driver_register_with_order(device_t *start, device_t *end, unsigned int order)
static status_t driver_register_with_order(const device_t *start, const device_t *end, unsigned int order)
{
status_t ret = success;
device_t *ptr = start;
device_t *ptr = (device_t *)start;
/*
* Iterate the whole driver table so that on order
* match execute driver_setup
Expand All @@ -41,10 +41,10 @@ static status_t driver_register_with_order(device_t *start, device_t *end, unsig
return ret;
}

static status_t driver_deregister_with_order(device_t *start, device_t *end, unsigned int order)
static status_t driver_deregister_with_order(const device_t *start, const device_t *end, unsigned int order)
{
status_t ret = success;
device_t *ptr = start;
device_t *ptr = (device_t *)start;
/*
* Iterate the whole driver table so that on order
* match execute driver_exit
Expand All @@ -58,9 +58,9 @@ static status_t driver_deregister_with_order(device_t *start, device_t *end, uns
return ret;
}

static status_t driver_setup_with_name(device_t *start, device_t *end, const char *name)
static status_t driver_setup_with_name(const device_t *start, const device_t *end, const char *name)
{
device_t *ptr = start;
device_t *ptr = (device_t *)start;
/*
* Iterate over the driver table and compare the names.
* On successful compare, run driver_setup.
Expand All @@ -74,9 +74,9 @@ static status_t driver_setup_with_name(device_t *start, device_t *end, const cha
return error_func_inval;
}

static status_t driver_exit_with_name(device_t *start, device_t *end, const char *name)
static status_t driver_exit_with_name(const device_t *start, const device_t *end, const char *name)
{
device_t *ptr = start;
device_t *ptr = (device_t *)start;
/*
* Iterate over the driver table and compare the names.
* On successful compare, run driver_setup.
Expand Down
8 changes: 5 additions & 3 deletions src/lib/libc/malloc_lite.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void heap_unlock(void)

static void split(chunk_t *fit_slot, size_t size)
{
chunk_t *new = (void *)((void *) fit_slot + size + sizeof(chunk_t));
chunk_t *new = (chunk_t *)((size_t) fit_slot + size + sizeof(chunk_t));
new->size = fit_slot->size - size - sizeof(chunk_t);
new->free = 1;
new->next = fit_slot->next;
Expand Down Expand Up @@ -83,9 +83,11 @@ static chunk_t *get_header(void *p)
status_t platform_init_heap()
{
heap_lock();
memset(&_heap_start, 0, (size_t)(&_heap_end - &_heap_start));
size_t sz = (size_t)&_heap_end;
sz -= (size_t)&_heap_start;
memset(&_heap_start, 0, sz);
freeList = (void *)&_heap_start;
freeList->size = (size_t)(&_heap_end - &_heap_start) - sizeof(chunk_t);
freeList->size = sz - sizeof(chunk_t);
freeList->free = 1;
freeList->next = NULL;
heap_unlock();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/libnmath/dsp/conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
* @size_c - size of output matrict c
* #return - Returns function execution status
*/
status_t conv(float *a, int size_a, float *b, int size_b, float *c, int size_c)
status_t conv(const float *a, int size_a, const float *b,
int size_b, float *c, int size_c)
{
/* As per linear convolution if the size of output 1D matrix
* is not greater than or equal to 1 less than sum of sizes of
Expand Down
3 changes: 2 additions & 1 deletion src/lib/libnmath/include/dsp/conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

#pragma once

status_t conv(float *a, int size_a, float *b, int size_b, float *c, int size_c);
status_t conv(const float *a, int size_a, const float *b,
int size_b, float *c, int size_c);
2 changes: 1 addition & 1 deletion src/platform/mega_avr/common/platform/platform_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static status_t plat_timer_setup()
tport->tmr_irq = (size_t) tm->interrupt[0].id;
tport->tmr_handler = plat_tmr_isr;

ret = timer_setup(tport, 2, PS);
ret |= timer_setup(tport, 2, PS);
if(ret)
goto cleanup_exit2;
plat_timer_set_period(1);
Expand Down
6 changes: 3 additions & 3 deletions src/platform/sifive/common_fe310/hal/prci/pll.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static inline void pll_config_for_nearest_freq(unsigned int base, unsigned int c
status_t _NOINLINE prci_pll_get_clk(sysclk_port_t *port, unsigned int *clk)
{
pllc_t *config = &pllc[arch_core_index()];
unsigned int pllref, refr, vco, pllout, plldivd;
unsigned int pllref, refr, vco, pllout;
pllref = port->base_clk;
sysdbg5("PLL: pllref = %u\n", pllref);

Expand All @@ -108,7 +108,7 @@ status_t _NOINLINE prci_pll_get_clk(sysclk_port_t *port, unsigned int *clk)
if(config->diven)
{
sysdbg5("PLL: Output divider is enabled with div = %u\n", config->n);
plldivd = pllout / (2 * (config->n + 1));
unsigned int plldivd = pllout / (2 * (config->n + 1));
sysdbg5("PLL: plldivd = %u\n", plldivd);
*clk = plldivd;
}
Expand All @@ -120,7 +120,7 @@ static inline void prci_pll_wait_to_lock(sysclk_port_t *port)
uint64_t t = clint_read_time();
while((uint32_t)(clint_read_time() - t) < 10)
asm volatile("");
while(MMIO32(port->baddr + PLLCFG_OFFSET) & (1 << PLLLOCK))
while(MMIO32(port->baddr + PLLCFG_OFFSET) & (1U << PLLLOCK))
arch_dsb();
}

Expand Down
4 changes: 2 additions & 2 deletions src/visor/terravisor/workers/mcall/machine_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ extern mcall_t _ecall_table_start;
extern mcall_t _ecall_table_end;

typedef void (*mcb_t)(call_arg_t, call_arg_t, call_arg_t, mret_t *);
static mcb_t get_callback_from_table(mcall_t *start, mcall_t *end, mcall_id_t id)
static mcb_t get_callback_from_table(const mcall_t *start, const mcall_t *end, mcall_id_t id)
{
mcall_t *ptr = start;
mcall_t *ptr = (mcall_t *)start;
while(ptr < end)
{
if(ptr->id == id)
Expand Down

0 comments on commit f145f98

Please sign in to comment.