OSDN Git Service

net: openvswitch: Use struct_size()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sat, 6 May 2023 16:04:16 +0000 (18:04 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 18 May 2023 04:25:46 +0000 (21:25 -0700)
Use struct_size() instead of hand writing it.
This is less verbose and more informative.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Link: https://lore.kernel.org/r/e7746fbbd62371d286081d5266e88bbe8d3fe9f0.1683388991.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/openvswitch/meter.c

index f2698d2..c4ebf81 100644 (file)
@@ -69,9 +69,7 @@ static struct dp_meter_instance *dp_meter_instance_alloc(const u32 size)
 {
        struct dp_meter_instance *ti;
 
-       ti = kvzalloc(sizeof(*ti) +
-                     sizeof(struct dp_meter *) * size,
-                     GFP_KERNEL);
+       ti = kvzalloc(struct_size(ti, dp_meters, size), GFP_KERNEL);
        if (!ti)
                return NULL;