Skip to content

Commit

Permalink
pds_core: fix mutex double unlock in error path
Browse files Browse the repository at this point in the history
Fix a double unlock in an error handling path by unlocking as soon as
the error is seen and removing unlocks in the error cleanup path.

Link: https://lore.kernel.org/kernel-janitors/[email protected]/
Fixes: 523847d ("pds_core: add devcmd device interfaces")
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Shannon Nelson <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
emusln authored and davem330 committed May 5, 2023
1 parent 1a30449 commit 1e76f42
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions drivers/net/ethernet/amd/pds_core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,16 @@ static int pdsc_init_pf(struct pdsc *pdsc)
set_bit(PDSC_S_FW_DEAD, &pdsc->state);

err = pdsc_setup(pdsc, PDSC_SETUP_INIT);
if (err)
if (err) {
mutex_unlock(&pdsc->config_lock);
goto err_out_unmap_bars;
}

err = pdsc_start(pdsc);
if (err)
if (err) {
mutex_unlock(&pdsc->config_lock);
goto err_out_teardown;
}

mutex_unlock(&pdsc->config_lock);

Expand All @@ -257,13 +262,15 @@ static int pdsc_init_pf(struct pdsc *pdsc)
err = devl_params_register(dl, pdsc_dl_params,
ARRAY_SIZE(pdsc_dl_params));
if (err) {
devl_unlock(dl);
dev_warn(pdsc->dev, "Failed to register devlink params: %pe\n",
ERR_PTR(err));
goto err_out_unlock_dl;
goto err_out_stop;
}

hr = devl_health_reporter_create(dl, &pdsc_fw_reporter_ops, 0, pdsc);
if (IS_ERR(hr)) {
devl_unlock(dl);
dev_warn(pdsc->dev, "Failed to create fw reporter: %pe\n", hr);
err = PTR_ERR(hr);
goto err_out_unreg_params;
Expand All @@ -279,15 +286,13 @@ static int pdsc_init_pf(struct pdsc *pdsc)
return 0;

err_out_unreg_params:
devl_params_unregister(dl, pdsc_dl_params,
ARRAY_SIZE(pdsc_dl_params));
err_out_unlock_dl:
devl_unlock(dl);
devlink_params_unregister(dl, pdsc_dl_params,
ARRAY_SIZE(pdsc_dl_params));
err_out_stop:
pdsc_stop(pdsc);
err_out_teardown:
pdsc_teardown(pdsc, PDSC_TEARDOWN_REMOVING);
err_out_unmap_bars:
mutex_unlock(&pdsc->config_lock);
del_timer_sync(&pdsc->wdtimer);
if (pdsc->wq)
destroy_workqueue(pdsc->wq);
Expand Down

0 comments on commit 1e76f42

Please sign in to comment.