Linux-RDMA Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] usnic: avoid overly large buffers on stack
@ 2019-09-06 15:57 Arnd Bergmann
  2019-09-12 13:47 ` Jason Gunthorpe
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2019-09-06 15:57 UTC (permalink / raw)
  To: Christian Benvenuti, Nelson Escobar, Parvi Kaustubhi,
	Doug Ledford, Jason Gunthorpe
  Cc: Arnd Bergmann, Leon Romanovsky, Gal Pressman, Parav Pandit,
	Davidlohr Bueso, Kamal Heib, Florian Westphal, linux-rdma,
	linux-kernel

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/infiniband/hw/usnic/usnic_ib_main.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/usnic/usnic_ib_main.c b/drivers/infiniband/hw/usnic/usnic_ib_main.c
index 03f54eb9404b..c9abe1c01e4e 100644
--- a/drivers/infiniband/hw/usnic/usnic_ib_main.c
+++ b/drivers/infiniband/hw/usnic/usnic_ib_main.c
@@ -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 */
-- 
2.20.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-06 15:57 [PATCH] usnic: avoid overly large buffers on stack Arnd Bergmann
2019-09-12 13:47 ` Jason Gunthorpe

Linux-RDMA Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rdma/0 linux-rdma/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rdma linux-rdma/ https://lore.kernel.org/linux-rdma \
		linux-rdma@vger.kernel.org linux-rdma@archiver.kernel.org
	public-inbox-index linux-rdma

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rdma


AGPL code for this site: git clone https://public-inbox.org/ public-inbox