Commit 62d4073e authored by Edwin Peer's avatar Edwin Peer Committed by David S. Miller

bnxt_en: fix memory leaks in bnxt_dcbnl_ieee_getets()

The allocated ieee_ets structure goes out of scope without being freed,
leaking memory. Appropriate result codes should be returned so that
callers do not rely on invalid data passed by reference.

Also cache the ETS config retrieved from the device so that it doesn't
need to be freed. The balance of the code was clearly written with the
intent of having the results of querying the hardware cached in the
device structure. The commensurate store was evidently missed though.

Fixes: 7df4ae9f ("bnxt_en: Implement DCBNL to support host-based DCBX.")
Signed-off-by: default avatarEdwin Peer <edwin.peer@broadcom.com>
Signed-off-by: default avatarMichael Chan <michael.chan@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a24ec322
...@@ -479,24 +479,26 @@ static int bnxt_dcbnl_ieee_getets(struct net_device *dev, struct ieee_ets *ets) ...@@ -479,24 +479,26 @@ static int bnxt_dcbnl_ieee_getets(struct net_device *dev, struct ieee_ets *ets)
{ {
struct bnxt *bp = netdev_priv(dev); struct bnxt *bp = netdev_priv(dev);
struct ieee_ets *my_ets = bp->ieee_ets; struct ieee_ets *my_ets = bp->ieee_ets;
int rc;
ets->ets_cap = bp->max_tc; ets->ets_cap = bp->max_tc;
if (!my_ets) { if (!my_ets) {
int rc;
if (bp->dcbx_cap & DCB_CAP_DCBX_HOST) if (bp->dcbx_cap & DCB_CAP_DCBX_HOST)
return 0; return 0;
my_ets = kzalloc(sizeof(*my_ets), GFP_KERNEL); my_ets = kzalloc(sizeof(*my_ets), GFP_KERNEL);
if (!my_ets) if (!my_ets)
return 0; return -ENOMEM;
rc = bnxt_hwrm_queue_cos2bw_qcfg(bp, my_ets); rc = bnxt_hwrm_queue_cos2bw_qcfg(bp, my_ets);
if (rc) if (rc)
return 0; goto error;
rc = bnxt_hwrm_queue_pri2cos_qcfg(bp, my_ets); rc = bnxt_hwrm_queue_pri2cos_qcfg(bp, my_ets);
if (rc) if (rc)
return 0; goto error;
/* cache result */
bp->ieee_ets = my_ets;
} }
ets->cbs = my_ets->cbs; ets->cbs = my_ets->cbs;
...@@ -505,6 +507,9 @@ static int bnxt_dcbnl_ieee_getets(struct net_device *dev, struct ieee_ets *ets) ...@@ -505,6 +507,9 @@ static int bnxt_dcbnl_ieee_getets(struct net_device *dev, struct ieee_ets *ets)
memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa)); memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa));
memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc)); memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc));
return 0; return 0;
error:
kfree(my_ets);
return rc;
} }
static int bnxt_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets) static int bnxt_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment