Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3680921pxf; Mon, 22 Mar 2021 12:15:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxby1uK0NgPkn4atgZ1HVwwSqbAktSR9Ln46xaEZwt39zALShAomEzvvINnIt5LPHmYtynh X-Received: by 2002:aa7:cb0a:: with SMTP id s10mr1185256edt.36.1616440536373; Mon, 22 Mar 2021 12:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616440536; cv=none; d=google.com; s=arc-20160816; b=yuD0gqATEf08nYf+bEgmD03/L55C1BPMRVzsafdbtEZrSTpWRoeJFw+yH40IHcP9+s Mq/XaqRuTEqWIemykmtnZF82cJaY+Vu2L95twEIbgi/NBb2fAP1f93DOamMlbSMaITSc 6LbhwATotM/PzqQ2jpS0Ge92d/HuxxWMznXsTKw0tkjUd0BPiLCWWQQfzuYXu5Lb60nS BKUuf/M4p4238aHkPkxKxq1oFjOL7rqKZSfzP7InotcJKqjltrs0W6W1FePfiS5BKCLQ sYpDmo7K4c4Vp8spmp7ohglwWCGjM8V4CP3HQxLj5CAKVAgxS2LJIqSIBuEvkfowQiON rJjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=1UQ+ySphikPYmcOREZJMTjlDDCrOsVCHxDYLzztStg0=; b=av81Rlaf1jzCJw2YmaM78vfAj9jae6q1lNIkHSBYSO/Hgi7hfyl1HQRKuNEpfC6N6J e3v/FuBAY8FE/WiSx4YNJLtYEBoNk3JIE9tn2QzMDFEX3ATmMtEgbiUfcieNix2LtHHV pv6JW1no8+XnHpf+s0Mbk8TobfjtGrjZX24qRaTtEPnG6eKosPaoXxoz1VGsD+gbt40C 4yryymXj2lBxNIRIfw2vCRm6fZcyfzI1FK2Momo2J8ibINsa59jjSRNeU4wBVb9vFwu1 DlUEOcOJpcTYoW+VTOw6uVrS5M/7BQV3nLJKmDa2TA0lzmqNB3QpePKYMsXn0p/jpUC0 tDFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hjnBZ4WC; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f6si11599369edq.600.2021.03.22.12.15.13; Mon, 22 Mar 2021 12:15:36 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hjnBZ4WC; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231912AbhCVTM1 (ORCPT + 99 others); Mon, 22 Mar 2021 15:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232071AbhCVTMM (ORCPT ); Mon, 22 Mar 2021 15:12:12 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 352FDC061574; Mon, 22 Mar 2021 12:12:12 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id e18so18350578wrt.6; Mon, 22 Mar 2021 12:12:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=1UQ+ySphikPYmcOREZJMTjlDDCrOsVCHxDYLzztStg0=; b=hjnBZ4WCrjOg8NJVDbytAmHGUcSedlPsR0mtIBVSbhg58CRvPqkxgW1T94fjLTEzms 6pMuge+Xyvjmn3ir/XkMzb1XswBPSbiM0hQxXa6a6qiTNSHTGvkpSGl80NG8OcuEiF65 91M9CW5bqrN6H90JpyCHjldMhd4LtvvI8lOvao6jXADDm7vVyZOC88lU+VMYRf3cllTL UAMfbhyxrkhjGKo6teeLe36+TFMy5W2qe4BWnpWISCqs/dRwrHEUZ8NFezgAtLecOPfZ lVss4xenHdHJOyOTaJwpOFPWIr74azYnR13j/45r5ALlSTSwZChttRRN69P4HWgwMwYZ BS+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=1UQ+ySphikPYmcOREZJMTjlDDCrOsVCHxDYLzztStg0=; b=jIwbeQyLKqEFF4FDze3nktq9PEQYLKS1nrD0/oxWdNAQbbdVLxYJB0ZL1vXv6gwlDd bvPXa0W229gl7527CgJpp0O7zBza1BFlJDS+/IVha6F5hoNOLDG+o08acw13eGJ96QBs qrC7a5Ocn18+pKjnThjDmS0zd3nZitG4wNPlX7Xs0KcUrFxXDpsC9UVDB4pS9ZRlLpfv Aeh2slkUY6WuawGr3c8Nc/nvEkO+fc53Uol0YzJGdCYBLeHsH81d/LShc7KXM4HDizqf E+b2gUVmiLOOkXsGkQGhw11avc/nOQrHI1VI4P02bdpRf5nekUHQJlSqf7moQToc+CMA 2BAg== X-Gm-Message-State: AOAM531vg/KjTqI5S08N8sjXhpbPZhB0kNkmkL95qySTcwFFKR4F+7Lj gWBkuRjwEbUQmZU6BaHCCho= X-Received: by 2002:a5d:6103:: with SMTP id v3mr38000wrt.375.1616440331027; Mon, 22 Mar 2021 12:12:11 -0700 (PDT) Received: from LEGION ([111.119.187.31]) by smtp.gmail.com with ESMTPSA id c16sm25151135wrs.81.2021.03.22.12.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 12:12:10 -0700 (PDT) Date: Tue, 23 Mar 2021 00:12:04 +0500 From: Muhammad Usama Anjum To: Zhang Rui , Daniel Lezcano , Amit Kucheria Cc: musamaanjum@gmail.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, colin.king@canonical.com, dan.carpenter@oracle.com Subject: [PATCH] thermal/core: avoid memory leak Message-ID: <20210322191204.GA2122573@LEGION> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When memory allocation for cdev is successful but ida_simple_get fails, branch to out_kfree_cdev label happens and cdev isn't freed. There are other some other branches in which the memory can leaked. Fix it by freeing cdev. Signed-off-by: Muhammad Usama Anjum --- 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 c8d4010940ef..3566fd291399 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1017,6 +1017,7 @@ __thermal_cooling_device_register(struct device_node *np, out_ida_remove: ida_simple_remove(&thermal_cdev_ida, cdev->id); out_kfree_cdev: + kfree(cdev); return ERR_PTR(ret); } -- 2.25.1