Skip to content

Commit

Permalink
lib: sbi: dbtr: fix potential NULL pointer dereferences
Browse files Browse the repository at this point in the history
In several dbtr functions, we first check that the dbtr trigger is not
NULL and that its state is what we expect. However, it only makes
sense to perform the second check if the dbtr trigger is not NULL.
Othwerwise we will dereference a NULL pointer. Thus, change the
condition so that it shortcuts to the first check if necessary.

Signed-off-by: Carlos López <[email protected]>
Reviewed-By: Anup Patel <[email protected]>
  • Loading branch information
00xc authored and avpatel committed Aug 2, 2024
1 parent 778949e commit baf6a75
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/sbi/sbi_dbtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ static void dbtr_trigger_enable(struct sbi_dbtr_trigger *trig)
unsigned long state;
unsigned long tdata1;

if (!trig && !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED)))
if (!trig || !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED)))
return;

state = trig->state;
Expand Down Expand Up @@ -403,7 +403,7 @@ static void dbtr_trigger_disable(struct sbi_dbtr_trigger *trig)
{
unsigned long tdata1;

if (!trig && !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED)))
if (!trig || !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED)))
return;

tdata1 = trig->tdata1;
Expand All @@ -429,7 +429,7 @@ static void dbtr_trigger_disable(struct sbi_dbtr_trigger *trig)

static void dbtr_trigger_clear(struct sbi_dbtr_trigger *trig)
{
if (!trig && !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED)))
if (!trig || !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED)))
return;

csr_write(CSR_TSELECT, trig->index);
Expand Down

0 comments on commit baf6a75

Please sign in to comment.