net/mlx5: Fix invalid pointer reference when prof_sel parameter is invalid
authorHuy Nguyen <huyn@mellanox.com>
Thu, 3 Nov 2016 23:48:47 +0000 (01:48 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 4 Nov 2016 18:59:37 +0000 (14:59 -0400)
When prof_sel is invalid, mlx5_core_warn is called but the
mlx5_core_dev is not initialized yet. Solution is moving the prof_sel code
after dev->pdev assignment

Fixes: 2974ab6e8bd8 ('net/mlx5: Improve driver log messages')
Signed-off-by: Huy Nguyen <huyn@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx5/core/main.c

index d5433c49b2b062a6608e5d7df1a136ab38a36989..3eb931585b3e38d6658892fd1dcb8482bb39094b 100644 (file)
@@ -1226,6 +1226,9 @@ static int init_one(struct pci_dev *pdev,
 
        pci_set_drvdata(pdev, dev);
 
+       dev->pdev = pdev;
+       dev->event = mlx5_core_event;
+
        if (prof_sel < 0 || prof_sel >= ARRAY_SIZE(profile)) {
                mlx5_core_warn(dev,
                               "selected profile out of range, selecting default (%d)\n",
@@ -1233,8 +1236,6 @@ static int init_one(struct pci_dev *pdev,
                prof_sel = MLX5_DEFAULT_PROF;
        }
        dev->profile = &profile[prof_sel];
-       dev->pdev = pdev;
-       dev->event = mlx5_core_event;
 
        INIT_LIST_HEAD(&priv->ctx_list);
        spin_lock_init(&priv->ctx_lock);