All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Ilya Dryomov <idryomov@gmail.com>, Xiubo Li <xiubli@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	ceph-devel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context()
Date: Sun, 19 May 2024 11:09:58 +0200	[thread overview]
Message-ID: <5b7c72bdb52703bbfa5511ed500aed4babde1308.1716109606.git.christophe.jaillet@wanadoo.fr> (raw)

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


             reply	other threads:[~2024-05-19  9:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-19  9:09 Christophe JAILLET [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5b7c72bdb52703bbfa5511ed500aed4babde1308.1716109606.git.christophe.jaillet@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=ceph-devel@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=idryomov@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=xiubli@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.