Skip to contentSkip to conversation

usnic: avoid overly large buffers on stack

PATCH Applied Arnd Bergmann 2 participants 2 messages Sep 6, 2019 – Sep 12, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usnic: avoid overly large buffers on stack

It's never a good idea to put a 1000-byte buffer on the kernel stack. The compiler warns about this instance when usnic_ib_log_vf() gets inlined into usnic_ib_pci_probe():

drivers/infiniband/hw/usnic/usnic_ib_main.c:543:12: error: stack frame size of 1044 bytes in function 'usnic_ib_pci_probe' [-Werror,-Wframe-larger-than=]

As this is only called for debugging purposes in the setup path, it's trivial to convert to a dynamic allocation.

---
 drivers/infiniband/hw/usnic/usnic_ib_main.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/infiniband/hw/usnic/usnic_ib_main.c +8 -2
index 03f54eb9404b..c9abe1c01e4e 100644
@@ -89,9 +89,15 @@ static void usnic_ib_dump_vf(struct usnic_ib_vf *vf, char *buf, int buf_sz)
 
 void usnic_ib_log_vf(struct usnic_ib_vf *vf)
 {
-	char buf[1000];
-	usnic_ib_dump_vf(vf, buf, sizeof(buf));
+	char *buf = kzalloc(1000, GFP_KERNEL);
+
+	if (!buf)
+		return;
+
+	usnic_ib_dump_vf(vf, buf, 1000);
 	usnic_dbg("%s\n", buf);
+
+	kfree(buf);
 }
 
 /* Start of netdev section */
Signature · 1 line
2.20.0
#1 lore raw
Quoted 6 lines · Arnd Bergmann

It's never a good idea to put a 1000-byte buffer on the kernel stack. The compiler warns about this instance when usnic_ib_log_vf() gets inlined into usnic_ib_pci_probe():

drivers/infiniband/hw/usnic/usnic_ib_main.c:543:12: error: stack frame size of 1044 bytes in function 'usnic_ib_pci_probe' [-Werror,-Wframe-larger-than=]

Quoted 7 lines

As this is only called for debugging purposes in the setup path, it's trivial to convert to a dynamic allocation.

---
 drivers/infiniband/hw/usnic/usnic_ib_main.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Applied to for-next, thanks

Jason