public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context()
@ 2024-05-19  9:09 Christophe JAILLET
  2024-05-19  9:09 ` [PATCH 2/2 net-next] libceph: Use __counted_by() in struct ceph_snap_context Christophe JAILLET
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Christophe JAILLET @ 2024-05-19  9:09 UTC (permalink / raw)
  To: Ilya Dryomov, Xiubo Li, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, ceph-devel,
	netdev

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 --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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-19 12:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-19  9:09 [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context() Christophe JAILLET
2024-05-19  9:09 ` [PATCH 2/2 net-next] libceph: Use __counted_by() in struct ceph_snap_context Christophe JAILLET
2024-05-19 11:34 ` [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context() kernel test robot
2024-05-19 12:45   ` Christophe JAILLET
2024-05-19 11:55 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox