From patchwork Mon Nov 2 02:11:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernard Zhao X-Patchwork-Id: 11872833 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3E741130 for ; Mon, 2 Nov 2020 02:12:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADE5C2225B for ; Mon, 2 Nov 2020 02:12:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727450AbgKBCMA (ORCPT ); Sun, 1 Nov 2020 21:12:00 -0500 Received: from mail-m17613.qiye.163.com ([59.111.176.13]:7021 "EHLO mail-m17613.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727445AbgKBCMA (ORCPT ); Sun, 1 Nov 2020 21:12:00 -0500 Received: from ubuntu.localdomain (unknown [58.213.83.157]) by mail-m17613.qiye.163.com (Hmail) with ESMTPA id CE486482B20; Mon, 2 Nov 2020 10:11:57 +0800 (CST) From: Bernard Zhao To: Zhang Rui , Daniel Lezcano , Amit Kucheria , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com, Bernard Zhao Subject: [PATCH] drivers/thermal: fix potential memleak in error branch Date: Sun, 1 Nov 2020 18:11:48 -0800 Message-Id: <20201102021149.3047-1-bernard@vivo.com> X-Mailer: git-send-email 2.29.0 MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZS1VLWVdZKFlBSE83V1ktWUFJV1kPCR oVCBIfWUFZSBoYSU8YTR9LGUwYVkpNS09JQ0hKSkNLSEpVEwETFhoSFyQUDg9ZV1kWGg8SFR0UWU FZT0tIVUpKS0hKQ1VLWQY+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Ky46Kww*Cz8pHSEPLR0UAjID LywwCUlVSlVKTUtPSUNISkpDT0xCVTMWGhIXVRkeCRUaCR87DRINFFUYFBZFWVdZEgtZQVlOQ1VJ SkhVQ0hVSk5MWVdZCAFZQUpNQ0g3Bg++ X-HM-Tid: 0a7586b9b19593bakuwsce486482b20 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Function __thermal_cooling_device_register, when device_register failed, cdev is not free after error value return, this may bring in potential memleak. Signed-off-by: Bernard Zhao --- drivers/thermal/thermal_core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 3d1e0033bf3e..e4bee15dfa1f 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1125,6 +1125,7 @@ __thermal_cooling_device_register(struct device_node *np, if (result) { ida_simple_remove(&thermal_cdev_ida, cdev->id); put_device(&cdev->device); + kfree(cdev); return ERR_PTR(result); }