diff mbox series

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

Message ID 5b7c72bdb52703bbfa5511ed500aed4babde1308.1716109606.git.christophe.jaillet@wanadoo.fr
State New
Headers show
Series [1/2,net-next] libceph: Use sruct_size() in ceph_create_snap_context() | expand

Commit Message

Christophe JAILLET May 19, 2024, 9:09 a.m. UTC
Use sruct_size() instead of hand-writing it.
This makes the code more readable and safer.

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

Patch

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;