From patchwork Mon Aug 19 07:24:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishka Dasgupta X-Patchwork-Id: 11100379 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 11F3818A6 for ; Mon, 19 Aug 2019 07:24:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7BAF2847F for ; Mon, 19 Aug 2019 07:24:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D940228590; Mon, 19 Aug 2019 07:24:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 891532847F for ; Mon, 19 Aug 2019 07:24:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=kKq05Mz77+Xlst3b3JSzYOb7F38gBv3YnEuPuj+Os74=; b=RAzQtxxUCqhLbr f4J+Lm6EV7AVjl0F7Ij1PqPBe/a1xu0FmYvLc+RUkz5PJ0dAZQPjzlypMLDo5aV1KuYf6FVhGfa9d 2F40QJjHafpHJL4LlgtxzuRRQognIRNJuNfGUvkAyv/dmEzBgBn5dhwqJlaYv1BV+LX3vu3q0oXpA VAepwC16Kq+/tYTmLOKFoRpRP4Ufu1fP9tonfUcfJ16ftV4u6qek+KJiViHTJFyWKd19eeUCEZWz7 oOODZLRW2v8nWUbdWk2v4ovbDPbl/yEhIV52bvufqx6W/X6ZkqMmQF3VYtASOnq7MdfMqgSVY0Glu PQV09VVZuOJyMf9kA0Hw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hzc28-0003Tu-5d; Mon, 19 Aug 2019 07:24:52 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hzc25-0003TT-F4 for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2019 07:24:50 +0000 Received: by mail-pf1-x441.google.com with SMTP id i30so647335pfk.9 for ; Mon, 19 Aug 2019 00:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8sEiIl57BH1UnpigrfcmtcS/+u7ss59hzQTNXNLQX8k=; b=ebNrBQTm89VrGyszHKb0JXq4atLLs2dVkzh284BbuHTOS6x539wBM0oFTauKN80T5K 6Dvd22LJ9BaGdROHkLWhXwgsVl/gZXL+4F/869QVCdSnng7W0WAXktMDUQlmCT+TPUx7 IO/4QNdZe8PJslVc3xCy/DNY9dLCZz9AIBI6s6lelsAmuLC9yeDt8KShhkvI6Qic0Q4h TnotgpExho7SKRtl2cflg9LXG/IE31mrSQQXMmWfbfPyRp9vymiuoT9C/at/F40qPTrB QRzeQRA0D12TjSobRVRuw6EXbXJdF/Fk1fI33vRxJX0bciQ/0iv43UfcUz3/PAXeLq0M hPFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8sEiIl57BH1UnpigrfcmtcS/+u7ss59hzQTNXNLQX8k=; b=I8OdP5xnvLPWwNs6T9JQgURDMznO2cQmfzOyq4fLp1f9qkzW4ESVBX0G4zGlCYd5tl EpQn8XwicSxPLJ7HP1zpZAoNB+CDagaXK4ONCevlvD2nPgGOFC3XACn8c1cdBCSNfV8h xIXA7pQfNwFO/Ku5T6PacWY+ZvtgCtC9jJUNScbFefpoxc2QlW1TroITjNEbrrCWIiWx K0hq4MLRP5C9D22B/9sJ2FmPI0Q/7yzUGYZMxm351AZBXabmlJmf5PRl48yeluwBH8t0 06o8tNh3eD1/uj8LXHX0U835G2Lp59wYJFHltrUdEFHvx7/WuXEqU5fhO7yG+CRutWsp hI6g== X-Gm-Message-State: APjAAAUiwQLRC9uEmCbz8aHvbGJ++3yP1DxSIgDgPfEYufi8lrks1qiF JMaGD2EaUeWYEce19+ngn0Rp18pf X-Google-Smtp-Source: APXvYqwdNNKfTGcPy3tFR86j9Kv69o3x6r+CjS+JP9c9oRwhwoUTd+0ke6YkZ7cfR8UGQOQ+gm/94Q== X-Received: by 2002:a62:db86:: with SMTP id f128mr22257886pfg.159.1566199488833; Mon, 19 Aug 2019 00:24:48 -0700 (PDT) Received: from localhost.localdomain ([110.225.16.165]) by smtp.gmail.com with ESMTPSA id u3sm11064496pjn.5.2019.08.19.00.24.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 00:24:48 -0700 (PDT) From: Nishka Dasgupta To: patrice.chotard@st.com, balbi@kernel.org, gregkh@linuxfoundation.org, linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org Subject: [PATCH 1/2] usb: dwc3: st: Add of_node_put() before return in probe function Date: Mon, 19 Aug 2019 12:54:35 +0530 Message-Id: <20190819072436.31402-1-nishkadg.linux@gmail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190819_002449_508100_F69EE22B X-CRM114-Status: GOOD ( 13.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nishka Dasgupta Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The local variable child in the function st_dwc3_probe takes the return value of of_get_child_by_name, which gets a node and does not put it. If the function returns without releasing child, this could cause a memory error. Hence put child as soon as there is no more use for it. Also create a new label, err_node_put, just before label undo_softreset; so that err_node_put puts child. In between initialisation of child and its first put, modify all statements that go to undo_softreset to now go to err_node_put instead, from where they can fall through to undo_softreset. Issue found with Coccinelle. Signed-off-by: Nishka Dasgupta Reviewed-by: Patrice Chotard --- drivers/usb/dwc3/dwc3-st.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c index 16081383c401..6f52c749cd58 100644 --- a/drivers/usb/dwc3/dwc3-st.c +++ b/drivers/usb/dwc3/dwc3-st.c @@ -255,24 +255,25 @@ static int st_dwc3_probe(struct platform_device *pdev) if (!child) { dev_err(&pdev->dev, "failed to find dwc3 core node\n"); ret = -ENODEV; - goto undo_softreset; + goto err_node_put; } /* Allocate and initialize the core */ ret = of_platform_populate(node, NULL, NULL, dev); if (ret) { dev_err(dev, "failed to add dwc3 core\n"); - goto undo_softreset; + goto err_node_put; } child_pdev = of_find_device_by_node(child); if (!child_pdev) { dev_err(dev, "failed to find dwc3 core device\n"); ret = -ENODEV; - goto undo_softreset; + goto err_node_put; } dwc3_data->dr_mode = usb_get_dr_mode(&child_pdev->dev); + of_node_put(child); /* * Configure the USB port as device or host according to the static @@ -292,6 +293,8 @@ static int st_dwc3_probe(struct platform_device *pdev) platform_set_drvdata(pdev, dwc3_data); return 0; +err_node_put: + of_node_put(child); undo_softreset: reset_control_assert(dwc3_data->rstc_rst); undo_powerdown: From patchwork Mon Aug 19 07:24:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishka Dasgupta X-Patchwork-Id: 11100381 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 914D2912 for ; Mon, 19 Aug 2019 07:25:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77AE928555 for ; Mon, 19 Aug 2019 07:25:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B455285A0; Mon, 19 Aug 2019 07:25:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0A35A28555 for ; Mon, 19 Aug 2019 07:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+PFKy4RpgvVKCTBUK0ZTjCQVBm/ttQ47RdQc8g9XA2s=; b=nykPCFsbqErqy8 FNQJD5+LTEhI8HIP6d0oqZmNbj8AtPrcI6GgnlJ71lAzVtlc88hK1677tpQLgk6RHZtTFUJI/4zSC 6Fy5FKFCh3kblmv634VxxVmxAcVoarsaPwQNZUNbUZ5/d39XVug2j2XS6IUt4mFDRn8MneRKHZvjs M3JOupi8wpuH58flXf0YV3rEUqALC6FEnKKtF9cOgGp7dOVPeHUhMw2HHX0IhSrMew3vnCdwH1HjZ QDOB5MYQtQKXL5JdHmTbSFN/7a2XXD8YsjyJ0gyvI8KGKr10LFlw/C5cl/DBzMdYFYsaDnMKOY1Qz TbS9/8Ndej2q833mMoSQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hzc2N-00042T-6x; Mon, 19 Aug 2019 07:25:07 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hzc28-0003Tw-G3 for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2019 07:24:53 +0000 Received: by mail-pl1-x644.google.com with SMTP id bj8so544548plb.4 for ; Mon, 19 Aug 2019 00:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n7dhYlMl//z73eacQGweSKumEFWSfBEWN+KSfFfbHHI=; b=VhH0eiPmWx5SbrmRmNTyZ+Byd8qqhGRd/QLUrNsVw6eRyDNWa+PPfBCxG5EhP/0ynJ 06rckRpaLN+OBrdr17FJqWlf74d3miggbogYkxalARhmPPAnLNiPN8BSwL6xkYEepv7g GpNCZ6z+XA2EOtXNefssS04Z6XGDZtd3ttD8uEoHa361laIzlxvH/5QOkCdmFZ+r7jfT BiyEvst69I+yNbVOsUjpdckeQuirWzcAn+Jlz6p0dZQbTPEHCDOjedc3JL80sBRApbf4 o7AfVwMw1MWqnC4w4hoqimp6G+htJPqhk9uPzn0+XEHx7LZW20thLbmV7uWAGsQmjGzt KvVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n7dhYlMl//z73eacQGweSKumEFWSfBEWN+KSfFfbHHI=; b=WffioKINFDYxLBJZ5Oh0VRxC3a7nrGN60ABsYAzdGLcHaUFy/P6QbrLrK0yYQTzj2n KTuS5u8jIwGwwsHcx3lBrE1MbFw0m+mpI+m0h1ttHCqa/y0tQNsYXYsI8TxakZH7DNvd I4eJ+yHN9UN+G7RqFLKpMMeX7D/WiA5Ga3eiTxONB4mqS3gOq0IatvXKXFsQPWmq7Sg5 yPwadoDVbcfr5JjTZatUlkgpjF9blJLeTrxE31rLiWOE3Y7M0ejPiNNODs6SLALKNzLB VkjtQg8f3b2zkqGoae9ffCxHIpyiQ1XQJGXnxL4XhVHqVAOzsZ8jrvr6eDi86my02Cas ZVQQ== X-Gm-Message-State: APjAAAWEqXi/murpiQjgi9S4/OFi6JZ4wJ1WGyLRIKW34+pt9fy4hXna hy5dh1SyGUOJwF1f8wRrDtU= X-Google-Smtp-Source: APXvYqyoWxQlwcpntJ672OeWe7rLF7xYFp0iacILMOmsGwKthmm0U3ynEBTnbdeuQjHC50gFN+IIrw== X-Received: by 2002:a17:902:29eb:: with SMTP id h98mr21709529plb.128.1566199491894; Mon, 19 Aug 2019 00:24:51 -0700 (PDT) Received: from localhost.localdomain ([110.225.16.165]) by smtp.gmail.com with ESMTPSA id u3sm11064496pjn.5.2019.08.19.00.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 00:24:51 -0700 (PDT) From: Nishka Dasgupta To: patrice.chotard@st.com, balbi@kernel.org, gregkh@linuxfoundation.org, linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org Subject: [PATCH 2/2] usb: dwc3: st: Add of_dev_put() in probe function Date: Mon, 19 Aug 2019 12:54:36 +0530 Message-Id: <20190819072436.31402-2-nishkadg.linux@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190819072436.31402-1-nishkadg.linux@gmail.com> References: <20190819072436.31402-1-nishkadg.linux@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190819_002452_567628_89D25146 X-CRM114-Status: GOOD ( 11.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nishka Dasgupta Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In function st_dwc3_probe, variable child_pdev takes the value returned by of_find_device_by_node, which gets a device pointer but does not put it. If child_pdev is not put before the probe function returns, it may cause a reference leak. Hence put child_pdev after its last usage. Issue found with Coccinelle. Signed-off-by: Nishka Dasgupta Reviewed-by: Patrice Chotard --- drivers/usb/dwc3/dwc3-st.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c index 6f52c749cd58..c682420f25ca 100644 --- a/drivers/usb/dwc3/dwc3-st.c +++ b/drivers/usb/dwc3/dwc3-st.c @@ -274,6 +274,7 @@ static int st_dwc3_probe(struct platform_device *pdev) dwc3_data->dr_mode = usb_get_dr_mode(&child_pdev->dev); of_node_put(child); + of_dev_put(child_pdev); /* * Configure the USB port as device or host according to the static