Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4691308ybp; Mon, 7 Oct 2019 12:18:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkfbzuAzPM69AgyCuEwKcjF9EbCNhqoRLUq1p6Eg7t5xiCg3zy5j4wU4/g6v7HmpoBOsMe X-Received: by 2002:a50:ab84:: with SMTP id u4mr30652927edc.13.1570475929998; Mon, 07 Oct 2019 12:18:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570475929; cv=none; d=google.com; s=arc-20160816; b=hTyr0CkyjtQOGJFrFDyiUsSf1ue3GA7EqPla3n57ysmKZkk2bGm+KMG1oatQQHa79S Cv77B1zYPWJgDTN2iFwrAECt9YSss9VWk5esqbA8Glb3NwAzvHICcaHm3t7zTtck4Mu9 Cck5vVZRU4dJI2W4jdlSrn2TPQaLZnWvcgg6mYUR0j2EC/5dfQ0AhBdbwpqk7IvpCbsW DSRMR7VSNp70Cd19GwuLXUc/5wl5lycRo1XIIq3yVb3DADKuAvYG5CIzzG693S9yu8JZ iwP/GsNpPVlPfaTgzafWmBHJh5ffZNspG5d6aZ8HoWgtPyo7KCBCPFyBxBSXM+plptnu afzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=Zfyd2CF7Jp2/eLv1mkoVaY5tdt50GOVthjJEFeOstU4=; b=Mc6DPahp1UTzu3pBw9mOl1MnBm930a+uYJ3IPMQDsI2QmiQ0RLjuEb+zJpHbd8XKas 24iPj3HhGi/bFHCwHeVWYeoM6wT94BbLobdLVDvBpvrarDyCyJSxrTayp7U4sUJIexqy /UqTuNPCK44MgaQA41wyx/bI3PJ8spqJVEjshkuSt8dEt0NjPDIO6A3F8Rf0tvoEgUlw Emcz0U2u68Ov34B4Ju5JkU6ySo6X66yZRHCJYBFC1fqc46j1OdNgvbAM90ujJLS3hgkx gUYbD/hCvq3nnbqH5pXY5W33pIJ0wYqP488l0ARUiEDpTzE3hcoEuuh+btaPCAHML5jh 3aSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8si7691698ejt.219.2019.10.07.12.18.25; Mon, 07 Oct 2019 12:18:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728723AbfJGTSB (ORCPT + 99 others); Mon, 7 Oct 2019 15:18:01 -0400 Received: from mga05.intel.com ([192.55.52.43]:21010 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728187AbfJGTSB (ORCPT ); Mon, 7 Oct 2019 15:18:01 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Oct 2019 12:18:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,269,1566889200"; d="scan'208";a="344820197" Received: from spandruv-desk.jf.intel.com ([10.54.75.31]) by orsmga004.jf.intel.com with ESMTP; 07 Oct 2019 12:18:00 -0700 Message-ID: <00b61947ffe509d02383903a059067517dd2605c.camel@linux.intel.com> Subject: Re: [PATCH v2 3/7] intel-speed-select: Add check for CascadeLake-N models From: Srinivas Pandruvada To: Andy Shevchenko Cc: Prarit Bhargava , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 07 Oct 2019 12:18:00 -0700 In-Reply-To: <20191007100313.GP32742@smile.fi.intel.com> References: <20191003121112.25870-1-prarit@redhat.com> <20191003121112.25870-4-prarit@redhat.com> <20191007100313.GP32742@smile.fi.intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-3.fc28) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2019-10-07 at 13:03 +0300, Andy Shevchenko wrote: > On Fri, Oct 04, 2019 at 10:15:21AM -0700, Srinivas Pandruvada wrote: > > On Thu, 2019-10-03 at 08:11 -0400, Prarit Bhargava wrote: > > > + /* only three CascadeLake-N models are supported */ > > > + if (is_clx_n_platform()) { > > > + FILE *fp; > > > + size_t n; > > > + char *line; > > > > Need n = 0 and *line = NULL here as getline() will require if it > > has to > > allocate. > > Good catch and thus... > > > > + int ret = 1; > > > + > > > + fp = fopen("/proc/cpuinfo", "r"); > > > + if (!fp) > > > + err(-1, "cannot open /proc/cpuinfo\n"); > > > + > > > + while (getline(&line, &n, fp) > 0) { > > > + if (strstr(line, "model name")) { > > > + if (strstr(line, "6252N") || > > > + strstr(line, "6230N") || > > > + strstr(line, "5218N")) > > > + ret = 0; > > > + break; > > > + } > > Missed free(line) here. This may not be required. After the first call geline() allocated a buffer and will reuse it during next call. If it is not enough it will realloc even if the buffer is passed by user via malloc(). From man page: " If *lineptr is set to NULL and *n is set 0 before the call, then getline() will allocate a buffer for storing the line. This buffer should be freed by the user program even if getline() failed. Alternatively, before calling getline(), *lineptr can contain a pointer to a malloc(3)-allocated buffer *n bytes in size. If the buffer is not large enough to hold the line, getline() resizes it with realloc(3), updating *lineptr and *n as necessary. In either case, on a successful call, *lineptr and *n will be updated to reflect the buffer address and allocated size respectively. " > > > > + } > > > + free(line); > > > + fclose(fp); > > > + return ret; > > > + } > > > + return 0; > > > } > > > > > > /* Open a file, and exit on failure */ > > > @@ -1889,7 +1927,9 @@ static void cmdline(int argc, char **argv) > > > fprintf(stderr, "Feature name and|or command not > > > specified\n"); > > > exit(0); > > > } > > > - update_cpu_model(); > > > + ret = update_cpu_model(); > > > + if (ret) > > > + err(-1, "Invalid CPU model (%d)\n", cpu_model); > > > printf("Intel(R) Speed Select Technology\n"); > > > printf("Executing on CPU model:%d[0x%x]\n", cpu_model, > > > cpu_model); > > > set_max_cpu_num(); > >