From 61c66d0fb074510155365f4dd03770bcd870be68 Mon Sep 17 00:00:00 2001 From: Jack Pham Date: Thu, 14 Jul 2016 10:52:11 -0700 Subject: [PATCH] usb: pd: pdphy: Assign __pdphy before usbpd_create() As the PD PHY probes, assign the static __pdphy pointer with the pdphy instance prior to calling usbpd_create(). This ensures that if the policy engine state machine kicks off right away and calls back into the PHY APIs that there is a valid instance found. As further safeguarding, also fix the open/close/signal/write APIs in the case where the instance cannot be found by using pr_err instead of dev_err which would lead to a NULL pointer dereference. Change-Id: I59a01f2ac3b0c374eb3420f40054cc05a80226ba Signed-off-by: Jack Pham --- drivers/usb/pd/qpnp-pdphy.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/usb/pd/qpnp-pdphy.c b/drivers/usb/pd/qpnp-pdphy.c index 4585393a9552..70bb916d863f 100644 --- a/drivers/usb/pd/qpnp-pdphy.c +++ b/drivers/usb/pd/qpnp-pdphy.c @@ -318,7 +318,7 @@ int pd_phy_open(struct pd_phy_params *params) struct usb_pdphy *pdphy = __pdphy; if (!pdphy) { - dev_err(pdphy->dev, "%s: pdphy not found\n", __func__); + pr_err("%s: pdphy not found\n", __func__); return -ENODEV; } @@ -382,7 +382,7 @@ int pd_phy_signal(enum pd_sig_type type, unsigned int timeout_ms) timeout_ms); if (!pdphy) { - dev_err(pdphy->dev, "%s: pdphy not found\n", __func__); + pr_err("%s: pdphy not found\n", __func__); return -ENODEV; } @@ -440,7 +440,7 @@ int pd_phy_write(u16 hdr, const u8 *data, size_t data_len, data, data_len, false); if (!pdphy) { - dev_err(pdphy->dev, "%s: pdphy not found\n", __func__); + pr_err("%s: pdphy not found\n", __func__); return -ENODEV; } @@ -507,7 +507,7 @@ void pd_phy_close(void) struct usb_pdphy *pdphy = __pdphy; if (!pdphy) { - dev_err(pdphy->dev, "%s: pdphy not found\n", __func__); + pr_err("%s: pdphy not found\n", __func__); return; } @@ -766,15 +766,17 @@ static int pdphy_probe(struct platform_device *pdev) if (ret < 0) return ret; + /* usbpd_create() could call back to us, so have __pdphy ready */ + __pdphy = pdphy; + pdphy->usbpd = usbpd_create(&pdev->dev); if (IS_ERR(pdphy->usbpd)) { dev_err(&pdev->dev, "usbpd_create failed: %ld\n", PTR_ERR(pdphy->usbpd)); + __pdphy = NULL; return PTR_ERR(pdphy->usbpd); } - __pdphy = pdphy; - pdphy_create_debugfs_entries(pdphy); return 0;