From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB3B8C433E2 for ; Fri, 19 Mar 2021 20:27:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 95A6661979 for ; Fri, 19 Mar 2021 20:27:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230419AbhCSU0a (ORCPT ); Fri, 19 Mar 2021 16:26:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230370AbhCSUZ5 (ORCPT ); Fri, 19 Mar 2021 16:25:57 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97C34C061760 for ; Fri, 19 Mar 2021 13:25:56 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id p19so6094686wmq.1 for ; Fri, 19 Mar 2021 13:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3m+0Blv5n7X4ghIz+zLSJn1A6/2kIt/8W8KDouftYUc=; b=nHtNjGrBJ98tS3ihrmTi9ZAEa1r1iIXPxVr2j+IakZ0huLcoROkDP5fFocCnzzcB66 hD1z7cDwSAO+XRTUttmUuUIQgJtLnez6T8EBRL9k12z3xkHU8dVWe1WKNssTPhQI1tW9 ZXiW/1mW2eqbOIIHluPsSoXIJSDn2rY0MBYUb1fLrg+yjWYbnTLaDpZsX/SCTdsMYvoH mN84hRqlYar39ex6/WuwbCxzJd5TrgI50iRYWKS0O7UrIt5ey7XRy9G53VdhMMoH/65U wQzsmVifk8F8dGJrzct1GVKmruTV9RAQ2FXQ1MImsMuicusn/SxM6aD6j1chOLYXySar SGLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3m+0Blv5n7X4ghIz+zLSJn1A6/2kIt/8W8KDouftYUc=; b=RCG90kb7NFB1tmVQ7Gqwog/e3N8TZv+7OUpM9AkluWWaWmLnvAGJ3MwOfJr0vU7DGE qFRSKWS/T5b/lF5kXLbNaf7C8RRAjt5MkO0XSLNQ118px7DkF7wqmZbJNTfw9hYN9tVY dHYWRAfZDy0Y3ioEKvd9DARWb3XiukNUlmrjmtn1aUj85gTmCtqv/69PoxdsUFutydBd G9/Iz/zbAG6z+oAQvxCrRyA3NNHc6SPoBSiwnw4I39D42/jnj1kE372oLliUS1sQaIER E9fThF+PMGduxpqQvUBS9PMFf/yCzalryU5v+ClnHSyA7Ccbik2j0v5UQV+Go++0EzPX GKyg== X-Gm-Message-State: AOAM531OHqx5HuyOyPnbTv5lfi85IrVoyRvh+B/qA4j/xQGIR/g6Fnf3 lKQjGs8kkmmoErFBGPsG/Glh37iA+YIBRg== X-Google-Smtp-Source: ABdhPJwZVp9QR1LumiiDbaPviiatvDCtefwYNSLA8em3zS8VOaPMNamxa8FzEra86SSF55L+Jy+4xw== X-Received: by 2002:a1c:f701:: with SMTP id v1mr3194099wmh.69.1616185555197; Fri, 19 Mar 2021 13:25:55 -0700 (PDT) Received: from mai.imgcgcw.net ([2a01:e34:ed2f:f020:ddd7:1eb:a66:7a85]) by smtp.gmail.com with ESMTPSA id b17sm9423638wrt.17.2021.03.19.13.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 13:25:54 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org Cc: Dan Carpenter , Amit Daniel Kachhap , Viresh Kumar , Javi Merino , Zhang Rui , Amit Kucheria , linux-pm@vger.kernel.org (open list:THERMAL/CPU_COOLING), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] thermal/drivers/cpuidle_cooling: Fix use after error Date: Fri, 19 Mar 2021 21:25:22 +0100 Message-Id: <20210319202522.891061-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the function successfully finishes it logs an information about the registration of the cooling device and use its name to build the message. Unfortunately it was freed right before: drivers/thermal/cpuidle_cooling.c:218 __cpuidle_cooling_register() warn: 'name' was already freed. Fix this by freeing after the message happened. Fixes: 6fd1b186d900 ("thermal/drivers/cpuidle_cooling: Use device name instead of auto-numbering") Reported-by: Dan Carpenter Signed-off-by: Daniel Lezcano --- drivers/thermal/cpuidle_cooling.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/cpuidle_cooling.c b/drivers/thermal/cpuidle_cooling.c index f32976163bad..4f41102e8b16 100644 --- a/drivers/thermal/cpuidle_cooling.c +++ b/drivers/thermal/cpuidle_cooling.c @@ -208,18 +208,20 @@ static int __cpuidle_cooling_register(struct device_node *np, cdev = thermal_of_cooling_device_register(np, name, idle_cdev, &cpuidle_cooling_ops); - kfree(name); - if (IS_ERR(cdev)) { ret = PTR_ERR(cdev); - goto out_unregister; + goto out_kfree_name; } pr_debug("%s: Idle injection set with idle duration=%u, latency=%u\n", name, idle_duration_us, latency_us); + kfree(name); + return 0; +out_kfree_name: + kfree(name); out_unregister: idle_inject_unregister(ii_dev); out_kfree: -- 2.25.1