Skip to content

Commit f77f8e3

Browse files
committed
coverity: CID 521344: Dereference before null check
Check gpio_is_ready_dt() before using i3c_mng_owner to prevent null pointer dereference when configuring or setting the GPIO pin. Signed-off-by: Steven Lee <[email protected]> Change-Id: I35e1a159d1948aa4d32cbe1d2f2dd68775931abe
1 parent 44c35c9 commit f77f8e3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/hrot_hal/gpio/platform/gpio_bhs.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ void BhsSwitchI3cMng(int owner)
110110
GPIO_DT_SPEC_GET_OR(DT_INST(0, aspeed_pfr_gpio_bhs),
111111
i3c_mng_mux_sel_out_gpios,
112112
{0});
113-
gpio_pin_configure_dt(&i3c_mng_owner, GPIO_OUTPUT);
114-
if (i3c_mng_owner.port) {
115-
LOG_INF("Switch I3C MNG Owner to %s", owner == I3C_MNG_OWNER_BMC ? "BMC" : "ROT");
116-
gpio_pin_set(i3c_mng_owner.port, i3c_mng_owner.pin, owner);
113+
114+
if (gpio_is_ready_dt(&i3c_mng_owner) == false) {
115+
LOG_ERR("I3C MNG Owner GPIO is not ready");
116+
return;
117117
}
118+
119+
gpio_pin_configure_dt(&i3c_mng_owner, GPIO_OUTPUT);
120+
LOG_INF("Switch I3C MNG Owner to %s", owner == I3C_MNG_OWNER_BMC ? "BMC" : "ROT");
121+
gpio_pin_set(i3c_mng_owner.port, i3c_mng_owner.pin, owner);
118122
i3c_mng_mux_owner = owner;
119123
}
120124
#endif

0 commit comments

Comments
 (0)