get_vbus_regulator_handle() logs a spurious "Failed to get vbus regulator handle" error during probe and stores the ERR_PTR in chip->vbus_reg even when sourcing VBUS is not requested. During tcpci_register_port(), tcpm_init_vbus() calls set_vbus(false, false) before the PMIC charger providing the vbus regulator has probed (the charger's power supply waits for the TCPM power supply), or on sink-only boards without a vbus regulator. Sink-only operation does not need the vbus regulator, and max_tcpci_set_vbus() already ignores regulator lookup failures when source is false. Leave chip->vbus_reg untouched when regulator_get_exclusive() fails, return the error from get_vbus_regulator_handle() silently, and log an error in max_tcpci_set_vbus() only when sourcing is requested. Fixes: 0c8935642cb0 ("usb: typec: tcpm/tcpci_maxim: deprecate WAR for setting charger mode") Cc: stable@vger.kernel.org Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/tcpci_maxim_core.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c index 2e6a8906fb32..736d01694745 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c +++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c @@ -208,15 +208,16 @@ static void process_rx(struct max_tcpci_chip *chip, u16 status) static int get_vbus_regulator_handle(struct max_tcpci_chip *chip) { - if (IS_ERR_OR_NULL(chip->vbus_reg)) { - chip->vbus_reg = regulator_get_exclusive(chip->dev, "vbus"); - if (IS_ERR_OR_NULL(chip->vbus_reg)) { - dev_err(chip->dev, - "Failed to get vbus regulator handle\n"); - return -ENODEV; - } - } + struct regulator *reg; + + if (chip->vbus_reg) + return 0; + reg = regulator_get_exclusive(chip->dev, "vbus"); + if (IS_ERR(reg)) + return PTR_ERR(reg); + + chip->vbus_reg = reg; return 0; } @@ -224,7 +225,7 @@ static void max_tcpci_put_vbus_regulator(void *data) { struct max_tcpci_chip *chip = data; - if (!IS_ERR_OR_NULL(chip->vbus_reg)) + if (chip->vbus_reg) regulator_put(chip->vbus_reg); } @@ -244,7 +245,12 @@ static int max_tcpci_set_vbus(struct tcpci *tcpci, struct tcpci_data *tdata, boo * Regulator is not necessary for sink only applications. Return * success in cases where sink mode is being modified. */ - return source ? ret : 1; + if (!source) + return 1; + + dev_err(chip->dev, "Failed to get vbus regulator: %pe\n", + ERR_PTR(ret)); + return ret; } if (source) { -- 2.56.1.839.g22a8290db9-goog