From patchwork Wed Aug 14 09:39:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13763180 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 12530C52D7F for ; Wed, 14 Aug 2024 09:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=JmXmcga/zjb6ahfiHPXOSzwplx1CZRP7/PHn0u7sCk0=; b=wyJY10YUYgbmOKCkcsc9K/OR1s 3AbHQVlsSjxrDJeHTj9jsH2/OLRpV/x+lgPvLsqPMAGAnwyecoi4m0t9EpvMPA8tq56pePfYpF9Dq V8OroEJmYR567bqVwPzgSGyNOa/a2K/mtc4mVYwBZF1790a8bAQJoe6rjFjDvaax3xZfApwMwSXZe HLPikbR4X/juMfLoBTqPEtlIr4GcOnTnd2TXA6VHfIxo72Eta0/dppBif2Sibz46B6lC2vgXJhdf3 ksHAppOSlEtHMuv481awdz5vVuynBW4m+LloXCcWaO+GIx/+risuQSA4wqPwuopahrZyytK9hLlJ+ Zqcc9bIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1seAUy-00000006R33-1fx2; Wed, 14 Aug 2024 09:40:56 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1seAU7-00000006Qmt-0rSa for linux-arm-kernel@lists.infradead.org; Wed, 14 Aug 2024 09:40:04 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-429c4a4c6a8so34612945e9.0 for ; Wed, 14 Aug 2024 02:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723628401; x=1724233201; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JmXmcga/zjb6ahfiHPXOSzwplx1CZRP7/PHn0u7sCk0=; b=lyJcC9lRybJc2PzhUSSHVcd9xX+tw+rZwiW7jZzhymlHzWIRubFyOqG83j19OXuzMK yIdohHGblj0s50Wuokxyp1v9M3u1RO3qTRRShcFhU2qP92btRdDhFUPOSqDnjurIRLGo sEuhULa3cJAQ9gbQIvofnx4SxRyaWzdyQ2EtWnGdmwpEBUXuwECM2AdPk9VYVmOF119J i0WEfpbYRFLpw5wMceZdlEFo7IKhSg2YvqYw94xmIX+gFA3T4prP66Fgk3On54yzzWON aenTzr8MrBSVC8qcr3wuE3cVp/bIvN8/OG0ewiokQuMtVE92JDdroIjR2OwkRXRvdG2X kqow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723628401; x=1724233201; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JmXmcga/zjb6ahfiHPXOSzwplx1CZRP7/PHn0u7sCk0=; b=C7eZ0ZlV5Qq4gxUNIpZpVPulZ249bb2Q24LcnIV1UZXvdN+zVr0ATulNDyZLXlVx+n rd9HRY0oIQmSySrpgDpv7SXFgOjlTQyP3PMEVL7SvxeEx2s4TYBBIF4SMUMydWAfkE+b Ni8QsEzWnIwPfRueYUtZ+K7I71+1BVqZUz4lDptA5LrkcSWUcputZclBFBp7/Ai7JVZG X2zLIB8ZpFCjNXdonI23L2rcC3whyjBLA/jW+AvqYkQtt1qDRhdriOtWFotL3qcNObLS 6X9p29+Nyr+B1+eISe/p4Cc0fi1/aVqTENFEJSZuIol2oBmUmtkrgThNXhPyc4RGgQDw 25OA== X-Forwarded-Encrypted: i=1; AJvYcCWMoHXgoIyoLMKu/rjpkYl0ifSyG8MlQhFTY2nzbpzEdlKDZcDCBodLDAB+7B3JUg2o7SCipBXHySqmR8g0WF+M7z950MK6K4R5Kkt36lAeZ7cUcPY= X-Gm-Message-State: AOJu0YzH/16lPhFL7tGFu8tQXf9WPct/sF9Yr+DMDEHbzgDWY3paZXV4 sOscWCBCvFh12aBoYPYje0KynHVEux4EKySHAow1VA5oXbqWZ46CqwC8BbnKpAA= X-Google-Smtp-Source: AGHT+IF/bJMKfHmeWBSdbtMjSNM/VzBYMVOeE4F12fOKUYhXLXD2wvGqLv30n/W4um8EnKsh44iMBg== X-Received: by 2002:a05:600c:3c96:b0:426:6eae:6596 with SMTP id 5b1f17b1804b1-429dd264983mr13645925e9.25.1723628400773; Wed, 14 Aug 2024 02:40:00 -0700 (PDT) Received: from krzk-bin.. ([178.197.215.209]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded28cdasm14195615e9.16.2024.08.14.02.39.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 02:40:00 -0700 (PDT) From: Krzysztof Kozlowski To: Patrice Chotard , Thinh Nguyen , Greg Kroah-Hartman , Felipe Balbi , Peter Griffin , Giuseppe Cavallaro , Lee Jones , linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH 1/2] usb: dwc3: st: fix probed platform device ref count on probe error path Date: Wed, 14 Aug 2024 11:39:56 +0200 Message-ID: <20240814093957.37940-1-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240814_024003_272575_97EE364F X-CRM114-Status: GOOD ( 13.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The probe function never performs any paltform device allocation, thus error path "undo_platform_dev_alloc" is entirely bogus. It drops the reference count from the platform device being probed. If error path is triggered, this will lead to unbalanced device reference counts and premature release of device resources, thus possible use-after-free when releasing remaining devm-managed resources. Fixes: f83fca0707c6 ("usb: dwc3: add ST dwc3 glue layer to manage dwc3 HC") Cc: Signed-off-by: Krzysztof Kozlowski Reviewed-by: Patrice Chotard Acked-by: Thinh Nguyen --- drivers/usb/dwc3/dwc3-st.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c index 211360eee95a..a9cb04043f08 100644 --- a/drivers/usb/dwc3/dwc3-st.c +++ b/drivers/usb/dwc3/dwc3-st.c @@ -219,10 +219,8 @@ static int st_dwc3_probe(struct platform_device *pdev) dwc3_data->regmap = regmap; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-reg"); - if (!res) { - ret = -ENXIO; - goto undo_platform_dev_alloc; - } + if (!res) + return -ENXIO; dwc3_data->syscfg_reg_off = res->start; @@ -233,8 +231,7 @@ static int st_dwc3_probe(struct platform_device *pdev) devm_reset_control_get_exclusive(dev, "powerdown"); if (IS_ERR(dwc3_data->rstc_pwrdn)) { dev_err(&pdev->dev, "could not get power controller\n"); - ret = PTR_ERR(dwc3_data->rstc_pwrdn); - goto undo_platform_dev_alloc; + return PTR_ERR(dwc3_data->rstc_pwrdn); } /* Manage PowerDown */ @@ -300,8 +297,6 @@ static int st_dwc3_probe(struct platform_device *pdev) reset_control_assert(dwc3_data->rstc_rst); undo_powerdown: reset_control_assert(dwc3_data->rstc_pwrdn); -undo_platform_dev_alloc: - platform_device_put(pdev); return ret; } From patchwork Wed Aug 14 09:39:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13763203 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0C6BC3DA4A for ; Wed, 14 Aug 2024 09:41:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=MGrgEwiDQnCrsN02sqw6lNl+tSbCrY1oNE/v488RmdI=; b=Ir1wUhB4+2Sug1Jp6rA8tFjrf3 IKEqA0tpnvQo9BvB6mLo0p05rnJb4eJLKRPCCmxThM0c2IiVA3T6M+dPeIeQ9fEkz9FJOV9ZLtKPq 16HFSZZcX7hHHtmO0dPhrWSz/OPeNd5eV0PYwsHA/W4xjuizKpehsr4OL2aMEEsv60zG1+VgMt7mv 5OzzLdtIUjZVpctB8kCxXxJnEw72vSZ2Zf1wCywbMewWkWmfUPKlP57hD7gf24dSGVA5KjGxhrzmG xcpEKMZrTRZqtGaCUUvy8ewc8pEQiFRgCV1ite5DrwoBAYYa0/EWFSDt3uEqiShAyXWhUJgNBp0IB D8h5rDBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1seAVZ-00000006R9g-0PwY; Wed, 14 Aug 2024 09:41:33 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1seAU8-00000006QnY-3YsR for linux-arm-kernel@lists.infradead.org; Wed, 14 Aug 2024 09:40:07 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2f15dd0b489so83360741fa.3 for ; Wed, 14 Aug 2024 02:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723628403; x=1724233203; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MGrgEwiDQnCrsN02sqw6lNl+tSbCrY1oNE/v488RmdI=; b=Ej9dM/J+S4jJb2DayWQq5Xg5hCybz3LBW+M5u2prTVaBrqWexNYaVPsdx98Kk6RtRW EuCiSJmLTsNCn/HkT0QNY5W55cuEvQZRTvFnE6NG2UmXx51Qdmeg6yuM9B33Ig1CtnYf 5w2YHin0SPPAD5G4yETgRTpZfu6CCa010ht8rfZ/xQbf5XXUvx7ZWdTq7S3kyTi6Lx2F NPYcunBr/PiMQs2edrvkKq0N5u03qe+69fOksPdPqQGINyBksdpLqrx9CQzT6amkhXSx MTf4JSU2kyfDod/Ed7D2vxAB5s9tRV1i+oQHRQhqL8dzH8J8q4mI0+XVKQh0WnfVbs0L O8iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723628403; x=1724233203; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MGrgEwiDQnCrsN02sqw6lNl+tSbCrY1oNE/v488RmdI=; b=lnXVgNfftBZ5FhPGgXb1wmv9Fv49lsIC6BKdqSvy/5IVgogyq8eq+4pXnfaOEO/+Gk oxK7H+ovEUVhStZCuqizGKnmyw0xiGnpwzAdZ2lCtzrSDXr9wDY8Z3D9TC4A5dghhc4I m8uIqXALGdUeHhkBc/6X4mxBkcdItTEtnrlQXVHVFH5K4XFWOzRf7UOgFIjhYR+2YDt1 w2wTQq6KbLNSs20LSgA0cI6YPAHZRM2tictnH8ChsH7iUvSf5ZfZTjuc/36rxiZi9AOZ N08hfjjJrN2Lz10JZdecWGx94vuILRGp+3p6shmz4dXOLEdY92A5up7+nj0p8h5LS5CO 4Usw== X-Forwarded-Encrypted: i=1; AJvYcCXBzjYMhWVITol/GAK7Jih2fBSNRMqdy0JwCFoE+ehSJew2woDvSltLgFx0u+GSNuWmvnkMR5kiESVESkb2ya/k@lists.infradead.org X-Gm-Message-State: AOJu0Yz+g2SijmFONfMC8TAes9FFKB9g3rMSH7jagBEm1BMVEErz+dbt E0eMWts2RTGNfb7JYwbQPn4XUkNBoz8rIve/5wE26ersMRtoy+q5GwWOOjxf4ND6I0Sdf+ZyvmR R X-Google-Smtp-Source: AGHT+IHrsSXMDzPW+YC1yMSEObvTKIKA03QKkD9vhWlsmxjtI4DSdraFVWhJ0pwmrnCg1VCCTAW2Bw== X-Received: by 2002:a2e:e0a:0:b0:2f0:1c7d:1ee2 with SMTP id 38308e7fff4ca-2f3aa1f99e7mr10852261fa.41.1723628402703; Wed, 14 Aug 2024 02:40:02 -0700 (PDT) Received: from krzk-bin.. ([178.197.215.209]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded28cdasm14195615e9.16.2024.08.14.02.40.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 02:40:01 -0700 (PDT) From: Krzysztof Kozlowski To: Patrice Chotard , Thinh Nguyen , Greg Kroah-Hartman , Felipe Balbi , Peter Griffin , Giuseppe Cavallaro , Lee Jones , linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH 2/2] usb: dwc3: st: add missing depopulate in probe error path Date: Wed, 14 Aug 2024 11:39:57 +0200 Message-ID: <20240814093957.37940-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240814093957.37940-1-krzysztof.kozlowski@linaro.org> References: <20240814093957.37940-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240814_024004_984133_8ACA5E5D X-CRM114-Status: GOOD ( 13.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Depopulate device in probe error paths to fix leak of children resources. Fixes: f83fca0707c6 ("usb: dwc3: add ST dwc3 glue layer to manage dwc3 HC") Cc: Signed-off-by: Krzysztof Kozlowski Reviewed-by: Patrice Chotard Acked-by: Thinh Nguyen --- Context of my other cleanup patches (separate series to be sent soon) will depend on this. --- drivers/usb/dwc3/dwc3-st.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c index a9cb04043f08..c8c7cd0c1796 100644 --- a/drivers/usb/dwc3/dwc3-st.c +++ b/drivers/usb/dwc3/dwc3-st.c @@ -266,7 +266,7 @@ static int st_dwc3_probe(struct platform_device *pdev) if (!child_pdev) { dev_err(dev, "failed to find dwc3 core device\n"); ret = -ENODEV; - goto err_node_put; + goto depopulate; } dwc3_data->dr_mode = usb_get_dr_mode(&child_pdev->dev); @@ -282,6 +282,7 @@ static int st_dwc3_probe(struct platform_device *pdev) ret = st_dwc3_drd_init(dwc3_data); if (ret) { dev_err(dev, "drd initialisation failed\n"); + of_platform_depopulate(dev); goto undo_softreset; } @@ -291,6 +292,8 @@ static int st_dwc3_probe(struct platform_device *pdev) platform_set_drvdata(pdev, dwc3_data); return 0; +depopulate: + of_platform_depopulate(dev); err_node_put: of_node_put(child); undo_softreset: