Skip to content

Commit 1195c7c

Browse files
committed
Merge branch 'mlxsw-Various-fixes'
Ido Schimmel says: ==================== mlxsw: Various fixes Fix two issues found by syzkaller. Patch #1 removes inappropriate usage of WARN_ON() following memory allocation failure. Constantly triggered when syzkaller injects faults. Patch #2 fixes a use-after-free that can be triggered by 'devlink dev info' following a failed devlink reload. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents f9f41e3 + c4317b1 commit 1195c7c

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

drivers/net/ethernet/mellanox/mlxsw/pci.c

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,23 +1414,12 @@ static int mlxsw_pci_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
14141414
u16 num_pages;
14151415
int err;
14161416

1417-
mutex_init(&mlxsw_pci->cmd.lock);
1418-
init_waitqueue_head(&mlxsw_pci->cmd.wait);
1419-
14201417
mlxsw_pci->core = mlxsw_core;
14211418

14221419
mbox = mlxsw_cmd_mbox_alloc();
14231420
if (!mbox)
14241421
return -ENOMEM;
14251422

1426-
err = mlxsw_pci_mbox_alloc(mlxsw_pci, &mlxsw_pci->cmd.in_mbox);
1427-
if (err)
1428-
goto mbox_put;
1429-
1430-
err = mlxsw_pci_mbox_alloc(mlxsw_pci, &mlxsw_pci->cmd.out_mbox);
1431-
if (err)
1432-
goto err_out_mbox_alloc;
1433-
14341423
err = mlxsw_pci_sw_reset(mlxsw_pci, mlxsw_pci->id);
14351424
if (err)
14361425
goto err_sw_reset;
@@ -1537,9 +1526,6 @@ static int mlxsw_pci_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
15371526
mlxsw_pci_free_irq_vectors(mlxsw_pci);
15381527
err_alloc_irq:
15391528
err_sw_reset:
1540-
mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.out_mbox);
1541-
err_out_mbox_alloc:
1542-
mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.in_mbox);
15431529
mbox_put:
15441530
mlxsw_cmd_mbox_free(mbox);
15451531
return err;
@@ -1553,8 +1539,6 @@ static void mlxsw_pci_fini(void *bus_priv)
15531539
mlxsw_pci_aqs_fini(mlxsw_pci);
15541540
mlxsw_pci_fw_area_fini(mlxsw_pci);
15551541
mlxsw_pci_free_irq_vectors(mlxsw_pci);
1556-
mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.out_mbox);
1557-
mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.in_mbox);
15581542
}
15591543

15601544
static struct mlxsw_pci_queue *
@@ -1776,6 +1760,37 @@ static const struct mlxsw_bus mlxsw_pci_bus = {
17761760
.features = MLXSW_BUS_F_TXRX | MLXSW_BUS_F_RESET,
17771761
};
17781762

1763+
static int mlxsw_pci_cmd_init(struct mlxsw_pci *mlxsw_pci)
1764+
{
1765+
int err;
1766+
1767+
mutex_init(&mlxsw_pci->cmd.lock);
1768+
init_waitqueue_head(&mlxsw_pci->cmd.wait);
1769+
1770+
err = mlxsw_pci_mbox_alloc(mlxsw_pci, &mlxsw_pci->cmd.in_mbox);
1771+
if (err)
1772+
goto err_in_mbox_alloc;
1773+
1774+
err = mlxsw_pci_mbox_alloc(mlxsw_pci, &mlxsw_pci->cmd.out_mbox);
1775+
if (err)
1776+
goto err_out_mbox_alloc;
1777+
1778+
return 0;
1779+
1780+
err_out_mbox_alloc:
1781+
mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.in_mbox);
1782+
err_in_mbox_alloc:
1783+
mutex_destroy(&mlxsw_pci->cmd.lock);
1784+
return err;
1785+
}
1786+
1787+
static void mlxsw_pci_cmd_fini(struct mlxsw_pci *mlxsw_pci)
1788+
{
1789+
mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.out_mbox);
1790+
mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.in_mbox);
1791+
mutex_destroy(&mlxsw_pci->cmd.lock);
1792+
}
1793+
17791794
static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
17801795
{
17811796
const char *driver_name = pdev->driver->name;
@@ -1831,6 +1846,10 @@ static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
18311846
mlxsw_pci->pdev = pdev;
18321847
pci_set_drvdata(pdev, mlxsw_pci);
18331848

1849+
err = mlxsw_pci_cmd_init(mlxsw_pci);
1850+
if (err)
1851+
goto err_pci_cmd_init;
1852+
18341853
mlxsw_pci->bus_info.device_kind = driver_name;
18351854
mlxsw_pci->bus_info.device_name = pci_name(mlxsw_pci->pdev);
18361855
mlxsw_pci->bus_info.dev = &pdev->dev;
@@ -1848,6 +1867,8 @@ static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
18481867
return 0;
18491868

18501869
err_bus_device_register:
1870+
mlxsw_pci_cmd_fini(mlxsw_pci);
1871+
err_pci_cmd_init:
18511872
iounmap(mlxsw_pci->hw_addr);
18521873
err_ioremap:
18531874
err_pci_resource_len_check:
@@ -1865,6 +1886,7 @@ static void mlxsw_pci_remove(struct pci_dev *pdev)
18651886
struct mlxsw_pci *mlxsw_pci = pci_get_drvdata(pdev);
18661887

18671888
mlxsw_core_bus_device_unregister(mlxsw_pci->core, false);
1889+
mlxsw_pci_cmd_fini(mlxsw_pci);
18681890
iounmap(mlxsw_pci->hw_addr);
18691891
pci_release_regions(mlxsw_pci->pdev);
18701892
pci_disable_device(mlxsw_pci->pdev);

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6262,7 +6262,7 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
62626262
}
62636263

62646264
fib_work = kzalloc(sizeof(*fib_work), GFP_ATOMIC);
6265-
if (WARN_ON(!fib_work))
6265+
if (!fib_work)
62666266
return NOTIFY_BAD;
62676267

62686268
fib_work->mlxsw_sp = router->mlxsw_sp;

0 commit comments

Comments
 (0)