From: Colin Ian King Date: Wed, 3 Mar 2021 09:58:26 +0000 (+0000) Subject: usb: dwc3: Fix dereferencing of null dwc->usb_psy X-Git-Tag: accepted/tizen/unified/20230118.172025~7412^2~251 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b0bf77cd389d12f61d1d79aa54e1ec03b68a8a11;p=platform%2Fkernel%2Flinux-rpi.git usb: dwc3: Fix dereferencing of null dwc->usb_psy Currently the null check logic on dwc->usb_psy is inverted as it allows calls to power_supply_put with a null dwc->usb_psy causing a null pointer dereference. Fix this by removing the ! operator. Addresses-Coverity: ("Dereference after null check") Fixes: 59fa3def35de ("usb: dwc3: add a power supply for current control") Signed-off-by: Colin Ian King Link: https://lore.kernel.org/r/20210303095826.6143-1-colin.king@canonical.com Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index d15f065..94fdbe5 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1628,7 +1628,7 @@ disable_clks: assert_reset: reset_control_assert(dwc->reset); - if (!dwc->usb_psy) + if (dwc->usb_psy) power_supply_put(dwc->usb_psy); return ret; @@ -1653,7 +1653,7 @@ static int dwc3_remove(struct platform_device *pdev) dwc3_free_event_buffers(dwc); dwc3_free_scratch_buffers(dwc); - if (!dwc->usb_psy) + if (dwc->usb_psy) power_supply_put(dwc->usb_psy); return 0;