From patchwork Thu Jun 17 08:20:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 462129 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp219184jae; Thu, 17 Jun 2021 01:21:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuBSpZTgvkgj0ie2XeggHWEVDlHvYZpXJu1mDbIDUcd2gSbFlIZ7FlQmc/aHwf3qj+8LyS X-Received: by 2002:aa7:d3c2:: with SMTP id o2mr2868866edr.358.1623918085903; Thu, 17 Jun 2021 01:21:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623918085; cv=none; d=google.com; s=arc-20160816; b=YxsK++/CWKVNNIObaPUeUzuJOzwHqbfwQpbSbBXuK4jD8wYwDUuM+81tjguo5TWs8J XmjCwHsJtfp1VynVHQK8Z6RyJgxKguF/+HgB/J8d3pNs2a/dmZLJlJSgPS3Uxp4iOm/F nFbsBi6maaHnoxUZTBEbCxXCyNt+UwVj+IA/BHbe3sLgJdR3bTEFrRxVTGc+EgI/NaI2 M0AdSrXxMDOSTdqCqYPbvGiLY1JZUBqZJ17S+xvHqqUPYLlhFoS0g3OS8fgPp55xgsK4 pVKOiDQgz8QgXH9oSK3Q1UP5XlwnVcXmWar0nwpm0jDeciX1C66xfvIfpgV8YTFZGH+S Qufg== 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; bh=1KgPY83fx6ausfItvsAtJCkKzhywi26M/62sXZL9AbA=; b=eiZD0yK4aaI/nvmapGu8azkyqb0mPMD+Z0CmlhYWIx2lkLTv2yRUpJlNg63+aVAblP Pg4NFvvXEsGOX3GO/kEX+l6QJTcBNC6OqHXfnJvU+U90b1X47QFBmHCJXslumgK5/Lk9 vo38NSCVOLPpowwWxhvLPc9Qc6TELwRoK9HAIaEOuEad/UJVp0I3ZBOdADhRjkoO3zYi 217JVYVoke/kEjJ9hISWp4T4foKf5o1f7b0oLFF9ohr2pMGDl+t+eHNCaaBWzni1bdxB JgKgU9YWgccd4Mh+Gpbd/b0VJieo4NHF1rSE+of5rQshYadhFppWPiTaxU7Onz4AJA/3 pSCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hp35si5914689ejc.243.2021.06.17.01.21.25; Thu, 17 Jun 2021 01:21:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229915AbhFQIXb (ORCPT + 17 others); Thu, 17 Jun 2021 04:23:31 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:7347 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229842AbhFQIXb (ORCPT ); Thu, 17 Jun 2021 04:23:31 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4G5FKF2wzYz6vxm; Thu, 17 Jun 2021 16:17:21 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 17 Jun 2021 16:21:21 +0800 Received: from thunder-town.china.huawei.com (10.174.179.0) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 17 Jun 2021 16:21:21 +0800 From: Zhen Lei To: Andy Gross , Bjorn Andersson , Vinod Koul , linux-arm-msm , dmaengine , linux-kernel CC: Zhen Lei Subject: [PATCH 1/1] dmaengine: qcom: Fix possible memory leak Date: Thu, 17 Jun 2021 16:20:58 +0800 Message-ID: <20210617082058.955-1-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.174.179.0] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org When krealloc() fails to expand the memory and returns NULL, the original memory is not released. In addition, subsequent memcpy() operation will overwrite the entire valid memory space, so using krealloc() to preserve the old content is not necessary. Change to release the old memory and then apply for new memory. Fixes: 5d0c3533a19f ("dmaengine: qcom: Add GPI dma driver") Signed-off-by: Zhen Lei --- drivers/dma/qcom/gpi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.25.1 diff --git a/drivers/dma/qcom/gpi.c b/drivers/dma/qcom/gpi.c index 43ac3ab23d4c..e24fe64f3b63 100644 --- a/drivers/dma/qcom/gpi.c +++ b/drivers/dma/qcom/gpi.c @@ -1625,7 +1625,8 @@ gpi_peripheral_config(struct dma_chan *chan, struct dma_slave_config *config) if (!config->peripheral_config) return -EINVAL; - gchan->config = krealloc(gchan->config, config->peripheral_size, GFP_NOWAIT); + kfree(gchan->config); + gchan->config = kmalloc(config->peripheral_size, GFP_NOWAIT); if (!gchan->config) return -ENOMEM;