[PATCH v3 7/7] staging: dgnc: tty.c: replaces kzalloc with kcalloc for arrays

Dan Carpenter dan.carpenter at oracle.com
Tue Sep 10 22:05:37 UTC 2013


This one is not right.

On Mon, Sep 09, 2013 at 03:01:28PM -0400, Lidza Louina wrote:
> This patch replaces kzalloc with kcalloc when using
> arrays. kcalloc is better suited for arrays because
> it has overflow protection.
> 
> Reported-by: Dan Carpenter <dan.carpenter at oracle.com>
> Signed-off-by: Lidza Louina <lidza.louina at gmail.com>
> ---
>  drivers/staging/dgnc/dgnc_tty.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
> index 07b79be..18705f9 100644
> --- a/drivers/staging/dgnc/dgnc_tty.c
> +++ b/drivers/staging/dgnc/dgnc_tty.c
> @@ -222,12 +222,12 @@ int dgnc_tty_register(struct dgnc_board *brd)
>  	 * The kernel wants space to store pointers to
>  	 * tty_struct's and termios's.
>  	 */
> -	brd->SerialDriver.ttys = kzalloc(brd->maxports * sizeof(*brd->SerialDriver.ttys), GFP_KERNEL);
> +	brd->SerialDriver.ttys = kcalloc(brd->SerialDriver.num, brd->maxports * sizeof(*brd->SerialDriver.ttys), GFP_KERNEL);


This should be:

	brd->SerialDriver.ttys = kcalloc(brd->maxports, sizeof(*brd->SerialDriver.ttys), GFP_KERNEL);

Btw, are you using vim with cscope set up?

make cscope
vim -t kcalloc
Move to the kmalloc_array() call and hit CTRL-]

regards,
dan carpenter



More information about the devel mailing list