]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net/mlx5: cmd: Fix memset with byte count warning
authorSaeed Mahameed <saeedm@mellanox.com>
Thu, 28 May 2020 06:16:02 +0000 (23:16 -0700)
committerSaeed Mahameed <saeedm@mellanox.com>
Sat, 30 May 2020 04:20:21 +0000 (21:20 -0700)
Fix sparse warning:
drivers/net/ethernet/mellanox/mlx5/core/cmd.c:1949:15:
warning: memset with byte count of 271720

mlx5_cmd_stats array is too big to be held inline in mlx5_cmd.
Allocate it separately.

Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/cmd.c
drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
include/linux/mlx5/driver.h

index eca159e8e123b8dd15fd40899fef0fddfc78279c..1d91a0d0ab1d7035ad6b318272277e35f1bdbd95 100644 (file)
@@ -1072,7 +1072,7 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
 
        ds = ent->ts2 - ent->ts1;
        op = MLX5_GET(mbox_in, in->first.data, opcode);
-       if (op < ARRAY_SIZE(cmd->stats)) {
+       if (op < MLX5_CMD_OP_MAX) {
                stats = &cmd->stats[op];
                spin_lock_irq(&stats->lock);
                stats->sum += ds;
@@ -1551,7 +1551,7 @@ static void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vec, bool force
 
                        if (ent->callback) {
                                ds = ent->ts2 - ent->ts1;
-                               if (ent->op < ARRAY_SIZE(cmd->stats)) {
+                               if (ent->op < MLX5_CMD_OP_MAX) {
                                        stats = &cmd->stats[ent->op];
                                        spin_lock_irqsave(&stats->lock, flags);
                                        stats->sum += ds;
@@ -1960,10 +1960,16 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev)
                return -EINVAL;
        }
 
-       cmd->pool = dma_pool_create("mlx5_cmd", dev->device, size, align, 0);
-       if (!cmd->pool)
+       cmd->stats = kvzalloc(MLX5_CMD_OP_MAX * sizeof(*cmd->stats), GFP_KERNEL);
+       if (!cmd->stats)
                return -ENOMEM;
 
+       cmd->pool = dma_pool_create("mlx5_cmd", dev->device, size, align, 0);
+       if (!cmd->pool) {
+               err = -ENOMEM;
+               goto dma_pool_err;
+       }
+
        err = alloc_cmd_page(dev, cmd);
        if (err)
                goto err_free_pool;
@@ -1999,7 +2005,7 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev)
 
        spin_lock_init(&cmd->alloc_lock);
        spin_lock_init(&cmd->token_lock);
-       for (i = 0; i < ARRAY_SIZE(cmd->stats); i++)
+       for (i = 0; i < MLX5_CMD_OP_MAX; i++)
                spin_lock_init(&cmd->stats[i].lock);
 
        sema_init(&cmd->sem, cmd->max_reg_cmds);
@@ -2046,7 +2052,8 @@ err_free_page:
 
 err_free_pool:
        dma_pool_destroy(cmd->pool);
-
+dma_pool_err:
+       kvfree(cmd->stats);
        return err;
 }
 EXPORT_SYMBOL(mlx5_cmd_init);
@@ -2060,6 +2067,7 @@ void mlx5_cmd_cleanup(struct mlx5_core_dev *dev)
        destroy_msg_cache(dev);
        free_cmd_page(dev, cmd);
        dma_pool_destroy(cmd->pool);
+       kvfree(cmd->stats);
 }
 EXPORT_SYMBOL(mlx5_cmd_cleanup);
 
index d2d57213511be2c8fe2fa24a76b348757b423437..07c8d9811bc811249ef42ff583cf9c15827a5829 100644 (file)
@@ -171,7 +171,7 @@ void mlx5_cmdif_debugfs_init(struct mlx5_core_dev *dev)
        cmd = &dev->priv.cmdif_debugfs;
        *cmd = debugfs_create_dir("commands", dev->priv.dbg_root);
 
-       for (i = 0; i < ARRAY_SIZE(dev->cmd.stats); i++) {
+       for (i = 0; i < MLX5_CMD_OP_MAX; i++) {
                stats = &dev->cmd.stats[i];
                namep = mlx5_command_str(i);
                if (strcmp(namep, "unknown command opcode")) {
index 6aa6bbd60559b6d495d0986fc9781c851aae74cb..13c0e4556eda941f132b55b3f7f23e6ae58fb9b2 100644 (file)
@@ -298,7 +298,7 @@ struct mlx5_cmd {
        struct mlx5_cmd_debug dbg;
        struct cmd_msg_cache cache[MLX5_NUM_COMMAND_CACHES];
        int checksum_disabled;
-       struct mlx5_cmd_stats stats[MLX5_CMD_OP_MAX];
+       struct mlx5_cmd_stats *stats;
 };
 
 struct mlx5_port_caps {