From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753363AbcHZMtv (ORCPT ); Fri, 26 Aug 2016 08:49:51 -0400 Received: from mout.web.de ([212.227.17.11]:62633 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751976AbcHZMtt (ORCPT ); Fri, 26 Aug 2016 08:49:49 -0400 Subject: [PATCH 1/8] cris-cryptocop: Use kmalloc_array() in two functions To: linux-cris-kernel@axis.com, Adam Buchbinder , Dave Hansen , Ingo Molnar , Jesper Nilsson , Jiri Kosina , Mikael Starvik , Thomas Gleixner References: <566ABCD9.1060404@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall , Paolo Bonzini From: SF Markus Elfring Message-ID: Date: Fri, 26 Aug 2016 14:48:06 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:eg4KDN6RVOhVocKNWqWYLdV9wSFYeH8iftelI6cAUbnmlQTxgDq +v5b53Jy16ykInYx+yGewIuETJY8MeGp52o7N2m34IeO3SjbcyfO355tSRXk3qGMHct82X2 CjWQb38xvptxKD6M3IFJ0YwFybkLd3IBBnKzFxiSvFR5MdAyzeqtaViVhuveUTBxqKgtGL6 +dKMCghwK8EeJpA8md2dw== X-UI-Out-Filterresults: notjunk:1;V01:K0:uHe2O7Fk7y8=:0fOt4G/USMKMErQ5DqCXHN 2eml1f5+Yrsig5/0YBJG6AAIYWeZ9RpJxM+aoFFbVeF7De/D3t4v8Jz/OqwrHpNhL5E/VYIBB i+5gueL2pCIT6LydeEpgmDk+mGewpw0Gr6PDZtqE28lVl6VOsseXdZTb1Gue2DfUR/gPoY8RQ nuEGOkDJFk0Lp+GVpKZIgHR1JgppQpB+TCyLT9wNZFwu6n82rMb0yVskRvcdAIYBkL1B1z0zU wOMs70hKDdirV1J/ZnOnedP/qEvGwCJ+oNeJVaeUSLmDrhu/2cV3QM24RkJ/lOmLrc6YnWWE0 KqNdB2mCaXZDY0i96Us9gVUIK2lC/vKJbzb0vocCcr3R1E4Rxm4VwAkYP0Vw+CAIsMP8n2QDu RCPeRo2RUvBAvbyjDkKRFAtp9V+78XXbduxaohDWtPy2DRUPCDKkyiAeBz2+7I1HzLJqpKzpn I3VYPToc/EiupF7IkatntBA+46Qj0aGMI9a5abvq0yAeIZjPdbyDeZWdRZJmx0GhUB5THjF21 mm/LxEj7lignLudhIr3aTfP9oNYmbvu1MenFJYdPdvJhdfvi8qJ2fXm8dyvAUPrYudxWLcxyo beKANh8ZUd9n7bKJUnGt/Wy0XPLvkMwtSNCXRfYtliqS6ZfmzFvuutpD76L+NEhs8J8eHnblK OHPMz8Q7MCyRrdkuDxfiPshoFEOF9SGvbyNmWGBy49ZZzRVLRgbJ492KXG1NnYHO2MoZIW+gL UMyFgkEugbtL1zrcbqTUHpQgM1K+ngdWC4BUBVMGztiRbSygOa1FxQFnDcqoG6oGeXiAvODPS 4rH1HL7 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Markus Elfring Date: Thu, 25 Aug 2016 22:11:44 +0200 * Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array". This issue was detected by using the Coccinelle software. * Replace the specifications of data structures by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring --- arch/cris/arch-v32/drivers/cryptocop.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/cris/arch-v32/drivers/cryptocop.c b/arch/cris/arch-v32/drivers/cryptocop.c index 2081d8b..1632abc 100644 --- a/arch/cris/arch-v32/drivers/cryptocop.c +++ b/arch/cris/arch-v32/drivers/cryptocop.c @@ -1532,7 +1532,9 @@ int cryptocop_new_session(cryptocop_session_id *sid, struct cryptocop_transform_ return -ENOMEM; } - sess->tfrm_ctx = kmalloc(no_tfrms * sizeof(struct cryptocop_transform_ctx), alloc_flag); + sess->tfrm_ctx = kmalloc_array(no_tfrms, + sizeof(*sess->tfrm_ctx), + alloc_flag); if (!sess->tfrm_ctx) { DEBUG_API(printk("cryptocop_new_session, kmalloc cryptocop_transform_ctx\n")); kfree(sess); @@ -2697,7 +2699,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig /* Map user pages for in and out data of the operation. */ noinpages = (((unsigned long int)(oper.indata + prev_ix) & ~PAGE_MASK) + oper.inlen - 1 - prev_ix + ~PAGE_MASK) >> PAGE_SHIFT; DEBUG(printk("cryptocop_ioctl_process: noinpages=%d\n", noinpages)); - inpages = kmalloc(noinpages * sizeof(struct page*), GFP_KERNEL); + inpages = kmalloc_array(noinpages, sizeof(*inpages), GFP_KERNEL); if (!inpages){ DEBUG_API(printk("cryptocop_ioctl_process: kmalloc inpages\n")); nooutpages = noinpages = 0; @@ -2707,7 +2709,9 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig if (oper.do_cipher){ nooutpages = (((unsigned long int)oper.cipher_outdata & ~PAGE_MASK) + oper.cipher_outlen - 1 + ~PAGE_MASK) >> PAGE_SHIFT; DEBUG(printk("cryptocop_ioctl_process: nooutpages=%d\n", nooutpages)); - outpages = kmalloc(nooutpages * sizeof(struct page*), GFP_KERNEL); + outpages = kmalloc_array(nooutpages, + sizeof(*outpages), + GFP_KERNEL); if (!outpages){ DEBUG_API(printk("cryptocop_ioctl_process: kmalloc outpages\n")); nooutpages = noinpages = 0; @@ -2753,8 +2757,12 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig /* Add 6 to nooutpages to make room for possibly inserted buffers for storing digest and * csum output and splits when units are (dis-)connected. */ - cop->tfrm_op.indata = kmalloc((noinpages) * sizeof(struct iovec), GFP_KERNEL); - cop->tfrm_op.outdata = kmalloc((6 + nooutpages) * sizeof(struct iovec), GFP_KERNEL); + cop->tfrm_op.indata = kmalloc_array(noinpages, + sizeof(*cop->tfrm_op.indata), + GFP_KERNEL); + cop->tfrm_op.outdata = kmalloc_array(6 + nooutpages, + sizeof(*cop->tfrm_op.outdata), + GFP_KERNEL); if (!cop->tfrm_op.indata || !cop->tfrm_op.outdata) { DEBUG_API(printk("cryptocop_ioctl_process: kmalloc iovecs\n")); err = -ENOMEM; -- 2.9.3