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>
This commit is contained in:
Yury Norov 2022-07-01 05:54:25 -07:00
parent e2863a7859
commit 4dea97f863
12 changed files with 19 additions and 19 deletions

View file

@ -4997,7 +4997,7 @@ static int setup_resources(struct udma_dev *ud)
switch (ud->match_data->type) { switch (ud->match_data->type) {
case DMA_TYPE_UDMA: case DMA_TYPE_UDMA:
dev_info(dev, dev_info(dev,
"Channels: %d (tchan: %u, rchan: %u, gp-rflow: %u)\n", "Channels: %d (tchan: %lu, rchan: %lu, gp-rflow: %lu)\n",
ch_count, ch_count,
ud->tchan_cnt - bitmap_weight(ud->tchan_map, ud->tchan_cnt - bitmap_weight(ud->tchan_map,
ud->tchan_cnt), ud->tchan_cnt),
@ -5008,7 +5008,7 @@ static int setup_resources(struct udma_dev *ud)
break; break;
case DMA_TYPE_BCDMA: case DMA_TYPE_BCDMA:
dev_info(dev, dev_info(dev,
"Channels: %d (bchan: %u, tchan: %u, rchan: %u)\n", "Channels: %d (bchan: %lu, tchan: %lu, rchan: %lu)\n",
ch_count, ch_count,
ud->bchan_cnt - bitmap_weight(ud->bchan_map, ud->bchan_cnt - bitmap_weight(ud->bchan_map,
ud->bchan_cnt), ud->bchan_cnt),
@ -5019,7 +5019,7 @@ static int setup_resources(struct udma_dev *ud)
break; break;
case DMA_TYPE_PKTDMA: case DMA_TYPE_PKTDMA:
dev_info(dev, dev_info(dev,
"Channels: %d (tchan: %u, rchan: %u)\n", "Channels: %d (tchan: %lu, rchan: %lu)\n",
ch_count, ch_count,
ud->tchan_cnt - bitmap_weight(ud->tchan_map, ud->tchan_cnt - bitmap_weight(ud->tchan_map,
ud->tchan_cnt), ud->tchan_cnt),

View file

@ -195,7 +195,7 @@ void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
set_bit(i, adev->gfx.mec.queue_bitmap); set_bit(i, adev->gfx.mec.queue_bitmap);
} }
dev_dbg(adev->dev, "mec queue bitmap weight=%d\n", bitmap_weight(adev->gfx.mec.queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES)); dev_dbg(adev->dev, "mec queue bitmap weight=%ld\n", bitmap_weight(adev->gfx.mec.queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES));
} }
void amdgpu_gfx_graphics_queue_acquire(struct amdgpu_device *adev) void amdgpu_gfx_graphics_queue_acquire(struct amdgpu_device *adev)

View file

@ -378,7 +378,7 @@ static void print_power_domains(struct i915_power_domains *power_domains,
power_domains); power_domains);
enum intel_display_power_domain domain; enum intel_display_power_domain domain;
drm_dbg(&i915->drm, "%s (%d):\n", prefix, bitmap_weight(mask->bits, POWER_DOMAIN_NUM)); drm_dbg(&i915->drm, "%s (%ld):\n", prefix, bitmap_weight(mask->bits, POWER_DOMAIN_NUM));
for_each_power_domain(domain, mask) for_each_power_domain(domain, mask)
drm_dbg(&i915->drm, "%s use_count %d\n", drm_dbg(&i915->drm, "%s use_count %d\n",
intel_display_power_domain_str(domain), intel_display_power_domain_str(domain),

View file

@ -363,7 +363,7 @@ void mdp5_smp_dump(struct mdp5_smp *smp, struct drm_printer *p)
} }
drm_printf(p, "TOTAL:\t%d\t(of %d)\n", total, smp->blk_cnt); drm_printf(p, "TOTAL:\t%d\t(of %d)\n", total, smp->blk_cnt);
drm_printf(p, "AVAIL:\t%d\n", smp->blk_cnt - drm_printf(p, "AVAIL:\t%ld\n", smp->blk_cnt -
bitmap_weight(state->state, smp->blk_cnt)); bitmap_weight(state->state, smp->blk_cnt));
if (drm_can_sleep()) if (drm_can_sleep())

View file

@ -3946,7 +3946,7 @@ static ssize_t domains_used_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct intel_iommu *iommu = dev_to_intel_iommu(dev); struct intel_iommu *iommu = dev_to_intel_iommu(dev);
return sprintf(buf, "%d\n", bitmap_weight(iommu->domain_ids, return sprintf(buf, "%ld\n", bitmap_weight(iommu->domain_ids,
cap_ndoms(iommu->cap))); cap_ndoms(iommu->cap)));
} }
static DEVICE_ATTR_RO(domains_used); static DEVICE_ATTR_RO(domains_used);

View file

@ -463,7 +463,7 @@ int mlx4_QUERY_FUNC_CAP_wrapper(struct mlx4_dev *dev, int slave,
field = min( field = min(
bitmap_weight(actv_ports.ports, dev->caps.num_ports), bitmap_weight(actv_ports.ports, dev->caps.num_ports),
dev->caps.num_ports); (unsigned long)dev->caps.num_ports);
MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_NUM_PORTS_OFFSET); MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_NUM_PORTS_OFFSET);
size = dev->caps.function_caps; /* set PF behaviours */ size = dev->caps.function_caps; /* set PF behaviours */

View file

@ -296,7 +296,7 @@ static ssize_t read_file_slot(struct file *file, char __user *user_buf,
spin_lock_bh(&priv->tx.tx_lock); spin_lock_bh(&priv->tx.tx_lock);
len = scnprintf(buf, sizeof(buf), len = scnprintf(buf, sizeof(buf),
"TX slot bitmap : %*pb\n" "TX slot bitmap : %*pb\n"
"Used slots : %d\n", "Used slots : %ld\n",
MAX_TX_BUF_NUM, priv->tx.tx_slot, MAX_TX_BUF_NUM, priv->tx.tx_slot,
bitmap_weight(priv->tx.tx_slot, MAX_TX_BUF_NUM)); bitmap_weight(priv->tx.tx_slot, MAX_TX_BUF_NUM));
spin_unlock_bh(&priv->tx.tx_lock); spin_unlock_bh(&priv->tx.tx_lock);

View file

@ -221,7 +221,7 @@ static char *carl9170_debugfs_mem_usage_read(struct ar9170 *ar, char *buf,
ADD(buf, *len, bufsize, "jar: [%*pb]\n", ADD(buf, *len, bufsize, "jar: [%*pb]\n",
ar->fw.mem_blocks, ar->mem_bitmap); ar->fw.mem_blocks, ar->mem_bitmap);
ADD(buf, *len, bufsize, "cookies: used:%3d / total:%3d, allocs:%d\n", ADD(buf, *len, bufsize, "cookies: used:%3ld / total:%3d, allocs:%d\n",
bitmap_weight(ar->mem_bitmap, ar->fw.mem_blocks), bitmap_weight(ar->mem_bitmap, ar->fw.mem_blocks),
ar->fw.mem_blocks, atomic_read(&ar->mem_allocs)); ar->fw.mem_blocks, atomic_read(&ar->mem_allocs));

View file

@ -163,7 +163,7 @@ bool __bitmap_intersects(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits); const unsigned long *bitmap2, unsigned int nbits);
bool __bitmap_subset(const unsigned long *bitmap1, bool __bitmap_subset(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits); const unsigned long *bitmap2, unsigned int nbits);
int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits); unsigned long __bitmap_weight(const unsigned long *bitmap, unsigned int nbits);
void __bitmap_set(unsigned long *map, unsigned int start, int len); void __bitmap_set(unsigned long *map, unsigned int start, int len);
void __bitmap_clear(unsigned long *map, unsigned int start, int len); void __bitmap_clear(unsigned long *map, unsigned int start, int len);
@ -431,7 +431,8 @@ static inline bool bitmap_full(const unsigned long *src, unsigned int nbits)
return find_first_zero_bit(src, nbits) == nbits; return find_first_zero_bit(src, nbits) == nbits;
} }
static __always_inline int bitmap_weight(const unsigned long *src, unsigned int nbits) static __always_inline
unsigned long bitmap_weight(const unsigned long *src, unsigned int nbits)
{ {
if (small_const_nbits(nbits)) if (small_const_nbits(nbits))
return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));

View file

@ -333,10 +333,9 @@ bool __bitmap_subset(const unsigned long *bitmap1,
} }
EXPORT_SYMBOL(__bitmap_subset); EXPORT_SYMBOL(__bitmap_subset);
int __bitmap_weight(const unsigned long *bitmap, unsigned int bits) unsigned long __bitmap_weight(const unsigned long *bitmap, unsigned int bits)
{ {
unsigned int k, lim = bits/BITS_PER_LONG; unsigned long k, w = 0, lim = bits/BITS_PER_LONG;
int w = 0;
for (k = 0; k < lim; k++) for (k = 0; k < lim; k++)
w += hweight_long(bitmap[k]); w += hweight_long(bitmap[k]);

View file

@ -11,7 +11,7 @@
#define DECLARE_BITMAP(name,bits) \ #define DECLARE_BITMAP(name,bits) \
unsigned long name[BITS_TO_LONGS(bits)] unsigned long name[BITS_TO_LONGS(bits)]
int __bitmap_weight(const unsigned long *bitmap, int bits); unsigned long __bitmap_weight(const unsigned long *bitmap, unsigned int bits);
void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, int bits); const unsigned long *bitmap2, int bits);
bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
@ -61,7 +61,7 @@ static inline bool bitmap_full(const unsigned long *src, unsigned int nbits)
return find_first_zero_bit(src, nbits) == nbits; return find_first_zero_bit(src, nbits) == nbits;
} }
static inline int bitmap_weight(const unsigned long *src, unsigned int nbits) static inline unsigned long bitmap_weight(const unsigned long *src, unsigned int nbits)
{ {
if (small_const_nbits(nbits)) if (small_const_nbits(nbits))
return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));

View file

@ -5,9 +5,9 @@
*/ */
#include <linux/bitmap.h> #include <linux/bitmap.h>
int __bitmap_weight(const unsigned long *bitmap, int bits) unsigned long __bitmap_weight(const unsigned long *bitmap, unsigned int bits)
{ {
int k, w = 0, lim = bits/BITS_PER_LONG; unsigned long k, w = 0, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; k++) for (k = 0; k < lim; k++)
w += hweight_long(bitmap[k]); w += hweight_long(bitmap[k]);