From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-by2nam03on0102.outbound.protection.outlook.com ([104.47.42.102]:30227 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935162AbeCSQMR (ORCPT ); Mon, 19 Mar 2018 12:12:17 -0400 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Jisheng Zhang , Peter Chen , Sasha Levin Subject: [PATCH AUTOSEL for 3.18 029/102] usb: chipidea: properly handle host or gadget initialization failure Date: Mon, 19 Mar 2018 16:12:03 +0000 Message-ID: <20180319161117.17833-29-alexander.levin@microsoft.com> References: <20180319161117.17833-1-alexander.levin@microsoft.com> In-Reply-To: <20180319161117.17833-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Jisheng Zhang [ Upstream commit c4a0bbbdb7f6e3c37fa6deb3ef28c5ed99da6175 ] If ci_hdrc_host_init() or ci_hdrc_gadget_init() returns error and the error !=3D -ENXIO, as Peter pointed out, "it stands for initialization for host or gadget has failed", so we'd better return failure rather continue. And before destroying the otg, i.e ci_hdrc_otg_destroy(ci), we should also check ci->roles[CI_ROLE_GADGET]. Signed-off-by: Jisheng Zhang Signed-off-by: Peter Chen Signed-off-by: Sasha Levin --- drivers/usb/chipidea/core.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 78f4d70db917..4a8934abdac8 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -553,7 +553,7 @@ static inline void ci_role_destroy(struct ci_hdrc *ci) { ci_hdrc_gadget_destroy(ci); ci_hdrc_host_destroy(ci); - if (ci->is_otg) + if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) ci_hdrc_otg_destroy(ci); } =20 @@ -653,20 +653,28 @@ static int ci_hdrc_probe(struct platform_device *pdev= ) /* initialize role(s) before the interrupt is requested */ if (dr_mode =3D=3D USB_DR_MODE_OTG || dr_mode =3D=3D USB_DR_MODE_HOST) { ret =3D ci_hdrc_host_init(ci); - if (ret) - dev_info(dev, "doesn't support host\n"); + if (ret) { + if (ret =3D=3D -ENXIO) + dev_info(dev, "doesn't support host\n"); + else + goto deinit_phy; + } } =20 if (dr_mode =3D=3D USB_DR_MODE_OTG || dr_mode =3D=3D USB_DR_MODE_PERIPHER= AL) { ret =3D ci_hdrc_gadget_init(ci); - if (ret) - dev_info(dev, "doesn't support gadget\n"); + if (ret) { + if (ret =3D=3D -ENXIO) + dev_info(dev, "doesn't support gadget\n"); + else + goto deinit_host; + } } =20 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) { dev_err(dev, "no supported roles\n"); ret =3D -ENODEV; - goto deinit_phy; + goto deinit_gadget; } =20 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) { @@ -676,7 +684,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) ret =3D ci_hdrc_otg_init(ci); if (ret) { dev_err(dev, "init otg fails, ret =3D %d\n", ret); - goto stop; + goto deinit_gadget; } } =20 @@ -727,7 +735,12 @@ static int ci_hdrc_probe(struct platform_device *pdev) =20 free_irq(ci->irq, ci); stop: - ci_role_destroy(ci); + if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) + ci_hdrc_otg_destroy(ci); +deinit_gadget: + ci_hdrc_gadget_destroy(ci); +deinit_host: + ci_hdrc_host_destroy(ci); deinit_phy: usb_phy_shutdown(ci->transceiver); =20 --=20 2.14.1