ethtool: Update ethtool_rxnfc::rule_cnt on return from ETHTOOL_GRXCLSRLALL
authorBen Hutchings <bhutchings@solarflare.com>
Tue, 6 Sep 2011 13:52:47 +0000 (13:52 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 16 Sep 2011 23:25:10 +0000 (19:25 -0400)
A user-space process must use ETHTOOL_GRXCLSRLCNT to find the number
of classification rules, then allocate a buffer of the right size,
then use ETHTOOL_GRXCLSRLALL to fill the buffer.  If some other
process inserts or deletes a rule between those two operations,
the user buffer might turn out to be the wrong size.

If it's too small, the return value will be -EMSGSIZE.  But if it's
too large, there is no indication of this.  Fix this by updating
the rule_cnt field on return.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/freescale/gianfar_ethtool.c
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
drivers/net/ethernet/sun/niu.c
include/linux/ethtool.h

index 4223830..f30b96f 100644 (file)
@@ -1676,6 +1676,7 @@ static int gfar_get_cls_all(struct gfar_private *priv,
        }
 
        cmd->data = MAX_FILER_IDX;
        }
 
        cmd->data = MAX_FILER_IDX;
+       cmd->rule_cnt = i;
 
        return 0;
 }
 
        return 0;
 }
index c0003ba..b8410bc 100644 (file)
@@ -2283,6 +2283,8 @@ static int ixgbe_get_ethtool_fdir_all(struct ixgbe_adapter *adapter,
                cnt++;
        }
 
                cnt++;
        }
 
+       cmd->rule_cnt = cnt;
+
        return 0;
 }
 
        return 0;
 }
 
index 5e1e1d2..d133888 100644 (file)
@@ -7299,6 +7299,8 @@ static int niu_get_ethtool_tcam_all(struct niu *np,
        }
        niu_unlock_parent(np, flags);
 
        }
        niu_unlock_parent(np, flags);
 
+       nfc->rule_cnt = cnt;
+
        return ret;
 }
 
        return ret;
 }
 
index 5d4a06a..45f00b6 100644 (file)
@@ -496,9 +496,9 @@ struct ethtool_rx_flow_spec {
  *
  * For %ETHTOOL_GRXCLSRLALL, @rule_cnt specifies the array size of the
  * user buffer for @rule_locs on entry.  On return, @data is the size
  *
  * For %ETHTOOL_GRXCLSRLALL, @rule_cnt specifies the array size of the
  * user buffer for @rule_locs on entry.  On return, @data is the size
- * of the rule table and @rule_locs contains the locations of the
- * defined rules.  Drivers must use the second parameter to get_rxnfc()
- * instead of @rule_locs.
+ * of the rule table, @rule_cnt is the number of defined rules, and
+ * @rule_locs contains the locations of the defined rules.  Drivers
+ * must use the second parameter to get_rxnfc() instead of @rule_locs.
  *
  * For %ETHTOOL_SRXCLSRLINS, @fs specifies the rule to add or update.
  * @fs.@location specifies the location to use and must not be ignored.
  *
  * For %ETHTOOL_SRXCLSRLINS, @fs specifies the rule to add or update.
  * @fs.@location specifies the location to use and must not be ignored.