From patchwork Thu Apr 18 14:57:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 790150 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F08A16C44E; Thu, 18 Apr 2024 14:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713452292; cv=none; b=HbnHvkXEgHaXaECNBFqB6bMHFSACJhLc/i1bqMaui+5zMOYrN7l1NtZ1QK4meHZad0jCg6Iskfc2/LYB0R+sC9wzB6wSEU3txVRbxzevTv/IVRFd96Jxbo8WEdzqPqsmxUsHOm7pYKZM8KVikHxMoZwiIOnPKzdq2TEEfaeZlT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713452292; c=relaxed/simple; bh=UK8vqYDQnVb4UuEiWOQ7/t28ga5C7zQ4CaigIsh4k3U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ayoeMhg9TC0O1DBYGedMdjcNivRaax4H7TBHdYu5PR0dWubVdOS3Mkb1fspACFGv8AkhrkAY5pI968y7jFTrQF2chU4V0An1hyhXpVG9wQTLxM6BL16+hD4QNoYRUzddnR3UjQlXReeMNEbuyJ1uS8xlriRpzKVcQ3mOu15/OhE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dn9CNOmA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Dn9CNOmA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E47CC3277B; Thu, 18 Apr 2024 14:58:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713452292; bh=UK8vqYDQnVb4UuEiWOQ7/t28ga5C7zQ4CaigIsh4k3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dn9CNOmAuEatBytm3HjuegWQ0hIru7pceldtn92AnbKt2+bU2CWWXMS58cDbEstNa 9NQmyobuAmOc6OGSdMulV7gOBVmdhtUVJbraIF4tlLIlRFOD4xDuRije705U/Vn0an t9LEzzXyVmHgdbjVkEhYLl5Y3S2dXHfTEb8X1mzBbiTfoMgoBFjkSvCPy67vnhQlZU QiIhMH+X/MFz+gvBiBpGEVwzOKflLtkw4R8VMqqgVMqhi5Xiww2kCdzVGkq6I3W59r c2MVgh53JAle7ZUoOyQkZbWxw7dgXsVImfnJEmwy7tZffSev2kF5QJ/iOpAY+FyIbv xG8RM5UA+V5qQ== Received: from johan by xi.lan with local (Exim 4.97.1) (envelope-from ) id 1rxTDK-000000001DR-2XFV; Thu, 18 Apr 2024 16:58:14 +0200 From: Johan Hovold To: Bryan O'Donoghue , Heikki Krogerus Cc: Bjorn Andersson , Konrad Dybcio , Greg Kroah-Hartman , Dmitry Baryshkov , linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH 1/2] usb: typec: qcom-pmic: fix use-after-free on late probe errors Date: Thu, 18 Apr 2024 16:57:29 +0200 Message-ID: <20240418145730.4605-2-johan+linaro@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240418145730.4605-1-johan+linaro@kernel.org> References: <20240418145730.4605-1-johan+linaro@kernel.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make sure to stop and deregister the port in case of late probe errors to avoid use-after-free issues when the underlying memory is released by devres. Fixes: a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver") Cc: stable@vger.kernel.org # 6.5 Cc: Bryan O'Donoghue Signed-off-by: Johan Hovold Reviewed-by: Dmitry Baryshkov Reviewed-by: Bryan O'Donoghue Reviewed-by: Heikki Krogerus --- drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c index e48412cdcb0f..d3958c061a97 100644 --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c @@ -104,14 +104,18 @@ static int qcom_pmic_typec_probe(struct platform_device *pdev) ret = tcpm->port_start(tcpm, tcpm->tcpm_port); if (ret) - goto fwnode_remove; + goto port_unregister; ret = tcpm->pdphy_start(tcpm, tcpm->tcpm_port); if (ret) - goto fwnode_remove; + goto port_stop; return 0; +port_stop: + tcpm->port_stop(tcpm); +port_unregister: + tcpm_unregister_port(tcpm->tcpm_port); fwnode_remove: fwnode_remove_software_node(tcpm->tcpc.fwnode); From patchwork Thu Apr 18 14:57:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 790943 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F0CC16C451; Thu, 18 Apr 2024 14:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713452292; cv=none; b=VYnf8SVhVQWWDMHx4uYMZtYNCQxPHopZFbvofHPcecSVt/1Di5EApzsER908EqTXeV3N44erLnkiPiv6Y28HsnF0sirIguKtzkaFB1Un9HZTzX9EogbuKAp2dQg+qMoAw1nJS51iiNxKlZjCzKk6mVdgq12fBQKNTtJNKJEZNAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713452292; c=relaxed/simple; bh=7w01AiG11Y7amIIDkVp7Po/rT6bsXkEo2AhSc//sXgI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NrRNlgNffAVHolSe8mDOHqaNBshgZFvt+McBMGZu334g0LDKkhsx0jlIhvTafGBq5JHJp3DlH0ZzFQMX59unj+ppifTN3dWIxoqhYHIWeQe8DHolRpZYx9amxYI856MQhtQeeanWn2yzAHWL1YTjt8SXGxPPNpvIcf3d2Xaialk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mGPfueHz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mGPfueHz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 106E1C4AF0C; Thu, 18 Apr 2024 14:58:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713452292; bh=7w01AiG11Y7amIIDkVp7Po/rT6bsXkEo2AhSc//sXgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mGPfueHzJOPx7dUM8DqwQ2dk78uCt5nikkbAQpTi3dY8RhP3WEvCTqqNNehyPMb+R 1Ie+rJDj6tDsJPTyMSMvJ37OQsqF1wTXiMYSlFG9EBU4WBeeG4Knyv6q//d9647hr8 ZHM/IfXkGjDktkDHm6WCBxwDgeQfNg4waOvOVvNyWUU825UaXbWiCAF1B+zielsGw5 CG/1plURpp4WurkDQ2GUBVVqjSH0Mv4fp+fa13nI9N2xt5wb6y4Jdum0651LjKaMz5 TXIhQIS8rpC49HP0YxloM+kSuM1MkyNp4ugHYRH8Ae0VbHVdxIZ1GP9zOAXlBg/Hez NxpRuLu9qPmOA== Received: from johan by xi.lan with local (Exim 4.97.1) (envelope-from ) id 1rxTDK-000000001DT-2uhC; Thu, 18 Apr 2024 16:58:14 +0200 From: Johan Hovold To: Bryan O'Donoghue , Heikki Krogerus Cc: Bjorn Andersson , Konrad Dybcio , Greg Kroah-Hartman , Dmitry Baryshkov , linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 2/2] usb: typec: qcom-pmic: fix pdphy start() error handling Date: Thu, 18 Apr 2024 16:57:30 +0200 Message-ID: <20240418145730.4605-3-johan+linaro@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240418145730.4605-1-johan+linaro@kernel.org> References: <20240418145730.4605-1-johan+linaro@kernel.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move disabling of the vdd-pdphy supply to the start() function which enabled it for symmetry and to make sure that it is disabled as intended in all error paths of pmic_typec_pdphy_reset() (i.e. not just when qcom_pmic_typec_pdphy_enable() fails). Fixes: a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver") Signed-off-by: Johan Hovold Reviewed-by: Heikki Krogerus --- drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c index 6560f4fc98d5..5b7f52b74a40 100644 --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c @@ -475,10 +475,8 @@ static int qcom_pmic_typec_pdphy_enable(struct pmic_typec_pdphy *pmic_typec_pdph qcom_pmic_typec_pdphy_reset_off(pmic_typec_pdphy); done: - if (ret) { - regulator_disable(pmic_typec_pdphy->vdd_pdphy); + if (ret) dev_err(dev, "pdphy_enable fail %d\n", ret); - } return ret; } @@ -524,12 +522,17 @@ static int qcom_pmic_typec_pdphy_start(struct pmic_typec *tcpm, ret = pmic_typec_pdphy_reset(pmic_typec_pdphy); if (ret) - return ret; + goto err_disable_vdd_pdhy; for (i = 0; i < pmic_typec_pdphy->nr_irqs; i++) enable_irq(pmic_typec_pdphy->irq_data[i].irq); return 0; + +err_disable_vdd_pdhy: + regulator_disable(pmic_typec_pdphy->vdd_pdphy); + + return ret; } static void qcom_pmic_typec_pdphy_stop(struct pmic_typec *tcpm)