Skip to content

Commit aff1270

Browse files
arndbjonmason
authored andcommitted
ntb: reduce stack usage in idt_scan_mws
idt_scan_mws() puts a large fixed-size array on the stack and copies it into a smaller dynamically allocated array at the end. On 32-bit targets, the fixed size can easily exceed the warning limit for possible stack overflow: drivers/ntb/hw/idt/ntb_hw_idt.c:1041:27: error: stack frame size (1032) exceeds limit (1024) in 'idt_scan_mws' [-Werror,-Wframe-larger-than] Change it to instead just always use dynamic allocation for the array from the start. It's too big for the stack, but not actually all that much for a permanent allocation. Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/all/202205111109.PiKTruEj-lkp@intel.com/ Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Signed-off-by: Jon Mason <jdmason@kudzu.us>
1 parent fd5625f commit aff1270

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

drivers/ntb/hw/idt/ntb_hw_idt.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,14 +1041,19 @@ static inline char *idt_get_mw_name(enum idt_mw_type mw_type)
10411041
static struct idt_mw_cfg *idt_scan_mws(struct idt_ntb_dev *ndev, int port,
10421042
unsigned char *mw_cnt)
10431043
{
1044-
struct idt_mw_cfg mws[IDT_MAX_NR_MWS], *ret_mws;
1044+
struct idt_mw_cfg *mws;
10451045
const struct idt_ntb_bar *bars;
10461046
enum idt_mw_type mw_type;
10471047
unsigned char widx, bidx, en_cnt;
10481048
bool bar_64bit = false;
10491049
int aprt_size;
10501050
u32 data;
10511051

1052+
mws = devm_kcalloc(&ndev->ntb.pdev->dev, IDT_MAX_NR_MWS,
1053+
sizeof(*mws), GFP_KERNEL);
1054+
if (!mws)
1055+
return ERR_PTR(-ENOMEM);
1056+
10521057
/* Retrieve the array of the BARs registers */
10531058
bars = portdata_tbl[port].bars;
10541059

@@ -1103,16 +1108,7 @@ static struct idt_mw_cfg *idt_scan_mws(struct idt_ntb_dev *ndev, int port,
11031108
}
11041109
}
11051110

1106-
/* Allocate memory for memory window descriptors */
1107-
ret_mws = devm_kcalloc(&ndev->ntb.pdev->dev, *mw_cnt, sizeof(*ret_mws),
1108-
GFP_KERNEL);
1109-
if (!ret_mws)
1110-
return ERR_PTR(-ENOMEM);
1111-
1112-
/* Copy the info of detected memory windows */
1113-
memcpy(ret_mws, mws, (*mw_cnt)*sizeof(*ret_mws));
1114-
1115-
return ret_mws;
1111+
return mws;
11161112
}
11171113

11181114
/*

0 commit comments

Comments
 (0)