Re: [PATCH] Need proper type casting before assignment, Remove compilation Warning.
From: Arvind Yadav Date: Fri, 8 Jul 2016 00:07:54 +0530 > -Return type of 'qe_muram_alloc' is 'unsigned long', That Was trying to > assigned in ucc_fast_tx_virtual_fifo_base_offset and > ucc_fast_rx_virtual_fifo_base_offset. These variable are 'unsigned int'. > So before assginment need a proper type casting. > > -Passing value in IS_ERR_VALUE() is wrong, as they pass an 'int' > into a function that takes an 'unsigned long' argument.This happens > to work because the type is sign-extended on 64-bit architectures > before it gets converted into an unsigned type. > > -Passing an 'unsigned short' or 'unsigned int'argument into > IS_ERR_VALUE() is guaranteed to be broken, as are 8-bit integers > and types that are wider than 'unsigned long'. > > -Any user will get compilation warning for that do not pass an > unsigned long' argument. > > Signed-off-by: Arvind Yadav Your subject line is improperly formed. It must have the subsystem or driver name, followed by a colon ":" and a space. Such as: [PATCH] ucc_geth: Need proper type ... ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
RE: [PATCH] Need proper type casting before assignment, Remove compilation Warning.
From: Arvind Yadav > Sent: 07 July 2016 19:38 > -Return type of 'qe_muram_alloc' is 'unsigned long', That Was trying to > assigned in ucc_fast_tx_virtual_fifo_base_offset and > ucc_fast_rx_virtual_fifo_base_offset. These variable are 'unsigned int'. > So before assginment need a proper type casting. Are you sure, seems to me that the type of one of the fields is wrong. The casts you are adding do not aid readability at all. > -Passing value in IS_ERR_VALUE() is wrong, as they pass an 'int' > into a function that takes an 'unsigned long' argument.This happens > to work because the type is sign-extended on 64-bit architectures > before it gets converted into an unsigned type. > > -Passing an 'unsigned short' or 'unsigned int'argument into > IS_ERR_VALUE() is guaranteed to be broken, as are 8-bit integers > and types that are wider than 'unsigned long'. Signed 8 and 16 bit values will be sign extended to 'int' before being used in any arithmetic operation. Unsigned ones get zero extended to 'int'. That probably means you shouldn't be using IS_ERR_VALUE(). David ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
[PATCH] Need proper type casting before assignment, Remove compilation Warning.
-Return type of 'qe_muram_alloc' is 'unsigned long', That Was trying to assigned in ucc_fast_tx_virtual_fifo_base_offset and ucc_fast_rx_virtual_fifo_base_offset. These variable are 'unsigned int'. So before assginment need a proper type casting. -Passing value in IS_ERR_VALUE() is wrong, as they pass an 'int' into a function that takes an 'unsigned long' argument.This happens to work because the type is sign-extended on 64-bit architectures before it gets converted into an unsigned type. -Passing an 'unsigned short' or 'unsigned int'argument into IS_ERR_VALUE() is guaranteed to be broken, as are 8-bit integers and types that are wider than 'unsigned long'. -Any user will get compilation warning for that do not pass an unsigned long' argument. Signed-off-by: Arvind Yadav --- drivers/net/ethernet/freescale/ucc_geth.c | 71 +-- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/drivers/net/ethernet/freescale/ucc_geth.c b/drivers/net/ethernet/freescale/ucc_geth.c index 5bf1ade..a5086b2 100644 --- a/drivers/net/ethernet/freescale/ucc_geth.c +++ b/drivers/net/ethernet/freescale/ucc_geth.c @@ -273,7 +273,7 @@ static int fill_init_enet_entries(struct ucc_geth_private *ugeth, unsigned int risc, int skip_page_for_first_entry) { - u32 init_enet_offset; + unsigned long init_enet_offset; u8 i; int snum; @@ -297,8 +297,8 @@ static int fill_init_enet_entries(struct ucc_geth_private *ugeth, } } *(p_start++) = - ((u8) snum << ENET_INIT_PARAM_SNUM_SHIFT) | init_enet_offset - | risc; + ((u8)snum << ENET_INIT_PARAM_SNUM_SHIFT) + | (u32)init_enet_offset | risc; } return 0; @@ -2232,9 +2232,10 @@ static int ucc_geth_alloc_tx(struct ucc_geth_private *ugeth) align) & ~(align - 1)); } else if (uf_info->bd_mem_part == MEM_PART_MURAM) { ugeth->tx_bd_ring_offset[j] = - qe_muram_alloc(length, + (u32)qe_muram_alloc(length, UCC_GETH_TX_BD_RING_ALIGNMENT); - if (!IS_ERR_VALUE(ugeth->tx_bd_ring_offset[j])) + if (!IS_ERR_VALUE( + (unsigned long)ugeth->tx_bd_ring_offset[j])) ugeth->p_tx_bd_ring[j] = (u8 __iomem *) qe_muram_addr(ugeth-> tx_bd_ring_offset[j]); @@ -2309,9 +2310,10 @@ static int ucc_geth_alloc_rx(struct ucc_geth_private *ugeth) align) & ~(align - 1)); } else if (uf_info->bd_mem_part == MEM_PART_MURAM) { ugeth->rx_bd_ring_offset[j] = - qe_muram_alloc(length, + (u32)qe_muram_alloc(length, UCC_GETH_RX_BD_RING_ALIGNMENT); - if (!IS_ERR_VALUE(ugeth->rx_bd_ring_offset[j])) + if (!IS_ERR_VALUE( + (unsigned long)ugeth->rx_bd_ring_offset[j])) ugeth->p_rx_bd_ring[j] = (u8 __iomem *) qe_muram_addr(ugeth-> rx_bd_ring_offset[j]); @@ -2367,7 +2369,8 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth) struct ucc_geth __iomem *ug_regs; int ret_val = -EINVAL; u32 remoder = UCC_GETH_REMODER_INIT; - u32 init_enet_pram_offset, cecr_subblock, command; + u32 cecr_subblock, command; + unsigned long init_enet_pram_offset; u32 ifstat, i, j, size, l2qt, l3qt; u16 temoder = UCC_GETH_TEMODER_INIT; u16 test; @@ -2519,9 +2522,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth) /* Tx global PRAM */ /* Allocate global tx parameter RAM page */ ugeth->tx_glbl_pram_offset = - qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram), + (u32)qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram), UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT); - if (IS_ERR_VALUE(ugeth->tx_glbl_pram_offset)) { + if (IS_ERR_VALUE((unsigned long)ugeth->tx_glbl_pram_offset)) { if (netif_msg_ifup(ugeth)) pr_err("Can not allocate DPRAM memory for p_tx_glbl_pram\n"); return -ENOMEM; @@ -2537,11 +2540,11 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth) /* TQPTR */ /* Size varies with number of Tx threads */ ugeth->thread_dat_tx_offset = - qe_muram_alloc(numThreadsTxNumerical * + (u32)qe
[PATCH] Need proper type casting before assignment, Remove compilation Warning.
-Return type of 'qe_muram_alloc' is 'unsigned long', That Was trying to assigned in ucc_fast_tx_virtual_fifo_base_offset and ucc_fast_rx_virtual_fifo_base_offset. These variable are 'unsigned int'. So before assginment need a proper type casting. -Passing value in IS_ERR_VALUE() is wrong, as they pass an 'int' into a function that takes an 'unsigned long' argument.This happens to work because the type is sign-extended on 64-bit architectures before it gets converted into an unsigned type. -Passing an 'unsigned short' or 'unsigned int'argument into IS_ERR_VALUE() is guaranteed to be broken, as are 8-bit integers and types that are wider than 'unsigned long'. -Any user will get compilation warning for that do not pass an unsigned long' argument. Signed-off-by: Arvind Yadav --- drivers/soc/fsl/qe/ucc_fast.c | 11 +++ 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/soc/fsl/qe/ucc_fast.c b/drivers/soc/fsl/qe/ucc_fast.c index a768931..98eed25 100644 --- a/drivers/soc/fsl/qe/ucc_fast.c +++ b/drivers/soc/fsl/qe/ucc_fast.c @@ -267,8 +267,10 @@ 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)) { + (unsigned int)qe_muram_alloc(uf_info->utfs, + UCC_FAST_VIRT_FIFO_REGS_ALIGNMENT); + if (IS_ERR_VALUE( + (unsigned long)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; @@ -278,10 +280,11 @@ int ucc_fast_init(struct ucc_fast_info * uf_info, struct ucc_fast_private ** ucc /* Allocate memory for Rx Virtual Fifo */ uccf->ucc_fast_rx_virtual_fifo_base_offset = - qe_muram_alloc(uf_info->urfs + + (unsigned int)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 (IS_ERR_VALUE( + (unsigned long)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; -- 1.9.1 ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev