Skip to contentSkip to conversation

slimbus: avoid null pointer dereference on msg

PATCH New Colin King 1 participant 1 message Dec 22, 2017

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 slimbus: avoid null pointer dereference on msg

From: Colin Ian King <[email protected]>

The pointer msg is checked to see if it is null at the start of the function and jumps to the error exit label reterr that then dereferences msg when it prints a dev_err error message. Avoid this potential null pointer dereference by only printing the error message if msg is not null.

Detected by CoverityScan, CID#1463141 ("Dereference after null check")

Fixes afbdcc7c384b ("slimbus: Add messaging APIs to slimbus framework")
---
 drivers/slimbus/messaging.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/slimbus/messaging.c +3 -2
index 755462a4c75e..8b2c77f516b9 100644
@@ -170,8 +170,9 @@ static int slim_val_inf_sanity(struct slim_controller *ctrl,
 		break;
 	}
 reterr:
-	dev_err(ctrl->dev, "Sanity check failed:msg:offset:0x%x, mc:%d\n",
-		msg->start_offset, mc);
+	if (msg)
+		dev_err(ctrl->dev, "Sanity check failed:msg:offset:0x%x, mc:%d\n",
+			msg->start_offset, mc);
 	return -EINVAL;
 }
 
Signature · 1 line
2.14.1