Skip to content

Commit ab137d0

Browse files
Venu ByravarasuStephen Warren
authored andcommitted
usb: host: tegra: make use of PHY pointer of HCD
As pointer to PHY structure can be stored in struct usb_hcd making use of it, to call Tegra PHY APIs. Call to usb_phy_shutdown() is moved up in tegra_ehci_remove(), so that to avoid dereferencing of hcd after its freed up. Signed-off-by: Venu Byravarasu <vbyravarasu@nvidia.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Acked-by: Felipe Balbi <balbi@ti.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Stephen Warren <swarren@nvidia.com>
1 parent 40e8b3a commit ab137d0

3 files changed

Lines changed: 29 additions & 22 deletions

File tree

‎drivers/usb/host/ehci-tegra.c‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static void tegra_ehci_power_up(struct usb_hcd *hcd)
5656
struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
5757

5858
clk_prepare_enable(tegra->clk);
59-
usb_phy_set_suspend(&tegra->phy->u_phy, 0);
59+
usb_phy_set_suspend(hcd->phy, 0);
6060
tegra->host_resumed = 1;
6161
}
6262

@@ -65,7 +65,7 @@ static void tegra_ehci_power_down(struct usb_hcd *hcd)
6565
struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
6666

6767
tegra->host_resumed = 0;
68-
usb_phy_set_suspend(&tegra->phy->u_phy, 1);
68+
usb_phy_set_suspend(hcd->phy, 1);
6969
clk_disable_unprepare(tegra->clk);
7070
}
7171

@@ -159,7 +159,7 @@ static int tegra_ehci_hub_control(
159159
if (tegra->port_resuming && !(temp & PORT_SUSPEND)) {
160160
/* Resume completed, re-enable disconnect detection */
161161
tegra->port_resuming = 0;
162-
tegra_usb_phy_postresume(tegra->phy);
162+
tegra_usb_phy_postresume(hcd->phy);
163163
}
164164
}
165165

@@ -212,7 +212,7 @@ static int tegra_ehci_hub_control(
212212
goto done;
213213

214214
/* Disable disconnect detection during port resume */
215-
tegra_usb_phy_preresume(tegra->phy);
215+
tegra_usb_phy_preresume(hcd->phy);
216216

217217
ehci->reset_done[wIndex-1] = jiffies + msecs_to_jiffies(25);
218218

@@ -476,7 +476,7 @@ static int controller_resume(struct device *dev)
476476
}
477477

478478
/* Force the phy to keep data lines in suspend state */
479-
tegra_ehci_phy_restore_start(tegra->phy, tegra->port_speed);
479+
tegra_ehci_phy_restore_start(hcd->phy, tegra->port_speed);
480480

481481
/* Enable host mode */
482482
tdi_reset(ehci);
@@ -543,17 +543,17 @@ static int controller_resume(struct device *dev)
543543
}
544544
}
545545

546-
tegra_ehci_phy_restore_end(tegra->phy);
546+
tegra_ehci_phy_restore_end(hcd->phy);
547547
goto done;
548548

549549
restart:
550550
if (tegra->port_speed <= TEGRA_USB_PHY_PORT_SPEED_HIGH)
551-
tegra_ehci_phy_restore_end(tegra->phy);
551+
tegra_ehci_phy_restore_end(hcd->phy);
552552

553553
tegra_ehci_restart(hcd);
554554

555555
done:
556-
tegra_usb_phy_preresume(tegra->phy);
556+
tegra_usb_phy_preresume(hcd->phy);
557557
tegra->port_resuming = 1;
558558
return 0;
559559
}
@@ -740,9 +740,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)
740740
goto fail_io;
741741
}
742742

743-
usb_phy_init(&tegra->phy->u_phy);
744-
745743
hcd->phy = u_phy = &tegra->phy->u_phy;
744+
usb_phy_init(hcd->phy);
745+
746746
u_phy->otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg),
747747
GFP_KERNEL);
748748
if (!u_phy->otg) {
@@ -752,7 +752,7 @@ static int tegra_ehci_probe(struct platform_device *pdev)
752752
}
753753
u_phy->otg->host = hcd_to_bus(hcd);
754754

755-
err = usb_phy_set_suspend(&tegra->phy->u_phy, 0);
755+
err = usb_phy_set_suspend(hcd->phy, 0);
756756
if (err) {
757757
dev_err(&pdev->dev, "Failed to power on the phy\n");
758758
goto fail;
@@ -798,7 +798,7 @@ static int tegra_ehci_probe(struct platform_device *pdev)
798798
if (!IS_ERR_OR_NULL(tegra->transceiver))
799799
otg_set_host(tegra->transceiver->otg, NULL);
800800
#endif
801-
usb_phy_shutdown(&tegra->phy->u_phy);
801+
usb_phy_shutdown(hcd->phy);
802802
fail_io:
803803
clk_disable_unprepare(tegra->clk);
804804
fail_clk:
@@ -820,11 +820,10 @@ static int tegra_ehci_remove(struct platform_device *pdev)
820820
otg_set_host(tegra->transceiver->otg, NULL);
821821
#endif
822822

823+
usb_phy_shutdown(hcd->phy);
823824
usb_remove_hcd(hcd);
824825
usb_put_hcd(hcd);
825826

826-
usb_phy_shutdown(&tegra->phy->u_phy);
827-
828827
clk_disable_unprepare(tegra->clk);
829828

830829
return 0;

‎drivers/usb/phy/tegra_usb_phy.c‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,30 +759,38 @@ struct tegra_usb_phy *tegra_usb_phy_open(struct device *dev, int instance,
759759
}
760760
EXPORT_SYMBOL_GPL(tegra_usb_phy_open);
761761

762-
void tegra_usb_phy_preresume(struct tegra_usb_phy *phy)
762+
void tegra_usb_phy_preresume(struct usb_phy *x)
763763
{
764+
struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
765+
764766
if (!phy->is_ulpi_phy)
765767
utmi_phy_preresume(phy);
766768
}
767769
EXPORT_SYMBOL_GPL(tegra_usb_phy_preresume);
768770

769-
void tegra_usb_phy_postresume(struct tegra_usb_phy *phy)
771+
void tegra_usb_phy_postresume(struct usb_phy *x)
770772
{
773+
struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
774+
771775
if (!phy->is_ulpi_phy)
772776
utmi_phy_postresume(phy);
773777
}
774778
EXPORT_SYMBOL_GPL(tegra_usb_phy_postresume);
775779

776-
void tegra_ehci_phy_restore_start(struct tegra_usb_phy *phy,
780+
void tegra_ehci_phy_restore_start(struct usb_phy *x,
777781
enum tegra_usb_phy_port_speed port_speed)
778782
{
783+
struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
784+
779785
if (!phy->is_ulpi_phy)
780786
utmi_phy_restore_start(phy, port_speed);
781787
}
782788
EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_start);
783789

784-
void tegra_ehci_phy_restore_end(struct tegra_usb_phy *phy)
790+
void tegra_ehci_phy_restore_end(struct usb_phy *x)
785791
{
792+
struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
793+
786794
if (!phy->is_ulpi_phy)
787795
utmi_phy_restore_end(phy);
788796
}

‎include/linux/usb/tegra_usb_phy.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ struct tegra_usb_phy {
6666
struct tegra_usb_phy *tegra_usb_phy_open(struct device *dev, int instance,
6767
void __iomem *regs, void *config, enum tegra_usb_phy_mode phy_mode);
6868

69-
void tegra_usb_phy_preresume(struct tegra_usb_phy *phy);
69+
void tegra_usb_phy_preresume(struct usb_phy *phy);
7070

71-
void tegra_usb_phy_postresume(struct tegra_usb_phy *phy);
71+
void tegra_usb_phy_postresume(struct usb_phy *phy);
7272

73-
void tegra_ehci_phy_restore_start(struct tegra_usb_phy *phy,
73+
void tegra_ehci_phy_restore_start(struct usb_phy *phy,
7474
enum tegra_usb_phy_port_speed port_speed);
7575

76-
void tegra_ehci_phy_restore_end(struct tegra_usb_phy *phy);
76+
void tegra_ehci_phy_restore_end(struct usb_phy *phy);
7777

7878
void tegra_ehci_set_pts(struct usb_phy *x, u8 pts_val);
7979

0 commit comments

Comments
 (0)