From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-pa0-f44.google.com ([209.85.220.44]:34190 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753839AbbIQHtG (ORCPT ); Thu, 17 Sep 2015 03:49:06 -0400 Received: by padhy16 with SMTP id hy16so13429776pad.1 for ; Thu, 17 Sep 2015 00:49:06 -0700 (PDT) From: Chaehyun Lim To: gregkh@linuxfoundation.org Cc: johnny.kim@atmel.com, rachel.kim@atmel.com, chris.park@atmel.com, tony.cho@atmel.com, glen.lee@atmel.com, leo.kim@atmel.com, linux-wireless@vger.kernel.org, devel@driverdev.osuosl.org, Chaehyun Lim Subject: [PATCH V2 4/8] staging: wilc1000: linux_wlan_spi.c: fix kzalloc error check Date: Thu, 17 Sep 2015 16:48:45 +0900 Message-Id: <1442476129-14908-4-git-send-email-chaehyun.lim@gmail.com> (sfid-20150917_094909_870453_3EB0502C) In-Reply-To: <1442476129-14908-1-git-send-email-chaehyun.lim@gmail.com> References: <1442476129-14908-1-git-send-email-chaehyun.lim@gmail.com> Sender: linux-wireless-owner@vger.kernel.org List-ID: This patch fixes error check of kzalloc. If kzalloc is failed, return type is used as -ENOMEM. Signed-off-by: Chaehyun Lim --- V2 : rebase latest staging-testing drivers/staging/wilc1000/linux_wlan_spi.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/staging/wilc1000/linux_wlan_spi.c b/drivers/staging/wilc1000/linux_wlan_spi.c index 3e24256..51bbd96 100644 --- a/drivers/staging/wilc1000/linux_wlan_spi.c +++ b/drivers/staging/wilc1000/linux_wlan_spi.c @@ -125,10 +125,8 @@ int linux_spi_write(u8 *b, u32 len) int remainder = len % TXRX_PHASE_SIZE; char *r_buffer = kzalloc(TXRX_PHASE_SIZE, GFP_KERNEL); - - if (!r_buffer) { - PRINT_ER("Failed to allocate memory for r_buffer\n"); - } + if (!r_buffer) + return -ENOMEM; if (blk) { while (i < blk) { @@ -208,10 +206,9 @@ int linux_spi_write(u8 *b, u32 len) .delay_usecs = 0, }; char *r_buffer = kzalloc(len, GFP_KERNEL); + if (!r_buffer) + return -ENOMEM; - if (!r_buffer) { - PRINT_ER("Failed to allocate memory for r_buffer\n"); - } tr.rx_buf = r_buffer; PRINT_D(BUS_DBG, "Request writing %d bytes\n", len); @@ -257,10 +254,8 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen) int remainder = rlen % TXRX_PHASE_SIZE; char *t_buffer = kzalloc(TXRX_PHASE_SIZE, GFP_KERNEL); - - if (!t_buffer) { - PRINT_ER("Failed to allocate memory for t_buffer\n"); - } + if (!t_buffer) + return -ENOMEM; if (blk) { while (i < blk) { @@ -337,10 +332,9 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen) }; char *t_buffer = kzalloc(rlen, GFP_KERNEL); + if (!t_buffer) + return -ENOMEM; - if (!t_buffer) { - PRINT_ER("Failed to allocate memory for t_buffer\n"); - } tr.tx_buf = t_buffer; memset(&msg, 0, sizeof(msg)); -- 2.5.1