When no profile ID matches the extraction sequence, ice_add_prof()
allocates a new one. If ice_update_fd_swap() or ice_update_prof_masking()
then fails, it returns without freeing the ID, and if allocating the
profile map entry fails, without dropping the reference it took. Either
way the profile ID, a resource of the whole device, is leaked.
Free the ID on the first two paths, and drop the reference on the third
before jumping to err_ice_add_prof.
Fixes: 31ad4e4ee1e4 ("ice: Allocate flow profile")
Fixes: 148beb612031 ("ice: Initialize Flow Director resources")
Fixes: b199dddbd399 ("ice: Support non word aligned input set field")
Signed-off-by: Jakub Ramaseuski <[email protected]>
---
drivers/net/ethernet/intel/ice/ice_flex_pipe.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_flex_pipe.c
b/drivers/net/ethernet/intel/ice/ice_flex_pipe.c
index 2a054d3abd466..6d619eeaf0190 100644
--- a/drivers/net/ethernet/intel/ice/ice_flex_pipe.c
+++ b/drivers/net/ethernet/intel/ice/ice_flex_pipe.c
@@ -3065,14 +3065,18 @@ ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64
id,
* during Tx.
*/
status = ice_update_fd_swap(hw, prof_id, es);
- if (status)
+ if (status) {
+ ice_free_prof_id(hw, blk, prof_id);
goto err_ice_add_prof;
+ }
} else if (blk == ICE_BLK_FD) {
ice_disable_fd_swap(hw, prof_id);
}
status = ice_update_prof_masking(hw, blk, prof_id, masks);
- if (status)
+ if (status) {
+ ice_free_prof_id(hw, blk, prof_id);
goto err_ice_add_prof;
+ }
/* and write new es */
ice_write_es(hw, blk, prof_id, es, symm);
@@ -3083,6 +3087,7 @@ ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64
id,
/* add profile info */
prof = devm_kzalloc_obj(ice_hw_to_dev(hw), *prof);
if (!prof) {
+ ice_prof_dec_ref(hw, blk, prof_id);
status = -ENOMEM;
goto err_ice_add_prof;
}
--
2.56.0