PM: hibernate: swap: Use vzalloc() and kzalloc()
authorCai Huoqing <caihuoqing@baidu.com>
Mon, 18 Oct 2021 13:16:21 +0000 (21:16 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 21 Oct 2021 11:04:57 +0000 (13:04 +0200)
Replace vmalloc()/memset() with vzalloc() and kmalloc()/memset() with
kzalloc() to simplify the code.

Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
kernel/power/swap.c

index 47107f9..d59420b 100644 (file)
@@ -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;