diff mbox series

[net-next] airo: work around stack usage warning

Message ID 20210323131634.2669455-1-arnd@kernel.org (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [net-next] airo: work around stack usage warning | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 1 maintainers not CCed: edumazet@google.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 61 this patch: 61
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch fail CHECK: Please don't use multiple blank lines CHECK: Unbalanced braces around else statement ERROR: "(foo*)" should be "(foo *)" ERROR: do not use assignment in if condition ERROR: else should follow close brace '}' ERROR: trailing statements should be on next line WARNING: Block comments use * on subsequent lines WARNING: Block comments use a trailing */ on a separate line WARNING: braces {} are not necessary for single statement blocks WARNING: line length of 81 exceeds 80 columns WARNING: line length of 86 exceeds 80 columns WARNING: line length of 95 exceeds 80 columns WARNING: quoted string split across lines WARNING: space prohibited between function name and open parenthesis '('
netdev/build_allmodconfig_warn success Errors and warnings before: 61 this patch: 61
netdev/header_inline success Link

Commit Message

Arnd Bergmann March 23, 2021, 1:16 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

gcc-11 with KASAN on 32-bit arm produces a warning about a function
that needs a lot of stack space:

drivers/net/wireless/cisco/airo.c: In function 'setup_card.constprop':
drivers/net/wireless/cisco/airo.c:3960:1: error: the frame size of 1512 bytes is larger than 1400 bytes [-Werror=frame-larger-than=]

Most of this is from a single large structure that could be dynamically
allocated or moved into the per-device structure.  However, as the callers
all seem to have a fairly well bounded call chain, the easiest change
is to pull out the part of the function that needs the large variables
into a separate function and mark that as noinline_for_stack. This does
not reduce the total stack usage, but it gets rid of the warning and
requires minimal changes otherwise.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/wireless/cisco/airo.c | 117 +++++++++++++++++-------------
 1 file changed, 65 insertions(+), 52 deletions(-)

Comments

Tom Rix March 23, 2021, 3:03 p.m. UTC | #1
On 3/23/21 6:16 AM, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> gcc-11 with KASAN on 32-bit arm produces a warning about a function
> that needs a lot of stack space:
>
> drivers/net/wireless/cisco/airo.c: In function 'setup_card.constprop':
> drivers/net/wireless/cisco/airo.c:3960:1: error: the frame size of 1512 bytes is larger than 1400 bytes [-Werror=frame-larger-than=]
>
> Most of this is from a single large structure that could be dynamically
> allocated or moved into the per-device structure.  However, as the callers
> all seem to have a fairly well bounded call chain, the easiest change
> is to pull out the part of the function that needs the large variables
> into a separate function and mark that as noinline_for_stack. This does
> not reduce the total stack usage, but it gets rid of the warning and
> requires minimal changes otherwise.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/net/wireless/cisco/airo.c | 117 +++++++++++++++++-------------
>  1 file changed, 65 insertions(+), 52 deletions(-)
>
> diff --git a/drivers/net/wireless/cisco/airo.c b/drivers/net/wireless/cisco/airo.c
> index e35e1380ae43..540ba694899c 100644
> --- a/drivers/net/wireless/cisco/airo.c
> +++ b/drivers/net/wireless/cisco/airo.c
> @@ -3818,6 +3818,68 @@ static inline void set_auth_type(struct airo_info *local, int auth_type)
>  		local->last_auth = auth_type;
>  }
>  
> +static int noinline_for_stack airo_readconfig(struct airo_info *ai, u8 *mac, int lock)
> +{
> +	int i, status;
> +	/* large variables, so don't inline this function,
> +	 * maybe change to kmalloc
> +	 */
> +	tdsRssiRid rssi_rid;
> +	CapabilityRid cap_rid;
> +
> +	kfree(ai->SSID);
> +	ai->SSID = NULL;
> +	// general configuration (read/modify/write)
> +	status = readConfigRid(ai, lock);
> +	if (status != SUCCESS) return ERROR;
> +
> +	status = readCapabilityRid(ai, &cap_rid, lock);
> +	if (status != SUCCESS) return ERROR;
> +
> +	status = PC4500_readrid(ai, RID_RSSI, &rssi_rid, sizeof(rssi_rid), lock);
> +	if (status == SUCCESS) {
> +		if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
> +			memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */
> +	}
> +	else {
> +		kfree(ai->rssi);
> +		ai->rssi = NULL;
> +		if (cap_rid.softCap & cpu_to_le16(8))
> +			ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
> +		else
> +			airo_print_warn(ai->dev->name, "unknown received signal "
> +					"level scale");
> +	}
> +	ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
> +	set_auth_type(ai, AUTH_OPEN);
> +	ai->config.modulation = MOD_CCK;
> +
> +	if (le16_to_cpu(cap_rid.len) >= sizeof(cap_rid) &&
> +	    (cap_rid.extSoftCap & cpu_to_le16(1)) &&
> +	    micsetup(ai) == SUCCESS) {
> +		ai->config.opmode |= MODE_MIC;
> +		set_bit(FLAG_MIC_CAPABLE, &ai->flags);
> +	}
> +
> +	/* Save off the MAC */
> +	for (i = 0; i < ETH_ALEN; i++) {
> +		mac[i] = ai->config.macAddr[i];
> +	}
> +
> +	/* Check to see if there are any insmod configured
> +	   rates to add */
> +	if (rates[0]) {
> +		memset(ai->config.rates, 0, sizeof(ai->config.rates));
> +		for (i = 0; i < 8 && rates[i]; i++) {
> +			ai->config.rates[i] = rates[i];
> +		}
> +	}
> +	set_bit (FLAG_COMMIT, &ai->flags);
> +
> +	return SUCCESS;
> +}
> +
> +
>  static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
>  {
>  	Cmd cmd;
> @@ -3864,58 +3926,9 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
>  	if (lock)
>  		up(&ai->sem);
>  	if (ai->config.len == 0) {
> -		int i;
> -		tdsRssiRid rssi_rid;
This is mostly an array, and what I guess is the problem.
> -		CapabilityRid cap_rid;
> -
> -		kfree(ai->SSID);
> -		ai->SSID = NULL;
> -		// general configuration (read/modify/write)
> -		status = readConfigRid(ai, lock);
> -		if (status != SUCCESS) return ERROR;
> -
> -		status = readCapabilityRid(ai, &cap_rid, lock);
> -		if (status != SUCCESS) return ERROR;
> -
> -		status = PC4500_readrid(ai, RID_RSSI,&rssi_rid, sizeof(rssi_rid), lock);
This is reading into a stack temp
> -		if (status == SUCCESS) {
> -			if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
> -				memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */

Here is the temp being copied to heap memory.

This is the only use of rssi_rid

Why not do the alloc in PC4500_read ?

The call would be something like

status = PC4500_readrid(ai, RID_RSSI, &ai->rssi, sizeof(), lock)

or since ai, is common reduce the signature of the function and make the call

PC4500_readid(ai, RID_RSSI, lock)

Tom

> -		}
> -		else {
> -			kfree(ai->rssi);
> -			ai->rssi = NULL;
> -			if (cap_rid.softCap & cpu_to_le16(8))
> -				ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
> -			else
> -				airo_print_warn(ai->dev->name, "unknown received signal "
> -						"level scale");
> -		}
> -		ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
> -		set_auth_type(ai, AUTH_OPEN);
> -		ai->config.modulation = MOD_CCK;
> -
> -		if (le16_to_cpu(cap_rid.len) >= sizeof(cap_rid) &&
> -		    (cap_rid.extSoftCap & cpu_to_le16(1)) &&
> -		    micsetup(ai) == SUCCESS) {
> -			ai->config.opmode |= MODE_MIC;
> -			set_bit(FLAG_MIC_CAPABLE, &ai->flags);
> -		}
> -
> -		/* Save off the MAC */
> -		for (i = 0; i < ETH_ALEN; i++) {
> -			mac[i] = ai->config.macAddr[i];
> -		}
> -
> -		/* Check to see if there are any insmod configured
> -		   rates to add */
> -		if (rates[0]) {
> -			memset(ai->config.rates, 0, sizeof(ai->config.rates));
> -			for (i = 0; i < 8 && rates[i]; i++) {
> -				ai->config.rates[i] = rates[i];
> -			}
> -		}
> -		set_bit (FLAG_COMMIT, &ai->flags);
> +		status = airo_readconfig(ai, mac, lock);
> +		if (status != SUCCESS)
> +			return ERROR;
>  	}
>  
>  	/* Setup the SSIDs if present */
Kalle Valo April 17, 2021, 6:02 p.m. UTC | #2
Arnd Bergmann <arnd@kernel.org> wrote:

> From: Arnd Bergmann <arnd@arndb.de>
> 
> gcc-11 with KASAN on 32-bit arm produces a warning about a function
> that needs a lot of stack space:
> 
> drivers/net/wireless/cisco/airo.c: In function 'setup_card.constprop':
> drivers/net/wireless/cisco/airo.c:3960:1: error: the frame size of 1512 bytes is larger than 1400 bytes [-Werror=frame-larger-than=]
> 
> Most of this is from a single large structure that could be dynamically
> allocated or moved into the per-device structure.  However, as the callers
> all seem to have a fairly well bounded call chain, the easiest change
> is to pull out the part of the function that needs the large variables
> into a separate function and mark that as noinline_for_stack. This does
> not reduce the total stack usage, but it gets rid of the warning and
> requires minimal changes otherwise.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Patch applied to wireless-drivers-next.git, thanks.

7909a590eba6 airo: work around stack usage warning
diff mbox series

Patch

diff --git a/drivers/net/wireless/cisco/airo.c b/drivers/net/wireless/cisco/airo.c
index e35e1380ae43..540ba694899c 100644
--- a/drivers/net/wireless/cisco/airo.c
+++ b/drivers/net/wireless/cisco/airo.c
@@ -3818,6 +3818,68 @@  static inline void set_auth_type(struct airo_info *local, int auth_type)
 		local->last_auth = auth_type;
 }
 
+static int noinline_for_stack airo_readconfig(struct airo_info *ai, u8 *mac, int lock)
+{
+	int i, status;
+	/* large variables, so don't inline this function,
+	 * maybe change to kmalloc
+	 */
+	tdsRssiRid rssi_rid;
+	CapabilityRid cap_rid;
+
+	kfree(ai->SSID);
+	ai->SSID = NULL;
+	// general configuration (read/modify/write)
+	status = readConfigRid(ai, lock);
+	if (status != SUCCESS) return ERROR;
+
+	status = readCapabilityRid(ai, &cap_rid, lock);
+	if (status != SUCCESS) return ERROR;
+
+	status = PC4500_readrid(ai, RID_RSSI, &rssi_rid, sizeof(rssi_rid), lock);
+	if (status == SUCCESS) {
+		if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
+			memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */
+	}
+	else {
+		kfree(ai->rssi);
+		ai->rssi = NULL;
+		if (cap_rid.softCap & cpu_to_le16(8))
+			ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
+		else
+			airo_print_warn(ai->dev->name, "unknown received signal "
+					"level scale");
+	}
+	ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
+	set_auth_type(ai, AUTH_OPEN);
+	ai->config.modulation = MOD_CCK;
+
+	if (le16_to_cpu(cap_rid.len) >= sizeof(cap_rid) &&
+	    (cap_rid.extSoftCap & cpu_to_le16(1)) &&
+	    micsetup(ai) == SUCCESS) {
+		ai->config.opmode |= MODE_MIC;
+		set_bit(FLAG_MIC_CAPABLE, &ai->flags);
+	}
+
+	/* Save off the MAC */
+	for (i = 0; i < ETH_ALEN; i++) {
+		mac[i] = ai->config.macAddr[i];
+	}
+
+	/* Check to see if there are any insmod configured
+	   rates to add */
+	if (rates[0]) {
+		memset(ai->config.rates, 0, sizeof(ai->config.rates));
+		for (i = 0; i < 8 && rates[i]; i++) {
+			ai->config.rates[i] = rates[i];
+		}
+	}
+	set_bit (FLAG_COMMIT, &ai->flags);
+
+	return SUCCESS;
+}
+
+
 static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
 {
 	Cmd cmd;
@@ -3864,58 +3926,9 @@  static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
 	if (lock)
 		up(&ai->sem);
 	if (ai->config.len == 0) {
-		int i;
-		tdsRssiRid rssi_rid;
-		CapabilityRid cap_rid;
-
-		kfree(ai->SSID);
-		ai->SSID = NULL;
-		// general configuration (read/modify/write)
-		status = readConfigRid(ai, lock);
-		if (status != SUCCESS) return ERROR;
-
-		status = readCapabilityRid(ai, &cap_rid, lock);
-		if (status != SUCCESS) return ERROR;
-
-		status = PC4500_readrid(ai, RID_RSSI,&rssi_rid, sizeof(rssi_rid), lock);
-		if (status == SUCCESS) {
-			if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
-				memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */
-		}
-		else {
-			kfree(ai->rssi);
-			ai->rssi = NULL;
-			if (cap_rid.softCap & cpu_to_le16(8))
-				ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
-			else
-				airo_print_warn(ai->dev->name, "unknown received signal "
-						"level scale");
-		}
-		ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
-		set_auth_type(ai, AUTH_OPEN);
-		ai->config.modulation = MOD_CCK;
-
-		if (le16_to_cpu(cap_rid.len) >= sizeof(cap_rid) &&
-		    (cap_rid.extSoftCap & cpu_to_le16(1)) &&
-		    micsetup(ai) == SUCCESS) {
-			ai->config.opmode |= MODE_MIC;
-			set_bit(FLAG_MIC_CAPABLE, &ai->flags);
-		}
-
-		/* Save off the MAC */
-		for (i = 0; i < ETH_ALEN; i++) {
-			mac[i] = ai->config.macAddr[i];
-		}
-
-		/* Check to see if there are any insmod configured
-		   rates to add */
-		if (rates[0]) {
-			memset(ai->config.rates, 0, sizeof(ai->config.rates));
-			for (i = 0; i < 8 && rates[i]; i++) {
-				ai->config.rates[i] = rates[i];
-			}
-		}
-		set_bit (FLAG_COMMIT, &ai->flags);
+		status = airo_readconfig(ai, mac, lock);
+		if (status != SUCCESS)
+			return ERROR;
 	}
 
 	/* Setup the SSIDs if present */