提交 e8589118 编写于 作者: P Peter Waskiewicz 提交者: David S. Miller

ethtool: Fix filter addition when caching n-tuple filters

We can allow a filter to be added successfully to the underlying
hardware, but still return an error if the cached list memory
allocation fails.  This patch fixes that condition.
Signed-off-by: NPeter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>
Signed-off-by: NJeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 02b1bae5
...@@ -283,18 +283,17 @@ static int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr) ...@@ -283,18 +283,17 @@ static int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr)
return ret; return ret;
} }
static int __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list, static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
struct ethtool_rx_ntuple_flow_spec *spec) struct ethtool_rx_ntuple_flow_spec *spec,
struct ethtool_rx_ntuple_flow_spec_container *fsc)
{ {
struct ethtool_rx_ntuple_flow_spec_container *fsc;
/* don't add filters forever */ /* don't add filters forever */
if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
return 0; /* free the container */
kfree(fsc);
fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC); return;
if (!fsc) }
return -ENOMEM;
/* Copy the whole filter over */ /* Copy the whole filter over */
fsc->fs.flow_type = spec->flow_type; fsc->fs.flow_type = spec->flow_type;
...@@ -310,14 +309,13 @@ static int __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list, ...@@ -310,14 +309,13 @@ static int __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
/* add to the list */ /* add to the list */
list_add_tail_rcu(&fsc->list, &list->list); list_add_tail_rcu(&fsc->list, &list->list);
list->count++; list->count++;
return 0;
} }
static int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr) static int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr)
{ {
struct ethtool_rx_ntuple cmd; struct ethtool_rx_ntuple cmd;
const struct ethtool_ops *ops = dev->ethtool_ops; const struct ethtool_ops *ops = dev->ethtool_ops;
struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
int ret; int ret;
if (!ops->set_rx_ntuple) if (!ops->set_rx_ntuple)
...@@ -329,16 +327,26 @@ static int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr) ...@@ -329,16 +327,26 @@ static int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr)
if (copy_from_user(&cmd, useraddr, sizeof(cmd))) if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
return -EFAULT; return -EFAULT;
ret = ops->set_rx_ntuple(dev, &cmd);
/* /*
* Cache filter in dev struct for GET operation only if * Cache filter in dev struct for GET operation only if
* the underlying driver doesn't have its own GET operation, and * the underlying driver doesn't have its own GET operation, and
* only if the filter was added successfully. * only if the filter was added successfully. First make sure we
* can allocate the filter, then continue if successful.
*/ */
if (!ops->get_rx_ntuple && !ret) if (!ops->get_rx_ntuple) {
if (__rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs)) fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
if (!fsc)
return -ENOMEM; return -ENOMEM;
}
ret = ops->set_rx_ntuple(dev, &cmd);
if (ret) {
kfree(fsc);
return ret;
}
if (!ops->get_rx_ntuple)
__rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册