Skip to content

Commit 9437e39

Browse files
caihuoqing1990rafaeljw
authored andcommitted
PM: hibernate: swap: Use vzalloc() and kzalloc()
Replace vmalloc()/memset() with vzalloc() and kmalloc()/memset() with kzalloc() to simplify the code. Signed-off-by: Cai Huoqing <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 01de5fc commit 9437e39

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

kernel/power/swap.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -705,22 +705,19 @@ static int save_image_lzo(struct swap_map_handle *handle,
705705
goto out_clean;
706706
}
707707

708-
data = vmalloc(array_size(nr_threads, sizeof(*data)));
708+
data = vzalloc(array_size(nr_threads, sizeof(*data)));
709709
if (!data) {
710710
pr_err("Failed to allocate LZO data\n");
711711
ret = -ENOMEM;
712712
goto out_clean;
713713
}
714-
for (thr = 0; thr < nr_threads; thr++)
715-
memset(&data[thr], 0, offsetof(struct cmp_data, go));
716714

717-
crc = kmalloc(sizeof(*crc), GFP_KERNEL);
715+
crc = kzalloc(sizeof(*crc), GFP_KERNEL);
718716
if (!crc) {
719717
pr_err("Failed to allocate crc\n");
720718
ret = -ENOMEM;
721719
goto out_clean;
722720
}
723-
memset(crc, 0, offsetof(struct crc_data, go));
724721

725722
/*
726723
* Start the compression threads.
@@ -1198,22 +1195,19 @@ static int load_image_lzo(struct swap_map_handle *handle,
11981195
goto out_clean;
11991196
}
12001197

1201-
data = vmalloc(array_size(nr_threads, sizeof(*data)));
1198+
data = vzalloc(array_size(nr_threads, sizeof(*data)));
12021199
if (!data) {
12031200
pr_err("Failed to allocate LZO data\n");
12041201
ret = -ENOMEM;
12051202
goto out_clean;
12061203
}
1207-
for (thr = 0; thr < nr_threads; thr++)
1208-
memset(&data[thr], 0, offsetof(struct dec_data, go));
12091204

1210-
crc = kmalloc(sizeof(*crc), GFP_KERNEL);
1205+
crc = kzalloc(sizeof(*crc), GFP_KERNEL);
12111206
if (!crc) {
12121207
pr_err("Failed to allocate crc\n");
12131208
ret = -ENOMEM;
12141209
goto out_clean;
12151210
}
1216-
memset(crc, 0, offsetof(struct crc_data, go));
12171211

12181212
clean_pages_on_decompress = true;
12191213

0 commit comments

Comments
 (0)