Re: [PATCH] rtla/utils: Fix the potential memory allocation failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

On 6/14/22 11:38, jianchunfu wrote:
> Add memory allocating check of mon_cpus before used in utils.
> 
Yeah, you found a problem, thanks for you patch! But it needs improvement.

Please, add the Fixes: tag.
Please Cc: linux-kernel

> Signed-off-by: jianchunfu <jianchunfu@xxxxxxxxxxxxxxxxxxxx>
> ---
>  tools/tracing/rtla/src/utils.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
> index ffaf8ec84..2a86440b3 100644
> --- a/tools/tracing/rtla/src/utils.c
> +++ b/tools/tracing/rtla/src/utils.c
> @@ -106,6 +106,10 @@ int parse_cpu_list(char *cpu_list, char **monitored_cpus)
>  	nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
>  
>  	mon_cpus = malloc(nr_cpus * sizeof(char));
> +	if (!mon_cpus) {
> +		perror("Failed to allocate memory");
> +		return -errno;
> +	}
>  	memset(mon_cpus, 0, (nr_cpus * sizeof(char)));

Your patch is fixing the problem, but it can be improved by:
	- using calloc (as in other .c)
	- removing the memset
	- instead of returning, goto err;

Do you mind sending a v2?

-- Daniel



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux