}
 }
 
+/**
+ * ice_eswitch_release_reprs - clear PR VSIs configuration
+ * @pf: poiner to PF struct
+ * @ctrl_vsi: pointer to switchdev control VSI
+ */
+static void
+ice_eswitch_release_reprs(struct ice_pf *pf, struct ice_vsi *ctrl_vsi)
+{
+       int i;
+
+       ice_for_each_vf(pf, i) {
+               struct ice_vsi *vsi = pf->vf[i].repr->src_vsi;
+               struct ice_vf *vf = &pf->vf[i];
+
+               /* Skip VFs that aren't configured */
+               if (!vf->repr->dst)
+                       continue;
+
+               ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
+               metadata_dst_free(vf->repr->dst);
+               vf->repr->dst = NULL;
+               ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr.addr,
+                                              ICE_FWD_TO_VSI);
+
+               netif_napi_del(&vf->repr->q_vector->napi);
+       }
+}
+
 /**
  * ice_eswitch_setup_reprs - configure port reprs to run in switchdev mode
  * @pf: pointer to PF struct
                                                       vf->hw_lan_addr.addr,
                                                       ICE_FWD_TO_VSI);
                        metadata_dst_free(vf->repr->dst);
+                       vf->repr->dst = NULL;
                        goto err;
                }
 
                                                       vf->hw_lan_addr.addr,
                                                       ICE_FWD_TO_VSI);
                        metadata_dst_free(vf->repr->dst);
+                       vf->repr->dst = NULL;
                        ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
                        goto err;
                }
        return 0;
 
 err:
-       for (i = i - 1; i >= 0; i--) {
-               struct ice_vsi *vsi = pf->vf[i].repr->src_vsi;
-               struct ice_vf *vf = &pf->vf[i];
-
-               ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
-               metadata_dst_free(vf->repr->dst);
-               ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr.addr,
-                                              ICE_FWD_TO_VSI);
-       }
+       ice_eswitch_release_reprs(pf, ctrl_vsi);
 
        return -ENODEV;
 }
 
-/**
- * ice_eswitch_release_reprs - clear PR VSIs configuration
- * @pf: poiner to PF struct
- * @ctrl_vsi: pointer to switchdev control VSI
- */
-static void
-ice_eswitch_release_reprs(struct ice_pf *pf, struct ice_vsi *ctrl_vsi)
-{
-       int i;
-
-       ice_for_each_vf(pf, i) {
-               struct ice_vsi *vsi = pf->vf[i].repr->src_vsi;
-               struct ice_vf *vf = &pf->vf[i];
-
-               ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
-               metadata_dst_free(vf->repr->dst);
-               ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr.addr,
-                                              ICE_FWD_TO_VSI);
-
-               netif_napi_del(&vf->repr->q_vector->napi);
-       }
-}
-
 /**
  * ice_eswitch_update_repr - reconfigure VF port representor
  * @vsi: VF VSI for which port representor is configured
 
 
        devlink_port_type_eth_set(&vf->devlink_port, repr->netdev);
 
+       ice_vc_change_ops_to_repr(&vf->vc_ops);
+
        return 0;
 
 err_netdev:
  */
 static void ice_repr_rem(struct ice_vf *vf)
 {
+       if (!vf->repr)
+               return;
+
        ice_devlink_destroy_vf_port(vf);
        kfree(vf->repr->q_vector);
        vf->repr->q_vector = NULL;
 #endif
        kfree(vf->repr);
        vf->repr = NULL;
+
+       ice_vc_set_dflt_vf_ops(&vf->vc_ops);
 }
 
 /**
- * ice_repr_add_for_all_vfs - add port representor for all VFs
+ * ice_repr_rem_from_all_vfs - remove port representor for all VFs
  * @pf: pointer to PF structure
  */
-int ice_repr_add_for_all_vfs(struct ice_pf *pf)
+void ice_repr_rem_from_all_vfs(struct ice_pf *pf)
 {
-       int err;
        int i;
 
        ice_for_each_vf(pf, i) {
                struct ice_vf *vf = &pf->vf[i];
 
-               err = ice_repr_add(vf);
-               if (err)
-                       goto err;
-
-               ice_vc_change_ops_to_repr(&vf->vc_ops);
-       }
-
-       return 0;
-
-err:
-       for (i = i - 1; i >= 0; i--) {
-               struct ice_vf *vf = &pf->vf[i];
-
                ice_repr_rem(vf);
-               ice_vc_set_dflt_vf_ops(&vf->vc_ops);
        }
-
-       return err;
 }
 
 /**
- * ice_repr_rem_from_all_vfs - remove port representor for all VFs
+ * ice_repr_add_for_all_vfs - add port representor for all VFs
  * @pf: pointer to PF structure
  */
-void ice_repr_rem_from_all_vfs(struct ice_pf *pf)
+int ice_repr_add_for_all_vfs(struct ice_pf *pf)
 {
+       int err;
        int i;
 
        ice_for_each_vf(pf, i) {
                struct ice_vf *vf = &pf->vf[i];
 
-               ice_repr_rem(vf);
-               ice_vc_set_dflt_vf_ops(&vf->vc_ops);
+               err = ice_repr_add(vf);
+               if (err)
+                       goto err;
        }
+
+       return 0;
+
+err:
+       ice_repr_rem_from_all_vfs(pf);
+
+       return err;
 }
 
 /**