aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/intel/i40e
diff options
context:
space:
mode:
authorAnjali Singhai Jain <anjali.singhai@intel.com>2014-07-10 03:58:21 -0400
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>2014-08-15 06:50:37 -0400
commit6e7b5bd32c7cd303eec4880149636ffbc2098df8 (patch)
tree083dfe2d28db64603459b3320e361363f8e74321 /drivers/net/ethernet/intel/i40e
parent478c9e74204f7bd5f97cca92e917749434ed6f92 (diff)
i40e: Fix a few potential VF dereferences
In some functions we might be doing potential dereference without a check. This patch puts the check in place for all these functions. Also fix the "for loops" so that we increment VF at the right place so that we always do it even if we are short-circuiting the loop through continue. Change-ID: Id4276cfb1e841031bb7b6d6790c414242f364a9f Signed-off-by: Anjali Singhai Jain <anjali.singhai@intel.com> Tested-by: Jim Young <jamesx.m.young@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/net/ethernet/intel/i40e')
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
index 502b53441fa9..3ac6a0d2f143 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
@@ -1003,11 +1003,19 @@ int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
1003static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode, 1003static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
1004 u32 v_retval, u8 *msg, u16 msglen) 1004 u32 v_retval, u8 *msg, u16 msglen)
1005{ 1005{
1006 struct i40e_pf *pf = vf->pf; 1006 struct i40e_pf *pf;
1007 struct i40e_hw *hw = &pf->hw; 1007 struct i40e_hw *hw;
1008 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id; 1008 int abs_vf_id;
1009 i40e_status aq_ret; 1009 i40e_status aq_ret;
1010 1010
1011 /* validate the request */
1012 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1013 return -EINVAL;
1014
1015 pf = vf->pf;
1016 hw = &pf->hw;
1017 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1018
1011 /* single place to detect unsuccessful return values */ 1019 /* single place to detect unsuccessful return values */
1012 if (v_retval) { 1020 if (v_retval) {
1013 vf->num_invalid_msgs++; 1021 vf->num_invalid_msgs++;
@@ -1928,10 +1936,10 @@ static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
1928{ 1936{
1929 struct i40e_hw *hw = &pf->hw; 1937 struct i40e_hw *hw = &pf->hw;
1930 struct i40e_vf *vf = pf->vf; 1938 struct i40e_vf *vf = pf->vf;
1931 int abs_vf_id;
1932 int i; 1939 int i;
1933 1940
1934 for (i = 0; i < pf->num_alloc_vfs; i++) { 1941 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
1942 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1935 /* Not all vfs are enabled so skip the ones that are not */ 1943 /* Not all vfs are enabled so skip the ones that are not */
1936 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) && 1944 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
1937 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) 1945 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
@@ -1940,10 +1948,8 @@ static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
1940 /* Ignore return value on purpose - a given VF may fail, but 1948 /* Ignore return value on purpose - a given VF may fail, but
1941 * we need to keep going and send to all of them 1949 * we need to keep going and send to all of them
1942 */ 1950 */
1943 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1944 i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval, 1951 i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
1945 msg, msglen, NULL); 1952 msg, msglen, NULL);
1946 vf++;
1947 } 1953 }
1948} 1954}
1949 1955
@@ -1959,12 +1965,12 @@ void i40e_vc_notify_link_state(struct i40e_pf *pf)
1959 struct i40e_hw *hw = &pf->hw; 1965 struct i40e_hw *hw = &pf->hw;
1960 struct i40e_vf *vf = pf->vf; 1966 struct i40e_vf *vf = pf->vf;
1961 struct i40e_link_status *ls = &pf->hw.phy.link_info; 1967 struct i40e_link_status *ls = &pf->hw.phy.link_info;
1962 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1963 int i; 1968 int i;
1964 1969
1965 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE; 1970 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
1966 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO; 1971 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
1967 for (i = 0; i < pf->num_alloc_vfs; i++) { 1972 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
1973 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1968 if (vf->link_forced) { 1974 if (vf->link_forced) {
1969 pfe.event_data.link_event.link_status = vf->link_up; 1975 pfe.event_data.link_event.link_status = vf->link_up;
1970 pfe.event_data.link_event.link_speed = 1976 pfe.event_data.link_event.link_speed =
@@ -1977,8 +1983,6 @@ void i40e_vc_notify_link_state(struct i40e_pf *pf)
1977 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT, 1983 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
1978 0, (u8 *)&pfe, sizeof(pfe), 1984 0, (u8 *)&pfe, sizeof(pfe),
1979 NULL); 1985 NULL);
1980 vf++;
1981 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1982 } 1986 }
1983} 1987}
1984 1988
@@ -2009,6 +2013,10 @@ void i40e_vc_notify_vf_reset(struct i40e_vf *vf)
2009 struct i40e_virtchnl_pf_event pfe; 2013 struct i40e_virtchnl_pf_event pfe;
2010 int abs_vf_id; 2014 int abs_vf_id;
2011 2015
2016 /* validate the request */
2017 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
2018 return;
2019
2012 /* verify if the VF is in either init or active before proceeding */ 2020 /* verify if the VF is in either init or active before proceeding */
2013 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) && 2021 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
2014 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) 2022 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))