Commit e5187ee3 authored by Jacob Keller's avatar Jacob Keller Committed by Jeff Kirsher

i40e: return immediately when failing to add fdir filter

Instead of setting err=true and checking this to determine when to free
the raw_packet near the end of the function, simply kfree and return
immediately. The resulting code is a bit cleaner and has one less
variable. This also resolves a subtle bug in the ipv4 case which could
fail to add the first filter and then never free the memory, resulting
in a small memory leak.

Change-ID: I7583aac033481dc794b4acaa14445059c8930ff1
Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Reviewed-by: default avatarAvinash Dayanand <avinash.dayanand@intel.com>
Reviewed-by: default avatarAlan Brady <alan.brady@intel.com>
Reviewed-by: default avatarMitch Williams <mitch.a.williams@intel.com>
Tested-by: default avatarAndrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
parent 01016da1
...@@ -203,7 +203,6 @@ static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi, ...@@ -203,7 +203,6 @@ static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi,
struct i40e_pf *pf = vsi->back; struct i40e_pf *pf = vsi->back;
struct udphdr *udp; struct udphdr *udp;
struct iphdr *ip; struct iphdr *ip;
bool err = false;
u8 *raw_packet; u8 *raw_packet;
int ret; int ret;
static char packet[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0, static char packet[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0,
...@@ -230,7 +229,9 @@ static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi, ...@@ -230,7 +229,9 @@ static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi,
dev_info(&pf->pdev->dev, dev_info(&pf->pdev->dev,
"PCTYPE:%d, Filter command send failed for fd_id:%d (ret = %d)\n", "PCTYPE:%d, Filter command send failed for fd_id:%d (ret = %d)\n",
fd_data->pctype, fd_data->fd_id, ret); fd_data->pctype, fd_data->fd_id, ret);
err = true; /* Free the packet buffer since it wasn't added to the ring */
kfree(raw_packet);
return -EOPNOTSUPP;
} else if (I40E_DEBUG_FD & pf->hw.debug_mask) { } else if (I40E_DEBUG_FD & pf->hw.debug_mask) {
if (add) if (add)
dev_info(&pf->pdev->dev, dev_info(&pf->pdev->dev,
...@@ -241,10 +242,8 @@ static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi, ...@@ -241,10 +242,8 @@ static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi,
"Filter deleted for PCTYPE %d loc = %d\n", "Filter deleted for PCTYPE %d loc = %d\n",
fd_data->pctype, fd_data->fd_id); fd_data->pctype, fd_data->fd_id);
} }
if (err)
kfree(raw_packet);
return err ? -EOPNOTSUPP : 0; return 0;
} }
#define I40E_TCPIP_DUMMY_PACKET_LEN 54 #define I40E_TCPIP_DUMMY_PACKET_LEN 54
...@@ -263,7 +262,6 @@ static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi, ...@@ -263,7 +262,6 @@ static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi,
struct i40e_pf *pf = vsi->back; struct i40e_pf *pf = vsi->back;
struct tcphdr *tcp; struct tcphdr *tcp;
struct iphdr *ip; struct iphdr *ip;
bool err = false;
u8 *raw_packet; u8 *raw_packet;
int ret; int ret;
/* Dummy packet */ /* Dummy packet */
...@@ -305,12 +303,13 @@ static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi, ...@@ -305,12 +303,13 @@ static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi,
fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP; fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
ret = i40e_program_fdir_filter(fd_data, raw_packet, pf, add); ret = i40e_program_fdir_filter(fd_data, raw_packet, pf, add);
if (ret) { if (ret) {
dev_info(&pf->pdev->dev, dev_info(&pf->pdev->dev,
"PCTYPE:%d, Filter command send failed for fd_id:%d (ret = %d)\n", "PCTYPE:%d, Filter command send failed for fd_id:%d (ret = %d)\n",
fd_data->pctype, fd_data->fd_id, ret); fd_data->pctype, fd_data->fd_id, ret);
err = true; /* Free the packet buffer since it wasn't added to the ring */
kfree(raw_packet);
return -EOPNOTSUPP;
} else if (I40E_DEBUG_FD & pf->hw.debug_mask) { } else if (I40E_DEBUG_FD & pf->hw.debug_mask) {
if (add) if (add)
dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d loc = %d)\n", dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d loc = %d)\n",
...@@ -321,10 +320,7 @@ static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi, ...@@ -321,10 +320,7 @@ static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi,
fd_data->pctype, fd_data->fd_id); fd_data->pctype, fd_data->fd_id);
} }
if (err) return 0;
kfree(raw_packet);
return err ? -EOPNOTSUPP : 0;
} }
#define I40E_IP_DUMMY_PACKET_LEN 34 #define I40E_IP_DUMMY_PACKET_LEN 34
...@@ -343,7 +339,6 @@ static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi, ...@@ -343,7 +339,6 @@ static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi,
{ {
struct i40e_pf *pf = vsi->back; struct i40e_pf *pf = vsi->back;
struct iphdr *ip; struct iphdr *ip;
bool err = false;
u8 *raw_packet; u8 *raw_packet;
int ret; int ret;
int i; int i;
...@@ -365,12 +360,15 @@ static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi, ...@@ -365,12 +360,15 @@ static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi,
fd_data->pctype = i; fd_data->pctype = i;
ret = i40e_program_fdir_filter(fd_data, raw_packet, pf, add); ret = i40e_program_fdir_filter(fd_data, raw_packet, pf, add);
if (ret) { if (ret) {
dev_info(&pf->pdev->dev, dev_info(&pf->pdev->dev,
"PCTYPE:%d, Filter command send failed for fd_id:%d (ret = %d)\n", "PCTYPE:%d, Filter command send failed for fd_id:%d (ret = %d)\n",
fd_data->pctype, fd_data->fd_id, ret); fd_data->pctype, fd_data->fd_id, ret);
err = true; /* The packet buffer wasn't added to the ring so we
* need to free it now.
*/
kfree(raw_packet);
return -EOPNOTSUPP;
} else if (I40E_DEBUG_FD & pf->hw.debug_mask) { } else if (I40E_DEBUG_FD & pf->hw.debug_mask) {
if (add) if (add)
dev_info(&pf->pdev->dev, dev_info(&pf->pdev->dev,
...@@ -383,10 +381,7 @@ static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi, ...@@ -383,10 +381,7 @@ static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi,
} }
} }
if (err) return 0;
kfree(raw_packet);
return err ? -EOPNOTSUPP : 0;
} }
/** /**
......
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