]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: dsa: mv88e6xxx: Use kcalloc()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 29 Jun 2025 12:35:50 +0000 (14:35 +0200)
committerJakub Kicinski <kuba@kernel.org>
Wed, 2 Jul 2025 02:31:38 +0000 (19:31 -0700)
Use kcalloc() instead of hand writing it. This is less verbose.

Also move the initialization of 'count' to save some LoC.

On a x86_64, with allmodconfig, as an example:
Before:
======
   text    data     bss     dec     hex filename
  18652    5920      64   24636    603c drivers/net/dsa/mv88e6xxx/devlink.o

After:
=====
   text    data     bss     dec     hex filename
  18498    5920      64   24482    5fa2 drivers/net/dsa/mv88e6xxx/devlink.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/2f4fca4ff84950da71e007c9169f18a0272476f3.1751200453.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/dsa/mv88e6xxx/devlink.c

index aec652e33fc172350722da5f71f5131a9f1aab73..da69e0b85879cc6ee62e2d37ce9c8e427b589980 100644 (file)
@@ -376,19 +376,14 @@ static int mv88e6xxx_region_atu_snapshot(struct devlink *dl,
        struct dsa_switch *ds = dsa_devlink_to_ds(dl);
        struct mv88e6xxx_devlink_atu_entry *table;
        struct mv88e6xxx_chip *chip = ds->priv;
-       int fid = -1, err = 0, count;
+       int fid = -1, err = 0, count = 0;
 
-       table = kmalloc_array(mv88e6xxx_num_databases(chip),
-                             sizeof(struct mv88e6xxx_devlink_atu_entry),
-                             GFP_KERNEL);
+       table = kcalloc(mv88e6xxx_num_databases(chip),
+                       sizeof(struct mv88e6xxx_devlink_atu_entry),
+                       GFP_KERNEL);
        if (!table)
                return -ENOMEM;
 
-       memset(table, 0, mv88e6xxx_num_databases(chip) *
-              sizeof(struct mv88e6xxx_devlink_atu_entry));
-
-       count = 0;
-
        mv88e6xxx_reg_lock(chip);
 
        while (1) {