Re: [PATCH 1/2] lscpu-arm: Allow externally sourced model name.

Karel Zak <[email protected]> Mon, 14 Jul 2025 14:11:21 +0200
Newsgroups org.kernel.vger.util-linux
Message-ID <orijvbt7r27kydrga2fq74hk7r4goizmbtqfqlbqngkpyizbod@xhwyidk2u3zh>
Hi Paul,

On Fri, Jul 11, 2025 at 02:16:47PM -0700, Paul Benoit wrote:
> When there isn't an entry for the model name in the id_part table(s),
> attempt to get the machine name from /sys/bus/soc/devices/soc0/machine

How is it supposed to work on a system with multiple CPU types (more CPU  
models) if it reads all from the same path?

> +	/*
> +	 * If the Model name was not found in the lscpu 'id_part' tables, see
> +	 * if there is a Machine name associated with the SOC.  This name may
> +	 * have been set via either SOC specific support code, or obtained
> +	 * via an ARM SMC CC call into Trusted Firmware.
> +	 */
> +	if (!ct->modelname) {
> +		fd = ul_path_fopen(NULL, "r", _PATH_SOC_MACHINENAME);
> +		if (fd) {
> +			if (!fgets(machinename, sizeof(machinename), fd))
> +				machinename[0] = '\0';
> +			fclose(fd);
> +
> +			/* Replace newline with string terminator */
> +			for (i = 0; i < strlen(machinename); i++) {
> +				if (machinename[i] == '\n')
> +					machinename[i] = '\0';
> +			}
> +
> +			if (strnlen(machinename, sizeof(machinename)))
> +				ct->modelname = xstrdup(machinename);

    if (!ct->modelname)
        ul_path_read_string(NULL, &ct->modelname, _PATH_SOC_MACHINENAME);

This should be enough, it reads the string, removes \n and strdup()
the result.

    Karel

-- 
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com