Skip to content

Commit 862b0e6

Browse files
superm1gregkh
authored andcommitted
PM: hibernate: Use atomic64_t for compressed_size variable
commit 66ededc upstream. `compressed_size` can overflow, showing nonsensical values. Change from `atomic_t` to `atomic64_t` to prevent overflow. Fixes: a06c6f5 ("PM: hibernate: Move to crypto APIs for LZO compression") Reported-by: Askar Safin <[email protected]> Closes: https://lore.kernel.org/linux-pm/[email protected]/ Signed-off-by: Mario Limonciello (AMD) <[email protected]> Tested-by: Askar Safin <[email protected]> Cc: 6.9+ <[email protected]> # 6.9+ Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8dd351c commit 862b0e6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

kernel/power/swap.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ struct cmp_data {
648648
};
649649

650650
/* Indicates the image size after compression */
651-
static atomic_t compressed_size = ATOMIC_INIT(0);
651+
static atomic64_t compressed_size = ATOMIC_INIT(0);
652652

653653
/*
654654
* Compression function that runs in its own thread.
@@ -676,7 +676,7 @@ static int compress_threadfn(void *data)
676676
&cmp_len);
677677
d->cmp_len = cmp_len;
678678

679-
atomic_set(&compressed_size, atomic_read(&compressed_size) + d->cmp_len);
679+
atomic64_add(d->cmp_len, &compressed_size);
680680
atomic_set_release(&d->stop, 1);
681681
wake_up(&d->done);
682682
}
@@ -708,7 +708,7 @@ static int save_compressed_image(struct swap_map_handle *handle,
708708

709709
hib_init_batch(&hb);
710710

711-
atomic_set(&compressed_size, 0);
711+
atomic64_set(&compressed_size, 0);
712712

713713
/*
714714
* We'll limit the number of threads for compression to limit memory
@@ -884,8 +884,8 @@ static int save_compressed_image(struct swap_map_handle *handle,
884884
ret = err2;
885885
if (!ret) {
886886
swsusp_show_speed(start, stop, nr_to_write, "Wrote");
887-
pr_info("Image size after compression: %d kbytes\n",
888-
(atomic_read(&compressed_size) / 1024));
887+
pr_info("Image size after compression: %lld kbytes\n",
888+
(atomic64_read(&compressed_size) / 1024));
889889
pr_info("Image saving done\n");
890890
} else {
891891
pr_err("Image saving failed: %d\n", ret);

0 commit comments

Comments
 (0)