[PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context()

From: Christophe JAILLET
Date: Sun May 19 2024 - 05:19:53 EST


Use sruct_size() instead of hand-writing it.
This makes the code more readable and safer.

Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
---
Compile tested only
---
net/ceph/snapshot.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/net/ceph/snapshot.c b/net/ceph/snapshot.c
index e24315937c45..7363ccebee99 100644
--- a/net/ceph/snapshot.c
+++ b/net/ceph/snapshot.c
@@ -28,11 +28,8 @@ struct ceph_snap_context *ceph_create_snap_context(u32 snap_count,
gfp_t gfp_flags)
{
struct ceph_snap_context *snapc;
- size_t size;

- size = sizeof (struct ceph_snap_context);
- size += snap_count * sizeof (snapc->snaps[0]);
- snapc = kzalloc(size, gfp_flags);
+ snapc = kzalloc(sruct_size(snapc, snaps, snap_count), gfp_flags);
if (!snapc)
return NULL;

--
2.45.1