ice: fix numeric overflow warning
authorBruce Allan <bruce.w.allan@intel.com>
Fri, 8 Feb 2019 20:50:35 +0000 (12:50 -0800)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Mon, 25 Feb 2019 16:56:01 +0000 (08:56 -0800)
When compiling and analyzing the driver on newer kernels, a static
analyzer warns about the following "numeric overflow" issues:

  "The result of expression: 'budget-1' generates 4-byte type while casting
   to a bigger size of 8-byte".

  "The result of expression: '*words-words_read' generates 4-byte type
   while casting to a bigger size of 8-byte".

Fix them both.

Signed-off-by: Bruce Allan <bruce.w.allan@intel.com>
Signed-off-by: Anirudh Venkataramanan <anirudh.venkataramanan@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/ice/ice_nvm.c
drivers/net/ethernet/intel/ice/ice_txrx.c

index ce64cecdae9cbb20c4d8651409a5d2d982934979..413fdbbcc4d0ce79266bf1883110e9cb1b69956d 100644 (file)
@@ -152,9 +152,10 @@ ice_read_sr_buf_aq(struct ice_hw *hw, u16 offset, u16 *words, u16 *data)
                 */
                off_w = offset % ICE_SR_SECTOR_SIZE_IN_WORDS;
                read_size = off_w ?
-                       min(*words,
-                           (u16)(ICE_SR_SECTOR_SIZE_IN_WORDS - off_w)) :
-                       min((*words - words_read), ICE_SR_SECTOR_SIZE_IN_WORDS);
+                       min_t(u16, *words,
+                             (ICE_SR_SECTOR_SIZE_IN_WORDS - off_w)) :
+                       min_t(u16, (*words - words_read),
+                             ICE_SR_SECTOR_SIZE_IN_WORDS);
 
                /* Check if this is last command, if so set proper flag */
                if ((words_read + read_size) >= *words)
index 67d129bfe4892952a91b850acb268850155d2460..c289d97f477d5251d4456e610fc544059c227c21 100644 (file)
@@ -1169,7 +1169,7 @@ int ice_napi_poll(struct napi_struct *napi, int budget)
                if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
                        ice_update_ena_itr(vsi, q_vector);
 
-       return min(work_done, budget - 1);
+       return min_t(int, work_done, budget - 1);
 }
 
 /* helper function for building cmd/type/offset */