Skip to content

Commit 66ededc

Browse files
superm1rafaeljw
authored andcommitted
PM: hibernate: Use atomic64_t for compressed_size variable
`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]>
1 parent 62b9ca1 commit 66ededc

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

kernel/power/swap.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ struct cmp_data {
635635
};
636636

637637
/* Indicates the image size after compression */
638-
static atomic_t compressed_size = ATOMIC_INIT(0);
638+
static atomic64_t compressed_size = ATOMIC_INIT(0);
639639

640640
/*
641641
* Compression function that runs in its own thread.
@@ -664,7 +664,7 @@ static int compress_threadfn(void *data)
664664
d->ret = crypto_acomp_compress(d->cr);
665665
d->cmp_len = d->cr->dlen;
666666

667-
atomic_set(&compressed_size, atomic_read(&compressed_size) + d->cmp_len);
667+
atomic64_add(d->cmp_len, &compressed_size);
668668
atomic_set_release(&d->stop, 1);
669669
wake_up(&d->done);
670670
}
@@ -696,7 +696,7 @@ static int save_compressed_image(struct swap_map_handle *handle,
696696

697697
hib_init_batch(&hb);
698698

699-
atomic_set(&compressed_size, 0);
699+
atomic64_set(&compressed_size, 0);
700700

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

0 commit comments

Comments
 (0)