soc: fsl: qe: avoid IS_ERR_VALUE in ucc_fast.c
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Thu, 28 Nov 2019 14:55:48 +0000 (15:55 +0100)
committerLi Yang <leoyang.li@nxp.com>
Mon, 9 Dec 2019 19:54:37 +0000 (13:54 -0600)
When building this on a 64-bit platform gcc rightly warns that the
error checking is broken (-ENOMEM stored in an u32 does not compare
greater than (unsigned long)-MAX_ERRNO). Instead, change the
ucc_fast_[tr]x_virtual_fifo_base_offset members to s32 and use an
ordinary check-for-negative. Also, this avoids treating 0 as "this
cannot have been returned from qe_muram_alloc() so don't free it".

Reviewed-by: Timur Tabi <timur@kernel.org>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Li Yang <leoyang.li@nxp.com>
drivers/soc/fsl/qe/ucc_fast.c
include/soc/fsl/qe/ucc_fast.h

index ca04524..ad6193e 100644 (file)
@@ -197,6 +197,8 @@ int ucc_fast_init(struct ucc_fast_info * uf_info, struct ucc_fast_private ** ucc
                        __func__);
                return -ENOMEM;
        }
+       uccf->ucc_fast_tx_virtual_fifo_base_offset = -1;
+       uccf->ucc_fast_rx_virtual_fifo_base_offset = -1;
 
        /* Fill fast UCC structure */
        uccf->uf_info = uf_info;
@@ -265,10 +267,9 @@ int ucc_fast_init(struct ucc_fast_info * uf_info, struct ucc_fast_private ** ucc
        /* 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)) {
+       if (uccf->ucc_fast_tx_virtual_fifo_base_offset < 0) {
                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;
        }
@@ -278,10 +279,9 @@ int ucc_fast_init(struct ucc_fast_info * uf_info, struct ucc_fast_private ** ucc
                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)) {
+       if (uccf->ucc_fast_rx_virtual_fifo_base_offset < 0) {
                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;
        }
@@ -384,11 +384,8 @@ void ucc_fast_free(struct ucc_fast_private * uccf)
        if (!uccf)
                return;
 
-       if (uccf->ucc_fast_tx_virtual_fifo_base_offset)
-               qe_muram_free(uccf->ucc_fast_tx_virtual_fifo_base_offset);
-
-       if (uccf->ucc_fast_rx_virtual_fifo_base_offset)
-               qe_muram_free(uccf->ucc_fast_rx_virtual_fifo_base_offset);
+       qe_muram_free(uccf->ucc_fast_tx_virtual_fifo_base_offset);
+       qe_muram_free(uccf->ucc_fast_rx_virtual_fifo_base_offset);
 
        if (uccf->uf_regs)
                iounmap(uccf->uf_regs);
index e9cc460..ba0e838 100644 (file)
@@ -188,9 +188,9 @@ 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
+       s32 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
+       s32 ucc_fast_rx_virtual_fifo_base_offset;/* pointer to base of Rx
                                                    virtual fifo */
 #ifdef STATISTICS
        u32 tx_frames;          /* Transmitted frames counter. */