[PATCH v4 2/5] perf tools riscv: Add support for get_cpuid_str function

Nikita Shubin nikita.shubin at maquefel.me
Fri Jun 24 22:28:13 PDT 2022


Hello Arnaldo!

On Fri, 24 Jun 2022 13:32:20 -0300
Arnaldo Carvalho de Melo <acme at kernel.org> wrote:

> > +	if (mimpid)
> > +		free(mimpid);  
> 
> just use:
> 
> 	
> 	free(mvendorid);
> 	free(marchid);
> 	free(mimpid);
> 
> fewer lines, free() accepts NULL.
> 
> > +
> > +	return cpuid;
> > +}
> > +
> > +int get_cpuid(char *buffer, size_t sz)
> > +{
> > +	char *cpuid = _get_cpuid();
> > +
> > +	if (sz < strlen(cpuid)) {
> > +		free(cpuid);
> > +		return -EINVAL;
> > +	}
> > +
> > +	scnprintf(buffer, sz, "%s", cpuid);  
> 
> You're leaking cpuid here.

Agree with both.

Thank you for pointing it out.

> 
> > +	return 0;
> > +}
> > +
> > +char *
> > +get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
> > +{
> > +	return _get_cpuid();
> > +}
> > -- 
> > 2.35.1  
> 




More information about the linux-riscv mailing list