Commit 181ad487 authored by Dimitris Lampridis's avatar Dimitris Lampridis

driver: respect stack frame limit

svec_fpga_app_init() declares too many local buffers that are allocated on the stack.

On some versions of GCC this is detected and reported, causing a warning that is promoted to an
error. Example:

svec-core-fpga.c:710:1: error: the frame size of 1968 bytes is larger than 1024 bytes
[-Werror=frame-larger-than=]

Since apparently it is not a very good idea to increase the stack frame size limit [1], the solution
implemented here is to switch to dynimically allocating the biggest buffer (struct resource res[]).

[1]: https://gcc.gnu.org/onlinedocs/gccint/Stack-Checking.html#Stack-Checking
"The maximum size of a stack frame, in bytes. GCC will generate probe instructions in non-leaf
functions to ensure at least this many bytes of stack are available. If a stack frame is larger than
this size, stack checking will not be reliable and GCC will issue a warning. The default is chosen
so that GCC only generates one instruction on most systems. You should normally not change the
default value of this macro."
Signed-off-by: Dimitris Lampridis's avatarDimitris Lampridis <dimitris.lampridis@cern.ch>
parent 9ec20cf1
......@@ -648,22 +648,26 @@ static int svec_fpga_app_init(struct svec_fpga *svec_fpga)
#define SVEC_FPGA_APP_RES_N (32 - SVEC_FPGA_APP_IRQ_BASE + 1)
struct vme_dev *vdev = to_vme_dev(svec_fpga->dev.parent);
unsigned int res_n = SVEC_FPGA_APP_RES_N;
struct resource res[SVEC_FPGA_APP_RES_N] = {
[0] = {
.name = "app-mem",
.flags = IORESOURCE_MEM,
},
};
struct resource *res;
struct platform_device *pdev;
struct irq_domain *vic_domain;
char app_name[SVEC_FPGA_APP_NAME_MAX];
unsigned long app_offset;
int err, fn = svec_fpga->function_nr;
int err = 0, fn = svec_fpga->function_nr;
res = kzalloc(SVEC_FPGA_APP_RES_N * sizeof(struct resource), GFP_KERNEL);
if (!res) {
return -ENOMEM;
}
res[0].name = "app-mem";
res[0].flags = IORESOURCE_MEM;
app_offset = svec_fpga_csr_app_offset(svec_fpga);
if (!app_offset) {
dev_warn(&svec_fpga->dev, "Application not found\n");
return 0;
err = 0;
goto err_free;
}
svec_fpga_metadata_get(&svec_fpga->meta_app,
......@@ -695,18 +699,21 @@ static int svec_fpga_app_init(struct svec_fpga *svec_fpga)
err = svec_fpga_app_id_build(svec_fpga, app_offset,
app_name, SVEC_FPGA_APP_NAME_MAX);
if (err)
return err;
goto err_free;
svec_fpga_app_restart(svec_fpga);
pdev = platform_device_register_resndata(&svec_fpga->dev,
app_name, PLATFORM_DEVID_AUTO,
res, res_n,
NULL, 0);
if (IS_ERR(pdev))
return PTR_ERR(pdev);
err = IS_ERR(pdev);
if (err)
goto err_free;
svec_fpga->app_pdev = pdev;
return 0;
err_free:
kfree(res);
return err;
}
static void svec_fpga_app_exit(struct svec_fpga *svec_fpga)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment