Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2507550rwd; Wed, 17 May 2023 10:36:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7gYWFT+/lBPvG7AgYJpO7MVsHpeJHaMNuH5FQRMxQzNrMgCf8WK5GDyXV6p6Rjpdh7q1Vq X-Received: by 2002:a17:903:234f:b0:1ae:bf5:7b5 with SMTP id c15-20020a170903234f00b001ae0bf507b5mr15790281plh.34.1684345013066; Wed, 17 May 2023 10:36:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684345013; cv=none; d=google.com; s=arc-20160816; b=JA31Z9Nrh7St8fyLSEsD2/2Lt/73wE12emBESswDMhIuKiQO9EQJYkUylDP6J5Gzkp oPzpc2JErT7BiaCO5Bd5/QEQVy+Cb2aInoYOr3sK0S8eWgCSCICrqyQ/folRQp1Xfm7a qfiJtKVfQAP00V0ltJmmHMXAzxyMYUT92EuYXvCBz/EUki7UI6+evS4DIw6o+Vl54RKk 21EpFROeZFGEFiKhsNjNIToUg8o9ugAsJCrgAEHv/xEb9v2H3gz69RDVV0qvr/xKrVE+ 5yvRrcqYxUV8DDNgt3kTLtj70Z823pUFg9mprxPBLDxQ0ZjNiqROTtuaMuQLYYx2H5wW TMaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=aom6zdq+nb9ytMsl0njXJSZ8hBFPWeXehVcz6nJqeBk=; b=KfZv8i8Ybe3FcuaglvEW6NvmJDFCpo7/TPluTsUhqvp8tjienfoAHKzGJU0HXfSkcP psruCZtqrtrP1Wpql7+b5fF8Y/0lV6zYK/wQ1pjaOW3C7t3ODnCrtnpypSAg3N1C0v8z ZNP72ukupNEXST8meyxnAbs4k+FKG/6NX8v89RB7zQKE4kKIc103NpY+q8xch7weOc8H ardyDVT42vw54DfDRQmEcVlBIFdOw/8yxGOTXjacry8MynQ+b3HqbADtvMSOMR8RJ1VS BExY/uJU8M1bjg2EMgx1SdFMSPaifJO/iUmorWevqcjxv3kmyA0SA1FZ/JsCo6WcuUA8 CFAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=b6ILUDy5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p13-20020a170902e74d00b001ab233bb792si10592142plf.441.2023.05.17.10.36.40; Wed, 17 May 2023 10:36:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=b6ILUDy5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229815AbjEQR0d (ORCPT + 99 others); Wed, 17 May 2023 13:26:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229805AbjEQR01 (ORCPT ); Wed, 17 May 2023 13:26:27 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06B57A5C7; Wed, 17 May 2023 10:26:02 -0700 (PDT) Received: from vefanov-Precision-3650-Tower.intra.ispras.ru (unknown [10.10.2.69]) by mail.ispras.ru (Postfix) with ESMTPSA id 6BEC340755CE; Wed, 17 May 2023 17:25:48 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 6BEC340755CE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1684344348; bh=aom6zdq+nb9ytMsl0njXJSZ8hBFPWeXehVcz6nJqeBk=; h=From:To:Cc:Subject:Date:From; b=b6ILUDy5tVtHTiedTk1ynvQrY53mc9N/+34FAKpQgbEZww0c6FcikJ+m0yEIdaCAW CZhTx7KZzFBxzx1/O8c9gY5QAVR4r1EpwHL9RAzFidYLln9RXaLsIA7n+p52qIpro1 FPNSvFn10XGwsFP4n+k2Rx4308mm5lJyg/GwGOeE= From: Vladislav Efanov To: Andy Gross Cc: Vladislav Efanov , Bjorn Andersson , Konrad Dybcio , Thinh Nguyen , Greg Kroah-Hartman , Shawn Guo , linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH] usb: dwc3: qcom: Fix potential memory leak Date: Wed, 17 May 2023 20:25:18 +0300 Message-Id: <20230517172518.442591-1-VEfanov@ispras.ru> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Function dwc3_qcom_probe() allocates memory for resource structure which is pointed by parent_res pointer. This memory is not freed. This leads to memory leak. Use stack memory to prevent memory leak. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 2bc02355f8ba ("usb: dwc3: qcom: Add support for booting with ACPI") Signed-off-by: Vladislav Efanov --- drivers/usb/dwc3/dwc3-qcom.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 959fc925ca7c..f52241883694 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -791,6 +791,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct dwc3_qcom *qcom; struct resource *res, *parent_res = NULL; + struct resource local_res; int ret, i; bool ignore_pipe_clk; bool wakeup_source; @@ -842,9 +843,8 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (np) { parent_res = res; } else { - parent_res = kmemdup(res, sizeof(struct resource), GFP_KERNEL); - if (!parent_res) - return -ENOMEM; + memcpy(&local_res, res, sizeof(struct resource)); + parent_res = &local_res; parent_res->start = res->start + qcom->acpi_pdata->qscratch_base_offset; -- 2.34.1