Move the mutex_lock() call up to prevent that DCB settings change after
the ice_query_port_ets() call.

This patch fixes a bug in an error path. Without this patch pf->tc_mutex
may be unlocked in an error path without having been locked. This bug has
been detected by the clang thread-safety analyzer.

Cc: Tony Nguyen <[email protected]>
Cc: Przemek Kitszel <[email protected]>
Cc: [email protected]
Fixes: 242b5e068b25 ("ice: Fix DCB rebuild after reset")
Signed-off-by: Bart Van Assche <[email protected]>
---
 drivers/net/ethernet/intel/ice/ice_dcb_lib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_dcb_lib.c 
b/drivers/net/ethernet/intel/ice/ice_dcb_lib.c
index bd77f1c001ee..78ded6876581 100644
--- a/drivers/net/ethernet/intel/ice/ice_dcb_lib.c
+++ b/drivers/net/ethernet/intel/ice/ice_dcb_lib.c
@@ -537,14 +537,14 @@ void ice_dcb_rebuild(struct ice_pf *pf)
        struct ice_dcbx_cfg *err_cfg;
        int ret;
 
+       mutex_lock(&pf->tc_mutex);
+
        ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
        if (ret) {
                dev_err(dev, "Query Port ETS failed\n");
                goto dcb_error;
        }
 
-       mutex_lock(&pf->tc_mutex);
-
        if (!pf->hw.port_info->qos_cfg.is_sw_lldp)
                ice_cfg_etsrec_defaults(pf->hw.port_info);
 

Reply via email to