Sean Rhodes has submitted this change. ( https://review.coreboot.org/c/coreboot/+/84615?usp=email )
(
3 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: drivers/intel/usb4: Guard usage of RFMU with a null check ......................................................................
drivers/intel/usb4: Guard usage of RFMU with a null check
Add a null check around the usage of the RFWU (Retimer Firmware Update path) in the `usb4_retimer_execute_ec_cmd` function. This ensures that any interaction with RFWU is only performed when the path is valid, preventing potential null pointer dereferences.
This fixes are large amount of errors when `ec_retimer_fw_update_path` isn't declared, such as comparisons like `If ((Local0 == Break))`.
Change-Id: I5a219345440f91332f680885b51e2cc09f14f7a7 Signed-off-by: Sean Rhodes sean@starlabs.systems Reviewed-on: https://review.coreboot.org/c/coreboot/+/84615 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: coreboot org coreboot.org@gmail.com --- M src/drivers/intel/usb4/retimer/retimer.c 1 file changed, 39 insertions(+), 34 deletions(-)
Approvals: coreboot org: Looks good to me, approved build bot (Jenkins): Verified
diff --git a/src/drivers/intel/usb4/retimer/retimer.c b/src/drivers/intel/usb4/retimer/retimer.c index 3769fc9..40dd4c1 100644 --- a/src/drivers/intel/usb4/retimer/retimer.c +++ b/src/drivers/intel/usb4/retimer/retimer.c @@ -36,10 +36,12 @@ /* Invoke EC Retimer firmware update command execution */ ec_retimer_fw_update(data); /* If RFWU has return value 0xfe, return error -1 */ - acpigen_write_if_lequal_namestr_int(RFWU, USB_RETIMER_FW_UPDATE_ERROR); - acpigen_disable_tx_gpio(power_gpio); - acpigen_write_return_integer(-1); - acpigen_pop_len(); /* If */ + if (RFWU) { + acpigen_write_if_lequal_namestr_int(RFWU, USB_RETIMER_FW_UPDATE_ERROR); + acpigen_disable_tx_gpio(power_gpio); + acpigen_write_return_integer(-1); + acpigen_pop_len(); /* If */ + }
acpigen_write_store_int_to_op(USB4_RETIMER_ITERATION_NUM, LOCAL2_OP); acpigen_emit_byte(WHILE_OP); @@ -47,39 +49,42 @@ acpigen_emit_byte(LGREATER_OP); acpigen_emit_byte(LOCAL2_OP); acpigen_emit_byte(ZERO_OP); - acpigen_write_if_lequal_namestr_int(RFWU, expected_value); - acpigen_emit_byte(BREAK_OP); - acpigen_pop_len(); /* If */
- if (cmd == USB_RETIMER_FW_UPDATE_GET_MUX) { - acpigen_write_if_lequal_namestr_int(RFWU, USB_RETIMER_FW_UPDATE_INVALID_MUX); - acpigen_write_sleep(USB4_RETIMER_POLL_CYCLE_MS); - acpigen_emit_byte(DECREMENT_OP); - acpigen_emit_byte(LOCAL2_OP); - acpigen_emit_byte(CONTINUE_OP); - acpigen_pop_len(); /* If */ - - acpigen_emit_byte(AND_OP); - acpigen_emit_namestring(RFWU); - acpigen_write_integer(USB_RETIMER_FW_UPDATE_MUX_MASK); - acpigen_emit_byte(LOCAL3_OP); - acpigen_write_if(); - acpigen_emit_byte(LNOT_OP); - acpigen_emit_byte(LEQUAL_OP); - acpigen_emit_byte(LOCAL3_OP); - acpigen_emit_byte(0); - acpigen_disable_tx_gpio(power_gpio); - acpigen_write_return_integer(-1); - acpigen_pop_len(); /* If */ - } else if (cmd == USB_RETIMER_FW_UPDATE_SET_TBT) { - /* - * EC return either USB_PD_MUX_USB4_ENABLED or USB_PD_MUX_TBT_COMPAT_ENABLED - * to RFWU after the USB_RETIMER_FW_UPDATE_SET_TBT command execution. It is - * needed to add additional check for USB_PD_MUX_TBT_COMPAT_ENABLED. - */ - acpigen_write_if_lequal_namestr_int(RFWU, USB_PD_MUX_TBT_COMPAT_ENABLED); + if (RFWU) { + acpigen_write_if_lequal_namestr_int(RFWU, expected_value); acpigen_emit_byte(BREAK_OP); acpigen_pop_len(); /* If */ + + if (cmd == USB_RETIMER_FW_UPDATE_GET_MUX) { + acpigen_write_if_lequal_namestr_int(RFWU, USB_RETIMER_FW_UPDATE_INVALID_MUX); + acpigen_write_sleep(USB4_RETIMER_POLL_CYCLE_MS); + acpigen_emit_byte(DECREMENT_OP); + acpigen_emit_byte(LOCAL2_OP); + acpigen_emit_byte(CONTINUE_OP); + acpigen_pop_len(); /* If */ + + acpigen_emit_byte(AND_OP); + acpigen_emit_namestring(RFWU); + acpigen_write_integer(USB_RETIMER_FW_UPDATE_MUX_MASK); + acpigen_emit_byte(LOCAL3_OP); + acpigen_write_if(); + acpigen_emit_byte(LNOT_OP); + acpigen_emit_byte(LEQUAL_OP); + acpigen_emit_byte(LOCAL3_OP); + acpigen_emit_byte(0); + acpigen_disable_tx_gpio(power_gpio); + acpigen_write_return_integer(-1); + acpigen_pop_len(); /* If */ + } else if (cmd == USB_RETIMER_FW_UPDATE_SET_TBT) { + /* + * EC return either USB_PD_MUX_USB4_ENABLED or USB_PD_MUX_TBT_COMPAT_ENABLED + * to RFWU after the USB_RETIMER_FW_UPDATE_SET_TBT command execution. It is + * needed to add additional check for USB_PD_MUX_TBT_COMPAT_ENABLED. + */ + acpigen_write_if_lequal_namestr_int(RFWU, USB_PD_MUX_TBT_COMPAT_ENABLED); + acpigen_emit_byte(BREAK_OP); + acpigen_pop_len(); /* If */ + } }
acpigen_write_sleep(USB4_RETIMER_POLL_CYCLE_MS);