From patchwork Fri Aug 5 08:40:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arvind Yadav X-Patchwork-Id: 9265183 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 0A7066048B for ; Fri, 5 Aug 2016 10:33:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF11F28409 for ; Fri, 5 Aug 2016 10:33:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3BD42842D; Fri, 5 Aug 2016 10:33:50 +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 831A028409 for ; Fri, 5 Aug 2016 10:33:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934926AbcHEKdo (ORCPT ); Fri, 5 Aug 2016 06:33:44 -0400 Received: from broadband.actcorp.in ([106.51.140.228]:20352 "EHLO arvind-ThinkPad-Edge-E431" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S934745AbcHEKdn (ORCPT ); Fri, 5 Aug 2016 06:33:43 -0400 X-Greylist: delayed 2684 seconds by postgrey-1.27 at vger.kernel.org; Fri, 05 Aug 2016 06:33:42 EDT Received: by arvind-ThinkPad-Edge-E431 (Postfix, from userid 1000) id 4C1044E1C1B; Fri, 5 Aug 2016 14:10:54 +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.2] ucc_slow: Fix to avoid IS_ERR_VALUE abuses and dead code on 64bit systems. Date: Fri, 5 Aug 2016 14:10:52 +0530 Message-Id: <1470386452-7263-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 slow protocols -: drivers/soc/fsl/qe/ucc_slow.c /* Get PRAM base */ uccs->us_pram_offset = qe_muram_alloc(UCC_SLOW_PRAM_SIZE, ALIGNMENT_OF_UCC_SLOW_PRAM); if (IS_ERR_VALUE(uccs->us_pram_offset)) { printk(KERN_ERR "%s: cannot allocate MURAM for PRAM", __func__); ucc_slow_free(uccs); return -ENOMEM; } id = ucc_slow_get_qe_cr_subblock(us_info->ucc_num); qe_issue_cmd(QE_ASSIGN_PAGE_TO_DEVICE, id, us_info->protocol, uccs->us_pram_offset); uccs->us_pram = qe_muram_addr(uccs->us_pram_offset); /* Allocate BDs. */ uccs->rx_base_offset = qe_muram_alloc(us_info->rx_bd_ring_len * sizeof(struct qe_bd), QE_ALIGNMENT_OF_BD); if (IS_ERR_VALUE(uccs->rx_base_offset)) { printk(KERN_ERR "%s: cannot allocate %u RX BDs\n", __func__, us_info->rx_bd_ring_len); uccs->rx_base_offset = 0; ucc_slow_free(uccs); return -ENOMEM; } uccs->tx_base_offset = qe_muram_alloc(us_info->tx_bd_ring_len * sizeof(struct qe_bd), QE_ALIGNMENT_OF_BD); if (IS_ERR_VALUE(uccs->tx_base_offset)) { printk(KERN_ERR "%s: cannot allocate TX BDs", __func__); uccs->tx_base_offset = 0; ucc_slow_free(uccs); return -ENOMEM; } qe_muram_alloc (a.k.a. cpm_muram_alloc) returns unsigned long. Return value store in a u32 (us_pram_offset, rx_base_offset and tx_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. Even qe_muram_addr will return wrong virtual address. Which can cause an error. This patch is to avoid this problem on 64bit machine. Signed-off-by: Arvind Yadav --- include/soc/fsl/qe/ucc_slow.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/soc/fsl/qe/ucc_slow.h b/include/soc/fsl/qe/ucc_slow.h index 6c0573a..fca30a1 100644 --- a/include/soc/fsl/qe/ucc_slow.h +++ b/include/soc/fsl/qe/ucc_slow.h @@ -189,7 +189,7 @@ struct ucc_slow_private { struct ucc_slow_info *us_info; struct ucc_slow __iomem *us_regs; /* Ptr to memory map of UCC regs */ struct ucc_slow_pram *us_pram; /* a pointer to the parameter RAM */ - u32 us_pram_offset; + unsigned long us_pram_offset; int enabled_tx; /* Whether channel is enabled for Tx (ENT) */ int enabled_rx; /* Whether channel is enabled for Rx (ENR) */ int stopped_tx; /* Whether channel has been stopped for Tx @@ -198,8 +198,12 @@ struct ucc_slow_private { struct list_head confQ; /* frames passed to chip waiting for tx */ u32 first_tx_bd_mask; /* mask is used in Tx routine to save status and length for first BD in a frame */ - u32 tx_base_offset; /* first BD in Tx BD table offset (In MURAM) */ - u32 rx_base_offset; /* first BD in Rx BD table offset (In MURAM) */ + unsigned long tx_base_offset; /* first BD in Tx BD table offset + * (In MURAM) + */ + unsigned long rx_base_offset; /* first BD in Rx BD table offset + * (In MURAM) + */ struct qe_bd *confBd; /* next BD for confirm after Tx */ struct qe_bd *tx_bd; /* next BD for new Tx request */ struct qe_bd *rx_bd; /* next BD to collect after Rx */