Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp200406ybg; Thu, 11 Jun 2020 22:08:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwERlGynZ9kaNW3T61p0/NC3m5kOY8dQIh0ToX2OELZWklRQuQFQADKI0Kmjc30i5Xl7tUe X-Received: by 2002:a50:c359:: with SMTP id q25mr10340985edb.123.1591938534781; Thu, 11 Jun 2020 22:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591938534; cv=none; d=google.com; s=arc-20160816; b=RgLAzAlvq7s1aHMa0SDFLVr0HsD4N8kaMOmO3On/8Y4c3crr44EKiS3GRP9XH/LCL/ fTrkzvYVX0Sk6QhZzI8IcMwORUrU9qtv3GpvOsiKG0KBIvJA0jhQ/WNcvmmH0VnmAhuF HNgmDSnsP43gstcKow+Zf2hv1iFCaJzv4u7/plvmlagR1MeTkM+QPUCqrslkfpwkaROr Yb58ZcQ0UnuNKF6fJDU+s9gAbazKqEt/e8i+bhpWn6CCiFfvyr034G2fV4RtEFKXLzth oTB6GuIoesi1FYY2upZez1TbpNnKWwQQM/UShJMHkLfNm3gOvVYS11cj/DxfjyCMqY7U 1BJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=QXh4aIU/IcakXcqXkwOQ1KmFhVM6qkBwRT2rQBSIlcM=; b=UIeG2xXahuwRgH8GZDJx37N694I72iDQ48c4Hb1VPpEQwadvQj0/g2GPGsqsoakaZZ NN32kkfM9rZ87AjMbAQ1zyfMDl3vzrq5/BZ/KdzOljQ2uiCYxLojW7DUDVQ4J9Be46Aq zyjnBQ/c9h6nLStr/1m4n9neziVDOtpAS+xHJ9TRk240gL2GWGqUE7xxI1bHDodxMRKN YSxEX2ouoY4s7DD7f1Vg1L5saZMjGxZpJIt6B5iJTCSUoneYTNGN5mP9TMmzwTmlIqXm wJNiaogSY03awY5guU2mrp6mY5Jy2/w5hUikDmH/4xlf9i8gqBNILjTjVQi2cijfRoYw M+uQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d18si2706638edv.51.2020.06.11.22.08.32; Thu, 11 Jun 2020 22:08:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726361AbgFLFGn (ORCPT + 99 others); Fri, 12 Jun 2020 01:06:43 -0400 Received: from m17617.mail.qiye.163.com ([59.111.176.17]:60604 "EHLO m17617.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725858AbgFLFGn (ORCPT ); Fri, 12 Jun 2020 01:06:43 -0400 Received: from njvxl5505.vivo.xyz (unknown [157.0.31.125]) by m17617.mail.qiye.163.com (Hmail) with ESMTPA id D641E2614DE; Fri, 12 Jun 2020 13:06:39 +0800 (CST) From: Bernard Zhao To: Rob Clark , Sean Paul , David Airlie , Daniel Vetter , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com, Bernard Zhao Subject: [PATCH] drm/msm: fix potential memleak issue Date: Fri, 12 Jun 2020 13:06:32 +0800 Message-Id: <20200612050633.3441-1-bernard@vivo.com> X-Mailer: git-send-email 2.17.1 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgYFAkeWUFZS1VLWVdZKFlBSE83V1ktWUFJV1kPCR oVCBIfWUFZSUIfT0tKHR4ZSUhCVkpOQkpCSENPS0tLSEhVEwETFhoSFyQUDg9ZV1kWGg8SFR0UWU FZT0tIVUpKS0hKTFVKS0tZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6MBg6Ghw*Tzg2GQszOC0WNjA3 PToKCh1VSlVKTkJKQkhDT0tLT01CVTMWGhIXVRkeCRUaCR87DRINFFUYFBZFWVdZEgtZQVlKTkxV S1VISlVKSU5ZV1kIAVlBSUtKQzcG X-HM-Tid: 0a72a6ec3f229375kuwsd641e2614de Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Function msm_gpu_crashstate_capture maybe called for several times, and then the state->bos is a potential memleak. Also the state->pos maybe alloc failed, but now without any handle. This change is to fix some potential memleak and add error handle when alloc failed. Signed-off-by: Bernard Zhao --- drivers/gpu/drm/msm/msm_gpu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c index a22d30622306..d67a9933f3ce 100644 --- a/drivers/gpu/drm/msm/msm_gpu.c +++ b/drivers/gpu/drm/msm/msm_gpu.c @@ -366,8 +366,11 @@ static void msm_gpu_crashstate_capture(struct msm_gpu *gpu, if (!should_dump(submit, submit->cmd[i].idx)) nr++; + kfree(state->bos); state->bos = kcalloc(nr, sizeof(struct msm_gpu_state_bo), GFP_KERNEL); + if (!state->bos) + return; for (i = 0; i < submit->nr_bos; i++) { if (should_dump(submit, i)) { -- 2.17.1