}
 
 /**
- * ice_sched_clear_tx_topo - clears the schduler tree nodes
- * @pi: port information structure
+ * ice_sched_clear_agg - clears the agg related information
+ * @hw: pointer to the hardware structure
  *
- * This function removes all the nodes from HW as well as from SW DB.
+ * This function removes agg list and free up agg related memory
+ * previously allocated.
  */
-static void ice_sched_clear_tx_topo(struct ice_port_info *pi)
+void ice_sched_clear_agg(struct ice_hw *hw)
 {
        struct ice_sched_agg_info *agg_info;
        struct ice_sched_agg_info *atmp;
-       struct ice_hw *hw;
-
-       if (!pi)
-               return;
 
-       hw = pi->hw;
-
-       list_for_each_entry_safe(agg_info, atmp, &pi->agg_list, list_entry) {
+       list_for_each_entry_safe(agg_info, atmp, &hw->agg_list, list_entry) {
                struct ice_sched_agg_vsi_info *agg_vsi_info;
                struct ice_sched_agg_vsi_info *vtmp;
 
                        list_del(&agg_vsi_info->list_entry);
                        devm_kfree(ice_hw_to_dev(hw), agg_vsi_info);
                }
+               list_del(&agg_info->list_entry);
+               devm_kfree(ice_hw_to_dev(hw), agg_info);
        }
+}
 
+/**
+ * ice_sched_clear_tx_topo - clears the scheduler tree nodes
+ * @pi: port information structure
+ *
+ * This function removes all the nodes from HW as well as from SW DB.
+ */
+static void ice_sched_clear_tx_topo(struct ice_port_info *pi)
+{
+       if (!pi)
+               return;
        if (pi->root) {
                ice_free_sched_node(pi, pi->root);
                pi->root = NULL;
        /* initialize the port for handling the scheduler tree */
        pi->port_state = ICE_SCHED_PORT_STATE_READY;
        mutex_init(&pi->sched_lock);
-       INIT_LIST_HEAD(&pi->agg_list);
 
 err_init_port:
        if (status && pi->root) {
        struct ice_sched_agg_info *agg_info;
        struct ice_sched_agg_info *atmp;
 
-       list_for_each_entry_safe(agg_info, atmp, &pi->agg_list, list_entry) {
+       list_for_each_entry_safe(agg_info, atmp, &pi->hw->agg_list,
+                                list_entry) {
                struct ice_sched_agg_vsi_info *agg_vsi_info;
                struct ice_sched_agg_vsi_info *vtmp;