[PATCH] gianfar: reduce stack usage in gianfar_ethtool.c

Subsystems: networking drivers, the rest

STALE5550d

3 messages, 2 authors, 2011-08-09 · open the first message on its own page

[PATCH] gianfar: reduce stack usage in gianfar_ethtool.c

From: <hidden>
Date: 2011-08-09 15:22:21

From: Wang Shaoyan <redacted>

  drivers/net/gianfar_ethtool.c:765: warning: the frame size of 2048 bytes is larger than 1024 bytes

Signed-off-by: Wang Shaoyan <redacted>
---
 drivers/net/gianfar_ethtool.c |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/net/gianfar_ethtool.c b/drivers/net/gianfar_ethtool.c
index 6e35069..039e9c3 100644
--- a/drivers/net/gianfar_ethtool.c
+++ b/drivers/net/gianfar_ethtool.c
@@ -686,10 +686,26 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, u
 {
 	unsigned int last_rule_idx = priv->cur_filer_idx;
 	unsigned int cmp_rqfpr;
-	unsigned int local_rqfpr[MAX_FILER_IDX + 1];
-	unsigned int local_rqfcr[MAX_FILER_IDX + 1];
+	unsigned int *local_rqfpr;
+	unsigned int *local_rqfcr;
 	int i = 0x0, k = 0x0;
 	int j = MAX_FILER_IDX, l = 0x0;
+	int ret = 1;
+
+	local_rqfpr = kmalloc(sizeof(unsigned int) * (MAX_FILER_IDX + 1),
+		GFP_KERNEL);
+	if (local_rqfpr) {
+		pr_err("Out of memory\n");
+		ret = 0;
+		got err;
+	}
+	local_rqfcr = kmalloc(sizeof(unsigned int) * (MAX_FILER_IDX + 1),
+		GFP_KERNEL);
+	if (local_rqfcr) {
+		pr_err("Out of memory\n");
+		ret = 0;
+		goto err1;
+	}
 
 	switch (class) {
 	case TCP_V4_FLOW:
@@ -765,7 +781,11 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, u
 		priv->cur_filer_idx = priv->cur_filer_idx - 1;
 	}
 
-	return 1;
+	kfree(local_rqfcr);
+err1:
+	kfree(local_rqfpr);
+err:
+	return ret;
 }
 
 static int gfar_set_hash_opts(struct gfar_private *priv, struct ethtool_rxnfc *cmd)
-- 
1.7.0.4

Re: [PATCH] gianfar: reduce stack usage in gianfar_ethtool.c

From: Eric Dumazet <hidden>
Date: 2011-08-09 15:43:47

Le mardi 09 août 2011 à 23:18 +0800, stufever@gmail.com a écrit :
quoted hunk
From: Wang Shaoyan <redacted>

  drivers/net/gianfar_ethtool.c:765: warning: the frame size of 2048 bytes is larger than 1024 bytes

Signed-off-by: Wang Shaoyan <redacted>
---
 drivers/net/gianfar_ethtool.c |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/net/gianfar_ethtool.c b/drivers/net/gianfar_ethtool.c
index 6e35069..039e9c3 100644
--- a/drivers/net/gianfar_ethtool.c
+++ b/drivers/net/gianfar_ethtool.c
@@ -686,10 +686,26 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, u
 {
 	unsigned int last_rule_idx = priv->cur_filer_idx;
 	unsigned int cmp_rqfpr;
-	unsigned int local_rqfpr[MAX_FILER_IDX + 1];
-	unsigned int local_rqfcr[MAX_FILER_IDX + 1];
+	unsigned int *local_rqfpr;
+	unsigned int *local_rqfcr;
 	int i = 0x0, k = 0x0;
 	int j = MAX_FILER_IDX, l = 0x0;
+	int ret = 1;
+
+	local_rqfpr = kmalloc(sizeof(unsigned int) * (MAX_FILER_IDX + 1),
+		GFP_KERNEL);
+	if (local_rqfpr) {
	if (!local_rqfpr) {
quoted hunk
+		pr_err("Out of memory\n");
+		ret = 0;
+		got err;
+	}
+	local_rqfcr = kmalloc(sizeof(unsigned int) * (MAX_FILER_IDX + 1),
+		GFP_KERNEL);
+	if (local_rqfcr) {
same here : if (!local_rqfcr) ...
quoted hunk
+		pr_err("Out of memory\n");
+		ret = 0;
+		goto err1;
+	}
 
 	switch (class) {
 	case TCP_V4_FLOW:
@@ -765,7 +781,11 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, u
 		priv->cur_filer_idx = priv->cur_filer_idx - 1;
 	}
 
-	return 1;
+	kfree(local_rqfcr);
+err1:
+	kfree(local_rqfpr);
+err:
+	return ret;
 }
 
 static int gfar_set_hash_opts(struct gfar_private *priv, struct ethtool_rxnfc *cmd)

Re: [PATCH] gianfar: reduce stack usage in gianfar_ethtool.c

From: Wang Shaoyan <hidden>
Date: 2011-08-09 16:02:06

Thanks, I'm sorry to my careless.

2011/8/9 Eric Dumazet [off-list ref]:
Le mardi 09 août 2011 à 23:18 +0800, stufever@gmail.com a écrit :
quoted
From: Wang Shaoyan <redacted>

  drivers/net/gianfar_ethtool.c:765: warning: the frame size of 2048 bytes is larger than 1024 bytes

Signed-off-by: Wang Shaoyan <redacted>
---
 drivers/net/gianfar_ethtool.c |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/net/gianfar_ethtool.c b/drivers/net/gianfar_ethtool.c
index 6e35069..039e9c3 100644
--- a/drivers/net/gianfar_ethtool.c
+++ b/drivers/net/gianfar_ethtool.c
@@ -686,10 +686,26 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, u
 {
      unsigned int last_rule_idx = priv->cur_filer_idx;
      unsigned int cmp_rqfpr;
-     unsigned int local_rqfpr[MAX_FILER_IDX + 1];
-     unsigned int local_rqfcr[MAX_FILER_IDX + 1];
+     unsigned int *local_rqfpr;
+     unsigned int *local_rqfcr;
      int i = 0x0, k = 0x0;
      int j = MAX_FILER_IDX, l = 0x0;
+     int ret = 1;
+
+     local_rqfpr = kmalloc(sizeof(unsigned int) * (MAX_FILER_IDX + 1),
+             GFP_KERNEL);
+     if (local_rqfpr) {
       if (!local_rqfpr) {
quoted
+             pr_err("Out of memory\n");
+             ret = 0;
+             got err;
+     }
+     local_rqfcr = kmalloc(sizeof(unsigned int) * (MAX_FILER_IDX + 1),
+             GFP_KERNEL);
+     if (local_rqfcr) {
same here : if (!local_rqfcr) ...
quoted
+             pr_err("Out of memory\n");
+             ret = 0;
+             goto err1;
+     }

      switch (class) {
      case TCP_V4_FLOW:
@@ -765,7 +781,11 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, u
              priv->cur_filer_idx = priv->cur_filer_idx - 1;
      }

-     return 1;
+     kfree(local_rqfcr);
+err1:
+     kfree(local_rqfpr);
+err:
+     return ret;
 }

 static int gfar_set_hash_opts(struct gfar_private *priv, struct ethtool_rxnfc *cmd)


-- 
Wang Shaoyan
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help