lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZoR1GSV4_IWrNMK3@agluck-desk3.sc.intel.com>
Date: Tue, 2 Jul 2024 14:46:01 -0700
From: Tony Luck <tony.luck@...el.com>
To: Reinette Chatre <reinette.chatre@...el.com>
Cc: "Wieczor-Retman, Maciej" <maciej.wieczor-retman@...el.com>,
	"shuah@...nel.org" <shuah@...nel.org>,
	"Yu, Fenghua" <fenghua.yu@...el.com>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"linux-kselftest@...r.kernel.org" <linux-kselftest@...r.kernel.org>,
	"ilpo.jarvinen@...ux.intel.com" <ilpo.jarvinen@...ux.intel.com>
Subject: Re: [PATCH v3 2/2] selftests/resctrl: Adjust SNC support messages

On Tue, Jul 02, 2024 at 02:26:25PM -0700, Reinette Chatre wrote:
> Hi Tony,
> 
> On 7/1/24 9:04 AM, Luck, Tony wrote:
> > +static bool cpus_offline_empty(void)
> > +{
> > +	char offline_cpus_str[64];
> > +	FILE *fp;
> > +
> > +	fp = fopen("/sys/devices/system/cpu/offline", "r");
> > 
> > Check for fp == NULL before using it.
> > 
> > +	if (fscanf(fp, "%s", offline_cpus_str) < 0) {
> > 
> > fscanf() seems like a heavy hammer.
> 
> Do you perhaps have any recommendations that should be used instead of
> fscanf()? I checked with stat() but could not see a difference between
> file with a CPU and a file without. Other alternative is
> open()/read()/close()? Looks like when there are no offline CPUs then
> the file will only contain '\n' so it may be possible to read one byte
> from the file and confirm it is '\n' as a check for "cpus_offline_empty()".

Sorry. I replied with Outlook and didn't quote things properly
so my alternate suggestion didn't stand out. Here it is again:

	if (fgets(offline_cpus_str, sizeof(offline_cpus_str), fp) == NULL) {
		fclose(fp);
		return true;
	}

But that was with the assumption that /sys/devices/system/cpu/offline
would be empty. Not that it would conatain a single "\n" as you say
above.

So fgets( ...) followed with "if (offline_cpus_str[0] == '\n') "?

-Tony

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ