From patchwork Thu Aug 4 16:52:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arvind Yadav X-Patchwork-Id: 9268581 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DAA4C607D6 for ; Mon, 8 Aug 2016 15:34:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCBEC283FE for ; Mon, 8 Aug 2016 15:34:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C191828415; Mon, 8 Aug 2016 15:34:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 686E5283FE for ; Mon, 8 Aug 2016 15:34:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752246AbcHHPeO (ORCPT ); Mon, 8 Aug 2016 11:34:14 -0400 Received: from broadband.actcorp.in ([106.51.140.156]:14180 "EHLO arvind-ThinkPad-Edge-E431" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752128AbcHHPeN (ORCPT ); Mon, 8 Aug 2016 11:34:13 -0400 Received: by arvind-ThinkPad-Edge-E431 (Postfix, from userid 1000) id CE5094E1A2B; Thu, 4 Aug 2016 22:22:46 +0530 (IST) From: Arvind Yadav To: zajec5@gmail.com, leoli@freescale.com Cc: qiang.zhao@freescale.com, scottwood@freescale.com, viresh.kumar@linaro.org, akpm@linux-foundation.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux@roeck-us.net, arnd@arndb.de, Arvind Yadav Subject: [v5.1] ucc_fast: Fix to avoid IS_ERR_VALUE abuses and dead code on 64bit systems. Date: Thu, 4 Aug 2016 22:22:43 +0530 Message-Id: <1470329563-5464-1-git-send-email-arvind.yadav.cs@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP IS_ERR_VALUE() assumes that parameter is an unsigned long. It can not be used to check if 'unsigned int' is passed insted. Which tends to reflect an error. In 64bit architectures sizeof (int) == 4 && sizeof (long) == 8. IS_ERR_VALUE(x) is ((x) >= (unsigned long)-4095). IS_ERR_VALUE() of 'unsigned int' is always false because the 32bit value is zero extended to 64 bits. Now Problem In UCC fast protocols -: drivers/soc/fsl/qe/ucc_fast.c /* Allocate memory for Tx Virtual Fifo */ uccf->ucc_fast_tx_virtual_fifo_base_offset = qe_muram_alloc(uf_info->utfs, UCC_FAST_VIRT_FIFO_REGS_ALIGNMENT); if (IS_ERR_VALUE(uccf->ucc_fast_tx_virtual_fifo_base_offset)) { printk(KERN_ERR "%s: cannot allocate MURAM for TX FIFO\n", __func__); uccf->ucc_fast_tx_virtual_fifo_base_offset = 0; ucc_fast_free(uccf); return -ENOMEM; } /* Allocate memory for Rx Virtual Fifo */ uccf->ucc_fast_rx_virtual_fifo_base_offset = qe_muram_alloc(uf_info->urfs + UCC_FAST_RECEIVE_VIRTUAL_FIFO_SIZE_FUDGE_FACTOR, UCC_FAST_VIRT_FIFO_REGS_ALIGNMENT); if (IS_ERR_VALUE(uccf->ucc_fast_rx_virtual_fifo_base_offset)) { printk(KERN_ERR "%s: cannot allocate MURAM for RX FIFO\n", __func__); uccf->ucc_fast_rx_virtual_fifo_base_offset = 0; ucc_fast_free(uccf); return -ENOMEM; } qe_muram_alloc (a.k.a. cpm_muram_alloc) returns unsigned long. Return value store in a u32 (ucc_fast_tx_virtual_fifo_base_offset and ucc_fast_rx_virtual_fifo_base_offset).If qe_muram_alloc will return any error, Then IS_ERR_VALUE will always return 0. it'll not call ucc_fast_free for any failure. Inside 'if code' will be a dead code on 64bit. This patch is to avoid this problem on 64bit machine. Signed-off-by: Arvind Yadav --- include/soc/fsl/qe/ucc_fast.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/soc/fsl/qe/ucc_fast.h b/include/soc/fsl/qe/ucc_fast.h index df8ea79..ada9070 100644 --- a/include/soc/fsl/qe/ucc_fast.h +++ b/include/soc/fsl/qe/ucc_fast.h @@ -165,10 +165,12 @@ struct ucc_fast_private { int stopped_tx; /* Whether channel has been stopped for Tx (STOP_TX, etc.) */ int stopped_rx; /* Whether channel has been stopped for Rx */ - u32 ucc_fast_tx_virtual_fifo_base_offset;/* pointer to base of Tx - virtual fifo */ - u32 ucc_fast_rx_virtual_fifo_base_offset;/* pointer to base of Rx - virtual fifo */ + unsigned long ucc_fast_tx_virtual_fifo_base_offset;/* pointer to base of + * Tx virtual fifo + */ + unsigned long ucc_fast_rx_virtual_fifo_base_offset;/* pointer to base of + * Rx virtual fifo + */ #ifdef STATISTICS u32 tx_frames; /* Transmitted frames counter. */ u32 rx_frames; /* Received frames counter (only frames