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] [day] [month] [year] [list]
Date:   Thu, 21 Oct 2021 13:06:24 +0200
From:   "Rafael J. Wysocki" <rafael@...nel.org>
To:     Cai Huoqing <caihuoqing@...du.com>
Cc:     "Rafael J. Wysocki" <rafael@...nel.org>,
        Pavel Machek <pavel@....cz>, Len Brown <len.brown@...el.com>,
        Linux PM <linux-pm@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] kernel: power: swap: Make use of vzalloc() and kzalloc()

On Mon, Oct 18, 2021 at 3:16 PM Cai Huoqing <caihuoqing@...du.com> wrote:
>
> Replacing vmalloc()/memset() with vzalloc() and replacing
> kmalloc()/memset() with kzalloc() to simplify the code.
>
> Signed-off-by: Cai Huoqing <caihuoqing@...du.com>
> ---
>  kernel/power/swap.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/power/swap.c b/kernel/power/swap.c
> index 9ec418955556..5e8368fa348c 100644
> --- a/kernel/power/swap.c
> +++ b/kernel/power/swap.c
> @@ -705,22 +705,19 @@ static int save_image_lzo(struct swap_map_handle *handle,
>                 goto out_clean;
>         }
>
> -       data = vmalloc(array_size(nr_threads, sizeof(*data)));
> +       data = vzalloc(array_size(nr_threads, sizeof(*data)));
>         if (!data) {
>                 pr_err("Failed to allocate LZO data\n");
>                 ret = -ENOMEM;
>                 goto out_clean;
>         }
> -       for (thr = 0; thr < nr_threads; thr++)
> -               memset(&data[thr], 0, offsetof(struct cmp_data, go));
>
> -       crc = kmalloc(sizeof(*crc), GFP_KERNEL);
> +       crc = kzalloc(sizeof(*crc), GFP_KERNEL);
>         if (!crc) {
>                 pr_err("Failed to allocate crc\n");
>                 ret = -ENOMEM;
>                 goto out_clean;
>         }
> -       memset(crc, 0, offsetof(struct crc_data, go));
>
>         /*
>          * Start the compression threads.
> @@ -1198,22 +1195,19 @@ static int load_image_lzo(struct swap_map_handle *handle,
>                 goto out_clean;
>         }
>
> -       data = vmalloc(array_size(nr_threads, sizeof(*data)));
> +       data = vzalloc(array_size(nr_threads, sizeof(*data)));
>         if (!data) {
>                 pr_err("Failed to allocate LZO data\n");
>                 ret = -ENOMEM;
>                 goto out_clean;
>         }
> -       for (thr = 0; thr < nr_threads; thr++)
> -               memset(&data[thr], 0, offsetof(struct dec_data, go));
>
> -       crc = kmalloc(sizeof(*crc), GFP_KERNEL);
> +       crc = kzalloc(sizeof(*crc), GFP_KERNEL);
>         if (!crc) {
>                 pr_err("Failed to allocate crc\n");
>                 ret = -ENOMEM;
>                 goto out_clean;
>         }
> -       memset(crc, 0, offsetof(struct crc_data, go));
>
>         clean_pages_on_decompress = true;
>
> --

Applied as 5.16 material with some edits in the subject and changelog, thanks!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ