Skip to content

Commit baf6a75

Browse files
00xcavpatel
authored andcommitted
lib: sbi: dbtr: fix potential NULL pointer dereferences
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]>
1 parent 778949e commit baf6a75

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/sbi/sbi_dbtr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ static void dbtr_trigger_enable(struct sbi_dbtr_trigger *trig)
357357
unsigned long state;
358358
unsigned long tdata1;
359359

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

363363
state = trig->state;
@@ -403,7 +403,7 @@ static void dbtr_trigger_disable(struct sbi_dbtr_trigger *trig)
403403
{
404404
unsigned long tdata1;
405405

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

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

430430
static void dbtr_trigger_clear(struct sbi_dbtr_trigger *trig)
431431
{
432-
if (!trig && !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED)))
432+
if (!trig || !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED)))
433433
return;
434434

435435
csr_write(CSR_TSELECT, trig->index);

0 commit comments

Comments
 (0)