Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp3881352ioa; Tue, 26 Apr 2022 11:34:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymPnfJbrixTHPU2honfAo4+1HxAdbCTF9DtjpDBLAX8rbh3sruTgNayfN8jyWqaVOj18+e X-Received: by 2002:a17:907:97cc:b0:6da:a8fb:d1db with SMTP id js12-20020a17090797cc00b006daa8fbd1dbmr22840103ejc.267.1650998077116; Tue, 26 Apr 2022 11:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650998077; cv=none; d=google.com; s=arc-20160816; b=0/lkq53+Iv4hKXlBB9yX/Rjr3u2JKUI+8Bp/uvdMJr6X6f1+O7wCvoXA3j7PnRVl5s VNm5ozuKYMxAfpt3pRdV7aGxNekgYBuzBMNACUnZujZG/9YmNYyVt/zo/nCvVU1GeKy/ wvf6VVcyBX3sSPSN4aIfFFjAzS87rMfPG4cIbaju4s+aUuMvEQqJyRzK/rZ959QHZcoZ 7RSSDFSvjL+vZ/r2DcfnHIjyR1nTI3WoWLQJxkI+8aBIy8tsG6yLCmV533S+uVmQQAFF KUMXmukrYv1hjlTVil47TBzeoJWGtDzk/pUkGdRF5trnX7LP3iNltp4I9pwt/ubWImci 4h4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=l14tyZSgzLXN2UoucRkpEODvdBocs6Ls5dwsVMC/3kA=; b=xDs+T6oHlwc1m6yBMEfc8aXUOzHZHJn4lFrjJ231sLiN2eSHdo8rYCV9XPXNdwV5Jv feucofdbxz/kyMkAherlCTKY8DcZ0u3Cbcl7vjuPiaoNbDQLtmLhbk47RbE2pZRfkO+v Trswpwba6PqsZwx/MM52Rxjvl0aMw6GldxdwdUJ19uxM/+OKIRzSi2chL55SXAwpByJU mUBM1KoV9jpgsMddGKtCfaQ/EMxej5A1JOADRzkisAK+WvbJI6KPyhkJPVnOksQGvZdk PgvrS/+55jhO7rNGlec3d+OEqYajs6FiQ78rzHfIOMabtPWFHdsb+w19mzQGWyw+/FnD b0xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kk55sE6m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb25-20020a1709070f9900b006f3a147c665si4370195ejc.635.2022.04.26.11.34.13; Tue, 26 Apr 2022 11:34:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kk55sE6m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348498AbiDZNmn (ORCPT + 99 others); Tue, 26 Apr 2022 09:42:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239468AbiDZNml (ORCPT ); Tue, 26 Apr 2022 09:42:41 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09A2A66AE6; Tue, 26 Apr 2022 06:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650980374; x=1682516374; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=7fuoHjFYh58bCMLDeH91TfTPQ3w0G2M79t/dH46cWVM=; b=kk55sE6m9ngH5zhZlN111jJef38ZLzfv5FlpLa3wXk/eaTmdeWxfHChL xQUTRX38IL78SDBiIZ9xIZ3QXUhSV6LL7I9IkNWmqPdt1J0wGRaKCrPaY Uh9aBFJEIpotgaWJcKgG0bRBd55X2qcPpX8ijPagbESMlI/uXpF3B7huC dpExB89eB1unPmgwo0xbk4vZYlCad05KFFgACmT6PJoHcExEVN/IUmiF/ xGei0lYlG/hP2fxwmZquqiS9JqtTBmDxAc3jQLT/Y/U1PLJNIdX61PyBA XrCZfxxP5tEc1jkYH23m9hjGJnyCYiZyt0bGbnySP0IcME9mDXYriRThK w==; X-IronPort-AV: E=McAfee;i="6400,9594,10328"; a="252955802" X-IronPort-AV: E=Sophos;i="5.90,291,1643702400"; d="scan'208";a="252955802" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 06:39:33 -0700 X-IronPort-AV: E=Sophos;i="5.90,290,1643702400"; d="scan'208";a="579898754" Received: from dongyiyu-mobl1.ccr.corp.intel.com (HELO chenyu5-mobl1) ([10.249.173.93]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 06:39:30 -0700 Date: Tue, 26 Apr 2022 21:39:26 +0800 From: Chen Yu To: Colin Ian King Cc: Len Brown , linux-pm@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tools/power turbostat: Fix file pointer leak Message-ID: <20220426133926.GA33188@chenyu5-mobl1> References: <20220426131607.1520483-1-colin.i.king@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220426131607.1520483-1-colin.i.king@gmail.com> X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 26, 2022 at 02:16:07PM +0100, Colin Ian King wrote: > Currently if a fscanf fails then an early return leaks an open > file pointer. Fix this by fclosing the file before the return. > Detected using static analysis with cppcheck: > > tools/power/x86/turbostat/turbostat.c:2039:3: error: Resource leak: fp [resourceLeak] > > Fixes: eae97e053fe3 ("tools/power turbostat: Support thermal throttle count print") > Signed-off-by: Colin Ian King > --- > tools/power/x86/turbostat/turbostat.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c > index e6779f599a8e..db431b31c4df 100644 > --- a/tools/power/x86/turbostat/turbostat.c > +++ b/tools/power/x86/turbostat/turbostat.c > @@ -2035,9 +2035,9 @@ int get_core_throt_cnt(int cpu, unsigned long long *cnt) > if (!fp) > return -1; > ret = fscanf(fp, "%lld", &tmp); > + fclose(fp); > if (ret != 1) > return -1; > - fclose(fp); > *cnt = tmp; > > return 0; Acked-by: Chen Yu Thanks for fixing it. Chenyu