summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRosen Penev <rosenp@gmail.com>2026-05-11 00:39:48 +0300
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2026-05-26 16:36:58 +0300
commit3da1dbf936d2fb25ef9925550bb276861d803e57 (patch)
tree6a760c421294def01d8a518889fd0f1bd484eef9
parent2068d7715e947f0321bc676a44215d3983af4bbc (diff)
downloadlinux-3da1dbf936d2fb25ef9925550bb276861d803e57.tar.xz
PM: hibernate: Use flexible array for CRC uncompressed buffers
The CRC uncompressed buffer pointer array has the same lifetime as struct crc_data, but it is currently allocated separately. That adds another allocation failure path and a matching cleanup branch without providing any extra flexibility. Store the pointer array as a flexible array member and allocate it together with the crc_data using kzalloc_flex(). The array remains zero-initialized, while the allocation and error handling become simpler. Assisted-by: Codex:GPT-5.5 Signed-off-by: Rosen Penev <rosenp@gmail.com> Link: https://patch.msgid.link/20260510213948.41750-1-rosenp@gmail.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--kernel/power/swap.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 2e64869bb5a0..b28233b8d00e 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -570,29 +570,23 @@ struct crc_data {
wait_queue_head_t done; /* crc update done */
u32 *crc32; /* points to handle's crc32 */
size_t **unc_len; /* uncompressed lengths */
- unsigned char **unc; /* uncompressed data */
+ unsigned char *unc[]; /* uncompressed data */
};
static struct crc_data *alloc_crc_data(int nr_threads)
{
struct crc_data *crc;
- crc = kzalloc_obj(*crc);
+ crc = kzalloc_flex(*crc, unc, nr_threads);
if (!crc)
return NULL;
- crc->unc = kcalloc(nr_threads, sizeof(*crc->unc), GFP_KERNEL);
- if (!crc->unc)
- goto err_free_crc;
-
crc->unc_len = kzalloc_objs(*crc->unc_len, nr_threads);
if (!crc->unc_len)
- goto err_free_unc;
+ goto err_free_crc;
return crc;
-err_free_unc:
- kfree(crc->unc);
err_free_crc:
kfree(crc);
return NULL;
@@ -607,7 +601,6 @@ static void free_crc_data(struct crc_data *crc)
kthread_stop(crc->thr);
kfree(crc->unc_len);
- kfree(crc->unc);
kfree(crc);
}