Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/bitmap: change type of bitmap_weight to unsigned long

bitmap_weight() doesn't return negative values, so change it's type
to unsigned long. It may help compiler to generate better code and
catch bugs.

Signed-off-by: Yury Norov <yury.norov@gmail.com>

+19 -19
+3 -3
drivers/dma/ti/k3-udma.c
··· 4997 4997 switch (ud->match_data->type) { 4998 4998 case DMA_TYPE_UDMA: 4999 4999 dev_info(dev, 5000 - "Channels: %d (tchan: %u, rchan: %u, gp-rflow: %u)\n", 5000 + "Channels: %d (tchan: %lu, rchan: %lu, gp-rflow: %lu)\n", 5001 5001 ch_count, 5002 5002 ud->tchan_cnt - bitmap_weight(ud->tchan_map, 5003 5003 ud->tchan_cnt), ··· 5008 5008 break; 5009 5009 case DMA_TYPE_BCDMA: 5010 5010 dev_info(dev, 5011 - "Channels: %d (bchan: %u, tchan: %u, rchan: %u)\n", 5011 + "Channels: %d (bchan: %lu, tchan: %lu, rchan: %lu)\n", 5012 5012 ch_count, 5013 5013 ud->bchan_cnt - bitmap_weight(ud->bchan_map, 5014 5014 ud->bchan_cnt), ··· 5019 5019 break; 5020 5020 case DMA_TYPE_PKTDMA: 5021 5021 dev_info(dev, 5022 - "Channels: %d (tchan: %u, rchan: %u)\n", 5022 + "Channels: %d (tchan: %lu, rchan: %lu)\n", 5023 5023 ch_count, 5024 5024 ud->tchan_cnt - bitmap_weight(ud->tchan_map, 5025 5025 ud->tchan_cnt),
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
··· 195 195 set_bit(i, adev->gfx.mec.queue_bitmap); 196 196 } 197 197 198 - dev_dbg(adev->dev, "mec queue bitmap weight=%d\n", bitmap_weight(adev->gfx.mec.queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES)); 198 + dev_dbg(adev->dev, "mec queue bitmap weight=%ld\n", bitmap_weight(adev->gfx.mec.queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES)); 199 199 } 200 200 201 201 void amdgpu_gfx_graphics_queue_acquire(struct amdgpu_device *adev)
+1 -1
drivers/gpu/drm/i915/display/intel_display_power.c
··· 378 378 power_domains); 379 379 enum intel_display_power_domain domain; 380 380 381 - drm_dbg(&i915->drm, "%s (%d):\n", prefix, bitmap_weight(mask->bits, POWER_DOMAIN_NUM)); 381 + drm_dbg(&i915->drm, "%s (%ld):\n", prefix, bitmap_weight(mask->bits, POWER_DOMAIN_NUM)); 382 382 for_each_power_domain(domain, mask) 383 383 drm_dbg(&i915->drm, "%s use_count %d\n", 384 384 intel_display_power_domain_str(domain),
+1 -1
drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c
··· 363 363 } 364 364 365 365 drm_printf(p, "TOTAL:\t%d\t(of %d)\n", total, smp->blk_cnt); 366 - drm_printf(p, "AVAIL:\t%d\n", smp->blk_cnt - 366 + drm_printf(p, "AVAIL:\t%ld\n", smp->blk_cnt - 367 367 bitmap_weight(state->state, smp->blk_cnt)); 368 368 369 369 if (drm_can_sleep())
+1 -1
drivers/iommu/intel/iommu.c
··· 3946 3946 struct device_attribute *attr, char *buf) 3947 3947 { 3948 3948 struct intel_iommu *iommu = dev_to_intel_iommu(dev); 3949 - return sprintf(buf, "%d\n", bitmap_weight(iommu->domain_ids, 3949 + return sprintf(buf, "%ld\n", bitmap_weight(iommu->domain_ids, 3950 3950 cap_ndoms(iommu->cap))); 3951 3951 } 3952 3952 static DEVICE_ATTR_RO(domains_used);
+1 -1
drivers/net/ethernet/mellanox/mlx4/fw.c
··· 463 463 464 464 field = min( 465 465 bitmap_weight(actv_ports.ports, dev->caps.num_ports), 466 - dev->caps.num_ports); 466 + (unsigned long)dev->caps.num_ports); 467 467 MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_NUM_PORTS_OFFSET); 468 468 469 469 size = dev->caps.function_caps; /* set PF behaviours */
+1 -1
drivers/net/wireless/ath/ath9k/htc_drv_debug.c
··· 296 296 spin_lock_bh(&priv->tx.tx_lock); 297 297 len = scnprintf(buf, sizeof(buf), 298 298 "TX slot bitmap : %*pb\n" 299 - "Used slots : %d\n", 299 + "Used slots : %ld\n", 300 300 MAX_TX_BUF_NUM, priv->tx.tx_slot, 301 301 bitmap_weight(priv->tx.tx_slot, MAX_TX_BUF_NUM)); 302 302 spin_unlock_bh(&priv->tx.tx_lock);
+1 -1
drivers/net/wireless/ath/carl9170/debug.c
··· 221 221 ADD(buf, *len, bufsize, "jar: [%*pb]\n", 222 222 ar->fw.mem_blocks, ar->mem_bitmap); 223 223 224 - ADD(buf, *len, bufsize, "cookies: used:%3d / total:%3d, allocs:%d\n", 224 + ADD(buf, *len, bufsize, "cookies: used:%3ld / total:%3d, allocs:%d\n", 225 225 bitmap_weight(ar->mem_bitmap, ar->fw.mem_blocks), 226 226 ar->fw.mem_blocks, atomic_read(&ar->mem_allocs)); 227 227
+3 -2
include/linux/bitmap.h
··· 163 163 const unsigned long *bitmap2, unsigned int nbits); 164 164 bool __bitmap_subset(const unsigned long *bitmap1, 165 165 const unsigned long *bitmap2, unsigned int nbits); 166 - int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits); 166 + unsigned long __bitmap_weight(const unsigned long *bitmap, unsigned int nbits); 167 167 void __bitmap_set(unsigned long *map, unsigned int start, int len); 168 168 void __bitmap_clear(unsigned long *map, unsigned int start, int len); 169 169 ··· 431 431 return find_first_zero_bit(src, nbits) == nbits; 432 432 } 433 433 434 - static __always_inline int bitmap_weight(const unsigned long *src, unsigned int nbits) 434 + static __always_inline 435 + unsigned long bitmap_weight(const unsigned long *src, unsigned int nbits) 435 436 { 436 437 if (small_const_nbits(nbits)) 437 438 return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
+2 -3
lib/bitmap.c
··· 333 333 } 334 334 EXPORT_SYMBOL(__bitmap_subset); 335 335 336 - int __bitmap_weight(const unsigned long *bitmap, unsigned int bits) 336 + unsigned long __bitmap_weight(const unsigned long *bitmap, unsigned int bits) 337 337 { 338 - unsigned int k, lim = bits/BITS_PER_LONG; 339 - int w = 0; 338 + unsigned long k, w = 0, lim = bits/BITS_PER_LONG; 340 339 341 340 for (k = 0; k < lim; k++) 342 341 w += hweight_long(bitmap[k]);
+2 -2
tools/include/linux/bitmap.h
··· 11 11 #define DECLARE_BITMAP(name,bits) \ 12 12 unsigned long name[BITS_TO_LONGS(bits)] 13 13 14 - int __bitmap_weight(const unsigned long *bitmap, int bits); 14 + unsigned long __bitmap_weight(const unsigned long *bitmap, unsigned int bits); 15 15 void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, 16 16 const unsigned long *bitmap2, int bits); 17 17 bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, ··· 61 61 return find_first_zero_bit(src, nbits) == nbits; 62 62 } 63 63 64 - static inline int bitmap_weight(const unsigned long *src, unsigned int nbits) 64 + static inline unsigned long bitmap_weight(const unsigned long *src, unsigned int nbits) 65 65 { 66 66 if (small_const_nbits(nbits)) 67 67 return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
+2 -2
tools/lib/bitmap.c
··· 5 5 */ 6 6 #include <linux/bitmap.h> 7 7 8 - int __bitmap_weight(const unsigned long *bitmap, int bits) 8 + unsigned long __bitmap_weight(const unsigned long *bitmap, unsigned int bits) 9 9 { 10 - int k, w = 0, lim = bits/BITS_PER_LONG; 10 + unsigned long k, w = 0, lim = bits/BITS_PER_LONG; 11 11 12 12 for (k = 0; k < lim; k++) 13 13 w += hweight_long(bitmap[k]);