[dpdk-dev] i40e: unintended sign extension
Commit Message
Suspicious implicit sign extension: pf->fdir.match_counter_index
with type unsigned short (16 bits, unsigned) is promoted in
pf->fdir.match_counter_index << 20 to type int (32 bits, signed),
then sign-extended to type unsigned long (64 bits, unsigned).
If pf->fdir.match_counter_index << 20 is greater than 0x7FFFFFFF,
the upper bits of the result will all be 1.
To fix the issue set explicit cast uint32_t of pf->fdir.match_counter_index.
Fixes: 05999aab4ca6 ("i40e: add or delete flow director")
Coverity ID 13315
Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
---
drivers/net/i40e/i40e_fdir.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Fri, May 20, 2016 at 03:03:36PM +0200, Slawomir Mrozowicz wrote:
> Suspicious implicit sign extension: pf->fdir.match_counter_index
> with type unsigned short (16 bits, unsigned) is promoted in
> pf->fdir.match_counter_index << 20 to type int (32 bits, signed),
> then sign-extended to type unsigned long (64 bits, unsigned).
> If pf->fdir.match_counter_index << 20 is greater than 0x7FFFFFFF,
> the upper bits of the result will all be 1.
> To fix the issue set explicit cast uint32_t of pf->fdir.match_counter_index.
>
> Fixes: 05999aab4ca6 ("i40e: add or delete flow director")
> Coverity ID 13315
>
> Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Applied to dpdk-next-net/rel_16_07
/Bruce
@@ -1141,7 +1141,8 @@ i40e_fdir_filter_programming(struct i40e_pf *pf,
fdirdp->dtype_cmd_cntindex |=
rte_cpu_to_le_32(I40E_TXD_FLTR_QW1_CNT_ENA_MASK);
fdirdp->dtype_cmd_cntindex |=
- rte_cpu_to_le_32((pf->fdir.match_counter_index <<
+ rte_cpu_to_le_32(
+ ((uint32_t)pf->fdir.match_counter_index <<
I40E_TXD_FLTR_QW1_CNTINDEX_SHIFT) &
I40E_TXD_FLTR_QW1_CNTINDEX_MASK);