diff options
| author | Bruce Allan <bruce.w.allan@intel.com> | 2019-02-08 15:50:31 -0500 |
|---|---|---|
| committer | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2019-02-25 11:56:01 -0500 |
| commit | c6dfd690f1c333475db1833ef3b5a4f4d6ba7365 (patch) | |
| tree | d41b3c08e8631325ebee244f0da68c159cc9c6f4 /drivers/net/ethernet/intel/ice/ice_txrx.c | |
| parent | 0e8fd74df2f37e2dcc305ed22f4feb8587b91929 (diff) | |
ice: sizeof(<type>) should be avoided
With sizeof(), it is preferable to use the variable of type <type> instead
of sizeof(<type>).
There are multiple places where a temporary variable is used to hold a
'size' value which is then used for a subsequent alloc/memset. Get rid
of the temporary variable by calculating size as part of the alloc/memset
statement.
Also remove unnecessary type-cast.
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>
Diffstat (limited to 'drivers/net/ethernet/intel/ice/ice_txrx.c')
| -rw-r--r-- | drivers/net/ethernet/intel/ice/ice_txrx.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/drivers/net/ethernet/intel/ice/ice_txrx.c b/drivers/net/ethernet/intel/ice/ice_txrx.c index 2357fcac996b..67d129bfe489 100644 --- a/drivers/net/ethernet/intel/ice/ice_txrx.c +++ b/drivers/net/ethernet/intel/ice/ice_txrx.c | |||
| @@ -48,7 +48,6 @@ static struct netdev_queue *txring_txq(const struct ice_ring *ring) | |||
| 48 | */ | 48 | */ |
| 49 | void ice_clean_tx_ring(struct ice_ring *tx_ring) | 49 | void ice_clean_tx_ring(struct ice_ring *tx_ring) |
| 50 | { | 50 | { |
| 51 | unsigned long size; | ||
| 52 | u16 i; | 51 | u16 i; |
| 53 | 52 | ||
| 54 | /* ring already cleared, nothing to do */ | 53 | /* ring already cleared, nothing to do */ |
| @@ -59,8 +58,7 @@ void ice_clean_tx_ring(struct ice_ring *tx_ring) | |||
| 59 | for (i = 0; i < tx_ring->count; i++) | 58 | for (i = 0; i < tx_ring->count; i++) |
| 60 | ice_unmap_and_free_tx_buf(tx_ring, &tx_ring->tx_buf[i]); | 59 | ice_unmap_and_free_tx_buf(tx_ring, &tx_ring->tx_buf[i]); |
| 61 | 60 | ||
| 62 | size = sizeof(struct ice_tx_buf) * tx_ring->count; | 61 | memset(tx_ring->tx_buf, 0, sizeof(*tx_ring->tx_buf) * tx_ring->count); |
| 63 | memset(tx_ring->tx_buf, 0, size); | ||
| 64 | 62 | ||
| 65 | /* Zero out the descriptor ring */ | 63 | /* Zero out the descriptor ring */ |
| 66 | memset(tx_ring->desc, 0, tx_ring->size); | 64 | memset(tx_ring->desc, 0, tx_ring->size); |
| @@ -226,21 +224,21 @@ static bool ice_clean_tx_irq(struct ice_vsi *vsi, struct ice_ring *tx_ring, | |||
| 226 | int ice_setup_tx_ring(struct ice_ring *tx_ring) | 224 | int ice_setup_tx_ring(struct ice_ring *tx_ring) |
| 227 | { | 225 | { |
| 228 | struct device *dev = tx_ring->dev; | 226 | struct device *dev = tx_ring->dev; |
| 229 | int bi_size; | ||
| 230 | 227 | ||
| 231 | if (!dev) | 228 | if (!dev) |
| 232 | return -ENOMEM; | 229 | return -ENOMEM; |
| 233 | 230 | ||
| 234 | /* warn if we are about to overwrite the pointer */ | 231 | /* warn if we are about to overwrite the pointer */ |
| 235 | WARN_ON(tx_ring->tx_buf); | 232 | WARN_ON(tx_ring->tx_buf); |
| 236 | bi_size = sizeof(struct ice_tx_buf) * tx_ring->count; | 233 | tx_ring->tx_buf = |
| 237 | tx_ring->tx_buf = devm_kzalloc(dev, bi_size, GFP_KERNEL); | 234 | devm_kzalloc(dev, sizeof(*tx_ring->tx_buf) * tx_ring->count, |
| 235 | GFP_KERNEL); | ||
| 238 | if (!tx_ring->tx_buf) | 236 | if (!tx_ring->tx_buf) |
| 239 | return -ENOMEM; | 237 | return -ENOMEM; |
| 240 | 238 | ||
| 241 | /* round up to nearest 4K */ | 239 | /* round up to nearest 4K */ |
| 242 | tx_ring->size = tx_ring->count * sizeof(struct ice_tx_desc); | 240 | tx_ring->size = ALIGN(tx_ring->count * sizeof(struct ice_tx_desc), |
| 243 | tx_ring->size = ALIGN(tx_ring->size, 4096); | 241 | 4096); |
| 244 | tx_ring->desc = dmam_alloc_coherent(dev, tx_ring->size, &tx_ring->dma, | 242 | tx_ring->desc = dmam_alloc_coherent(dev, tx_ring->size, &tx_ring->dma, |
| 245 | GFP_KERNEL); | 243 | GFP_KERNEL); |
| 246 | if (!tx_ring->desc) { | 244 | if (!tx_ring->desc) { |
| @@ -267,7 +265,6 @@ err: | |||
| 267 | void ice_clean_rx_ring(struct ice_ring *rx_ring) | 265 | void ice_clean_rx_ring(struct ice_ring *rx_ring) |
| 268 | { | 266 | { |
| 269 | struct device *dev = rx_ring->dev; | 267 | struct device *dev = rx_ring->dev; |
| 270 | unsigned long size; | ||
| 271 | u16 i; | 268 | u16 i; |
| 272 | 269 | ||
| 273 | /* ring already cleared, nothing to do */ | 270 | /* ring already cleared, nothing to do */ |
| @@ -292,8 +289,7 @@ void ice_clean_rx_ring(struct ice_ring *rx_ring) | |||
| 292 | rx_buf->page_offset = 0; | 289 | rx_buf->page_offset = 0; |
| 293 | } | 290 | } |
| 294 | 291 | ||
| 295 | size = sizeof(struct ice_rx_buf) * rx_ring->count; | 292 | memset(rx_ring->rx_buf, 0, sizeof(*rx_ring->rx_buf) * rx_ring->count); |
| 296 | memset(rx_ring->rx_buf, 0, size); | ||
| 297 | 293 | ||
| 298 | /* Zero out the descriptor ring */ | 294 | /* Zero out the descriptor ring */ |
| 299 | memset(rx_ring->desc, 0, rx_ring->size); | 295 | memset(rx_ring->desc, 0, rx_ring->size); |
| @@ -331,15 +327,15 @@ void ice_free_rx_ring(struct ice_ring *rx_ring) | |||
| 331 | int ice_setup_rx_ring(struct ice_ring *rx_ring) | 327 | int ice_setup_rx_ring(struct ice_ring *rx_ring) |
| 332 | { | 328 | { |
| 333 | struct device *dev = rx_ring->dev; | 329 | struct device *dev = rx_ring->dev; |
| 334 | int bi_size; | ||
| 335 | 330 | ||
| 336 | if (!dev) | 331 | if (!dev) |
| 337 | return -ENOMEM; | 332 | return -ENOMEM; |
| 338 | 333 | ||
| 339 | /* warn if we are about to overwrite the pointer */ | 334 | /* warn if we are about to overwrite the pointer */ |
| 340 | WARN_ON(rx_ring->rx_buf); | 335 | WARN_ON(rx_ring->rx_buf); |
| 341 | bi_size = sizeof(struct ice_rx_buf) * rx_ring->count; | 336 | rx_ring->rx_buf = |
| 342 | rx_ring->rx_buf = devm_kzalloc(dev, bi_size, GFP_KERNEL); | 337 | devm_kzalloc(dev, sizeof(*rx_ring->rx_buf) * rx_ring->count, |
| 338 | GFP_KERNEL); | ||
| 343 | if (!rx_ring->rx_buf) | 339 | if (!rx_ring->rx_buf) |
| 344 | return -ENOMEM; | 340 | return -ENOMEM; |
| 345 | 341 | ||
