ice_phy_conf_link() allocates the PHY capabilities buffer and only
then validates hw->port_info.
If hw->port_info is NULL,it returns directly without freeing
PHY capabilities buffer causing the buffer leak.

This patch fixes the issue by moving the hw->port_info NULL check
above the PHY capabilities buffer allocation.

Fixes: 36afbc269081 ("net/ice: support link speed change")
Cc: [email protected]

Signed-off-by: Anurag Mandal <[email protected]>
---
 drivers/net/intel/ice/ice_ethdev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/intel/ice/ice_ethdev.c 
b/drivers/net/intel/ice/ice_ethdev.c
index 2c5ffe07f3..dd23a7555c 100644
--- a/drivers/net/intel/ice/ice_ethdev.c
+++ b/drivers/net/intel/ice/ice_ethdev.c
@@ -5253,14 +5253,14 @@ ice_phy_conf_link(struct ice_hw *hw,
        u64 phy_type_low = 0;
        u64 phy_type_high = 0;
 
+       if (!pi)
+               return -EIO;
+
        phy_caps = (struct ice_aqc_get_phy_caps_data *)
                ice_malloc(hw, sizeof(*phy_caps));
        if (!phy_caps)
                return ICE_ERR_NO_MEMORY;
 
-       if (!pi)
-               return -EIO;
-
 
        if (ice_fw_supports_report_dflt_cfg(pi->hw))
                err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
-- 
2.34.1

Reply via email to