From ba8e0a401457a03755c2a6538d209ef7ffdf6840 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Wed, 24 Mar 2010 12:19:30 +0000 Subject: [PATCH] serial2002: Reduce stack usage in serial_2002_open() by allocating dig_in_config, dig_out_config, chan_in_config and chan_out_config arrays using kcalloc(). --- comedi/drivers/serial2002.c | 47 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/comedi/drivers/serial2002.c b/comedi/drivers/serial2002.c index 974f0a1c..3bb3c457 100644 --- a/comedi/drivers/serial2002.c +++ b/comedi/drivers/serial2002.c @@ -407,29 +407,21 @@ static int serial_2002_open(comedi_device * dev) int min; int max; } config_t; - config_t dig_in_config[32]; - config_t dig_out_config[32]; - config_t chan_in_config[32]; - config_t chan_out_config[32]; + config_t *dig_in_config; + config_t *dig_out_config; + config_t *chan_in_config; + config_t *chan_out_config; int i; - for (i = 0; i < 32; i++) { - dig_in_config[i].kind = 0; - dig_in_config[i].bits = 0; - dig_in_config[i].min = 0; - dig_in_config[i].max = 0; - dig_out_config[i].kind = 0; - dig_out_config[i].bits = 0; - dig_out_config[i].min = 0; - dig_out_config[i].max = 0; - chan_in_config[i].kind = 0; - chan_in_config[i].bits = 0; - chan_in_config[i].min = 0; - chan_in_config[i].max = 0; - chan_out_config[i].kind = 0; - chan_out_config[i].bits = 0; - chan_out_config[i].min = 0; - chan_out_config[i].max = 0; + result = 0; + dig_in_config = kcalloc(32, sizeof(config_t), GFP_KERNEL); + dig_out_config = kcalloc(32, sizeof(config_t), GFP_KERNEL); + chan_in_config = kcalloc(32, sizeof(config_t), GFP_KERNEL); + chan_out_config = kcalloc(32, sizeof(config_t), GFP_KERNEL); + if (!dig_in_config || !dig_out_config + || !chan_in_config || !chan_out_config) { + result = -ENOMEM; + goto err_alloc_configs; } tty_setspeed(devpriv->tty, devpriv->speed); @@ -652,7 +644,17 @@ static int serial_2002_open(comedi_device * dev) } } } - result = 0; +err_alloc_configs: + kfree(dig_in_config); + kfree(dig_out_config); + kfree(chan_in_config); + kfree(chan_out_config); + if (result) { + if (devpriv->tty) { + filp_close(devpriv->tty, 0); + devpriv->tty = NULL; + } + } } return result; } @@ -661,6 +663,7 @@ static void serial_2002_close(comedi_device * dev) { if (!IS_ERR(devpriv->tty) && (devpriv->tty != 0)) { filp_close(devpriv->tty, 0); + devpriv->tty = NULL; } } -- 2.26.2