kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] phy: sun4i-usb: fix dereference of pointer phy0 before it is null checked
@ 2020-06-25 12:44 Colin King
  2020-06-25 12:57 ` Vinod Koul
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2020-06-25 12:44 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Vinod Koul, Maxime Ripard, Chen-Yu Tsai,
	Krzysztof Kozlowski, Paul Kocialkowski, linux-arm-kernel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently pointer phy0 is being dereferenced via the assignment of
phy on the call to phy_get_drvdata before phy0 is null checked, this
can lead to a null pointer dereference. Fix this by performing the
null check on phy0 before the call to phy_get_drvdata. Also replace
the phy0 = NULL check with the more usual !phy0 idiom.

Addresses-Coverity: ("Dereference before null check")
Fixes: e6f32efb1b12 ("phy: sun4i-usb: Make sure to disable PHY0 passby for peripheral mode")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/phy/allwinner/phy-sun4i-usb.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
index 7e09ad6a0b42..f7a59a75df1a 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -545,13 +545,14 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
 	struct sun4i_usb_phy_data *data  		container_of(work, struct sun4i_usb_phy_data, detect.work);
 	struct phy *phy0 = data->phys[0].phy;
-	struct sun4i_usb_phy *phy = phy_get_drvdata(phy0);
+	struct sun4i_usb_phy *phy;
 	bool force_session_end, id_notify = false, vbus_notify = false;
 	int id_det, vbus_det;
 
-	if (phy0 = NULL)
+	if (!phy0)
 		return;
 
+	phy = phy_get_drvdata(phy0);
 	id_det = sun4i_usb_phy0_get_id_det(data);
 	vbus_det = sun4i_usb_phy0_get_vbus_det(data);
 
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] phy: sun4i-usb: fix dereference of pointer phy0 before it is null checked
  2020-06-25 12:44 [PATCH] phy: sun4i-usb: fix dereference of pointer phy0 before it is null checked Colin King
@ 2020-06-25 12:57 ` Vinod Koul
  0 siblings, 0 replies; 2+ messages in thread
From: Vinod Koul @ 2020-06-25 12:57 UTC (permalink / raw)
  To: Colin King
  Cc: kernel-janitors, linux-kernel, Krzysztof Kozlowski,
	Kishon Vijay Abraham I, Paul Kocialkowski, Chen-Yu Tsai,
	Maxime Ripard, linux-arm-kernel

On 25-06-20, 13:44, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently pointer phy0 is being dereferenced via the assignment of
> phy on the call to phy_get_drvdata before phy0 is null checked, this
> can lead to a null pointer dereference. Fix this by performing the
> null check on phy0 before the call to phy_get_drvdata. Also replace
> the phy0 = NULL check with the more usual !phy0 idiom.

Applied, thanks
-- 
~Vinod

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-25 12:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-25 12:44 [PATCH] phy: sun4i-usb: fix dereference of pointer phy0 before it is null checked Colin King
2020-06-25 12:57 ` Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).