From 8081c70a82a691beb54d114fa9d42124d631cc4e Mon Sep 17 00:00:00 2001 From: Zhang Yubing Date: Sun, 14 Nov 2021 10:58:06 +0800 Subject: [PATCH] phy: rockchip: usbdp-phy: add pointer check, avoid NULL pointer When enter DP mode, exit DP mode, disconnect device, the data is NULL. And only check the hpd is connect, set the gpio. Signed-off-by: Zhang Yubing Change-Id: I7a3558c5ee5f954055fdd5edbbd50b5079d8f323 --- drivers/phy/rockchip/phy-rockchip-usbdp.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c index d314b0bd0cae..aec6fae650ba 100644 --- a/drivers/phy/rockchip/phy-rockchip-usbdp.c +++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c @@ -805,16 +805,6 @@ static int usbdp_typec_mux_set(struct typec_mux *mux, break; } - if (udphy->sbu1_dc_gpio && udphy->sbu1_dc_gpio) { - if (udphy->flip) { - gpiod_set_value_cansleep(udphy->sbu1_dc_gpio, 1); - gpiod_set_value_cansleep(udphy->sbu2_dc_gpio, 0); - } else { - gpiod_set_value_cansleep(udphy->sbu1_dc_gpio, 0); - gpiod_set_value_cansleep(udphy->sbu2_dc_gpio, 1); - } - } - if (udphy->mode != mode) { udphy->mode = mode; udphy->mode_change = true; @@ -823,7 +813,17 @@ static int usbdp_typec_mux_set(struct typec_mux *mux, if (state->alt && state->alt->svid == USB_TYPEC_DP_SID) { struct typec_displayport_data *data = state->data; - bool hpd = !!(data->status & DP_STATUS_HPD_STATE); + bool hpd = !!(data && (data->status & DP_STATUS_HPD_STATE)); + + if (hpd && udphy->sbu1_dc_gpio && udphy->sbu1_dc_gpio) { + if (udphy->flip) { + gpiod_set_value_cansleep(udphy->sbu1_dc_gpio, 1); + gpiod_set_value_cansleep(udphy->sbu2_dc_gpio, 0); + } else { + gpiod_set_value_cansleep(udphy->sbu1_dc_gpio, 0); + gpiod_set_value_cansleep(udphy->sbu2_dc_gpio, 1); + } + } if (cfg->hpd_event_trigger) cfg->hpd_event_trigger(udphy, hpd);