From patchwork Fri Mar 19 20:25:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 404825 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp1682775jai; Fri, 19 Mar 2021 13:27:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/8+Y5/EddURC0FMlnRsltkHR7DsKXA03on3EDg+6t2XfBx285xSKjVOLMdbJzMZYbyvMz X-Received: by 2002:a17:907:3d01:: with SMTP id gm1mr6577463ejc.214.1616185620374; Fri, 19 Mar 2021 13:27:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616185620; cv=none; d=google.com; s=arc-20160816; b=0vQBJNoo0CUXKMc3Y1qod4onKy809VD1k7rJGIvZC7qwXxuvT1gvwW615JtO9NkHgN tU6zwRe4xBQKSjbcufJ2Fuv8PIp+X4DvCjwp3yqWVE/L32HGZ1Gs37RxjmKdEMGe+2vo ktcLdDvkrg7qjcBAWYjyGrFbs7vKQmNCzAvq8SNi5UV/p5dz4kbcnck4A4KV1DP/y87p Um1KuiNSy4uqU9tHttIYNwmWMDkT0Rc+qRhDIRRaZk/X6g2jhRu/xNljgekOSre53R6P nOOr4FcBdC4fgQFvNiCdxtF2UqKT6XzTLqFYzclG1apblZZ0RA+TnZu7pVGfWPw7f8UZ sQHw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3m+0Blv5n7X4ghIz+zLSJn1A6/2kIt/8W8KDouftYUc=; b=FVxs9e7cpBWl8DKWX2t5dyOY+86AS7QzUNew+dO5lG7Xj1m9Zy1oowrQT6m34/bw+n ZSOdLSPukafbJ3aReywCOPB1MnrZ2VstUUplrJMCNwAj+c4Siqe26NOmALbY6HUv1CX8 C6q7q/nQQF8CQYrMjB8iVcVRBwMKySC4FMbuypCCfmIgtd1L+xi8YQxAUJ8lG7w6BDC3 RPFbIuRAF3Wz/arc7dxldWfXelMfxcStdW/36c5UFV8XqmUOFPJgdeKZIu7Yv2FwQmMu bDZxcDPyeKrW6lFkVy+yZ/kQZGTTffG5rDL2e4ymvlHRHQca+vpFsr+pvLP0d2zUC5Q0 hucA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nHtNjGrB; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si4549332edd.298.2021.03.19.13.27.00; Fri, 19 Mar 2021 13:27:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-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=@linaro.org header.s=google header.b=nHtNjGrB; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230186AbhCSU02 (ORCPT + 7 others); Fri, 19 Mar 2021 16:26:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbhCSUZ5 (ORCPT ); Fri, 19 Mar 2021 16:25:57 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97203C06175F for ; Fri, 19 Mar 2021 13:25:56 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id g20so6090804wmk.3 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=DGcN9w4rBXn7QDX8u8wBxme9DnHUjs1tI3p8jbYFUik98MUXaWIUN3RLUakBPVcTsu /G7uloqfNHP1gAj2EOa14htLEZQyR/D9iDZwyFXecj+UxMWXYj6gxUMcUUgxUocF9+VY hDar/Q6gn5izoPFUxAJyOe3dYTPAz24kvF7PjC98ZUgMIVWhy6SppHydGgPLGij5DbHs urhv7eGWKplCYX48/R9lBuKZYq3jIbLwhpTxNjc0zdBE0hZI1hLD4M+RrjPLydL+knQc ADTk9091COjVscrOef65HE/nRijZmFF9NkuE7y1pIjzejNoj3Kz/GLccPZOW6IfU78I0 qavg== X-Gm-Message-State: AOAM532ZKJWbCuoE38bx8K8U8vXk4hrKuQGzh7My+bMxCc6pHxlSn9tB 9+1qiHseqlvRVOV5A3JoVRBfvw== 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 Precedence: bulk List-ID: X-Mailing-List: linux-pm@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(-) -- 2.25.1 Acked-by: Viresh Kumar 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: