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

Re: [Xen-devel] [PATCH v8 04/16] microcode/amd: fix memory leak


  • To: Chao Gao <chao.gao@xxxxxxxxx>
  • From: Jan Beulich <JBeulich@xxxxxxxx>
  • Date: Fri, 2 Aug 2019 13:39:42 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=suse.com;dmarc=pass action=none header.from=suse.com;dkim=pass header.d=suse.com;arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=awlSxgRq/NXqLi9pOxcixGtHtuKQG/c4nqEpeshAJz0=; b=ES4ctkHGZ6ZNoerflRnY0ky2LGXdtpo87+7FxHwYf+h7ggN57ilqEqyFWEO0UQk6JBR2sEss6v6E5RrcY9rAHsOI41CskIb+vnQ4v4Aye0GJ3LyCorvKZpPqbwBT+PQalTyvsc5YB3HiiNUdZaPOz4ZDovHZ11RAQcpyW1jmE6LxtFihpR6vjRLt2alhlj60poExu3Vm/dSPRvzik+0vs4Xb48XEMrAWMJ3h8h02914FsVrN/nbu3vJeiX+zqkToWguEGCFkBxxDv0ISTug8bnr8F4aCGrQtHL/sPE0jbSX/DYJ563vTUa2MrSTB8COppZ33qXZ3VE9x9N1RznKnPA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UTKRaMIcjU7aeToaWaz8hBYsJlny3Rbo/DRvk88BN4GtvHhHjYGD91bwQp5zeFiUaW0GyxhdowbwMPljyrwUafp4ugX6ZUtghKtpCB66l1U9ISkz8Nhw6MG1Zs5xNVBK1+R3qGxSi5pxk68MwZ5HXcUWxluxL3V7ee1sJT9uAXPGzZLn9354+suvpyl+CuZIRb9b/4+iVVL/KzzgXUp73QodB0cZFVByff1bHi4sVZy6gSvubGx++eqjLVIa1PtYd637Uo+B625cdSRi4hQhrATxiFGZArmRIk1hitPM0EynG2Zq6Qz1PyfTZwobiPfYgN3RMoPsmR8HpjxrXSrMHg==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=JBeulich@xxxxxxxx;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Ashok Raj <ashok.raj@xxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Fri, 02 Aug 2019 13:41:43 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHVSFKOdk5vupejrkq3Gs8xPRZZh6bn3tGA
  • Thread-topic: [PATCH v8 04/16] microcode/amd: fix memory leak

On 01.08.2019 12:22, Chao Gao wrote:
> --- a/xen/arch/x86/microcode_amd.c
> +++ b/xen/arch/x86/microcode_amd.c
> @@ -433,6 +433,9 @@ static int cpu_request_microcode(unsigned int cpu, const 
> void *buf,
>           goto out;
>       }
>   
> +    mc_amd->equiv_cpu_table_size = 0;
> +    mc_amd->equiv_cpu_table = NULL;

Instead of adding these, you could as well use xzalloc()
further up and drop the explicit initialization of ->mpb and
->mpb_size to NULL/0 a few lines down.

> @@ -479,6 +482,8 @@ static int cpu_request_microcode(unsigned int cpu, const 
> void *buf,
>   
>       if ( error )
>       {
> +        if ( mc_amd->equiv_cpu_table_size )
> +            xfree(mc_amd->equiv_cpu_table);

Why the if()? There's no problem calling xfree() with a NULL
argument.

> @@ -549,11 +554,14 @@ static int cpu_request_microcode(unsigned int cpu, 
> const void *buf,
>   
>       if ( save_error )
>       {
> -        xfree(mc_amd);
>           uci->mc.mc_amd = mc_old;
> +        mc_old = mc_amd;
>       }
> -    else
> -        xfree(mc_old);
> +
> +    if ( mc_old->mpb_size )
> +        xfree(mc_old->mpb);
> +    xfree(mc_old->equiv_cpu_table);

Same here. With the adjustments made (could possibly be done
again while committing)
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>

Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.