]> git.baikalelectronics.ru Git - kernel.git/commitdiff
lib/bitmap: change type of bitmap_weight to unsigned long
authorYury Norov <yury.norov@gmail.com>
Fri, 1 Jul 2022 12:54:25 +0000 (05:54 -0700)
committerYury Norov <yury.norov@gmail.com>
Fri, 15 Jul 2022 13:35:54 +0000 (06:35 -0700)
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>
12 files changed:
drivers/dma/ti/k3-udma.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
drivers/gpu/drm/i915/display/intel_display_power.c
drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c
drivers/iommu/intel/iommu.c
drivers/net/ethernet/mellanox/mlx4/fw.c
drivers/net/wireless/ath/ath9k/htc_drv_debug.c
drivers/net/wireless/ath/carl9170/debug.c
include/linux/bitmap.h
lib/bitmap.c
tools/include/linux/bitmap.h
tools/lib/bitmap.c

index 2f0d2c68c93c6152c433d47b4c4d5321feeec53b..07cb48db76bafe97ba3510b5470ee6a8159639a8 100644 (file)
@@ -4997,7 +4997,7 @@ static int setup_resources(struct udma_dev *ud)
        switch (ud->match_data->type) {
        case DMA_TYPE_UDMA:
                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,
                         ud->tchan_cnt - bitmap_weight(ud->tchan_map,
                                                       ud->tchan_cnt),
@@ -5008,7 +5008,7 @@ static int setup_resources(struct udma_dev *ud)
                break;
        case DMA_TYPE_BCDMA:
                dev_info(dev,
-                        "Channels: %d (bchan: %u, tchan: %u, rchan: %u)\n",
+                        "Channels: %d (bchan: %lu, tchan: %lu, rchan: %lu)\n",
                         ch_count,
                         ud->bchan_cnt - bitmap_weight(ud->bchan_map,
                                                       ud->bchan_cnt),
@@ -5019,7 +5019,7 @@ static int setup_resources(struct udma_dev *ud)
                break;
        case DMA_TYPE_PKTDMA:
                dev_info(dev,
-                        "Channels: %d (tchan: %u, rchan: %u)\n",
+                        "Channels: %d (tchan: %lu, rchan: %lu)\n",
                         ch_count,
                         ud->tchan_cnt - bitmap_weight(ud->tchan_map,
                                                       ud->tchan_cnt),
index 16699158e00d8c47dc1a6908966c72fd10bb7e77..1098506ba1aaf179ea6aa5f06b6690007f4314bb 100644 (file)
@@ -195,7 +195,7 @@ void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
                        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)
index 949edc983a16951f207f5bf95797430f282ba2bd..4204e8a0e1a60900bca09d68f65e351d5dd4eaea 100644 (file)
@@ -378,7 +378,7 @@ static void print_power_domains(struct i915_power_domains *power_domains,
                                                     power_domains);
        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)
                drm_dbg(&i915->drm, "%s use_count %d\n",
                        intel_display_power_domain_str(domain),
index 56a3063545ec467a8313844da8bb41e2f3435461..3d35b3982a60cebc4ec02c7bd2b25012cf2248dd 100644 (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, "AVAIL:\t%d\n", smp->blk_cnt -
+       drm_printf(p, "AVAIL:\t%ld\n", smp->blk_cnt -
                        bitmap_weight(state->state, smp->blk_cnt));
 
        if (drm_can_sleep())
index 44016594831de562b80c59e2d964f26a4e1a27fe..2f1b09f347069b9d55c7d09e3d4b27f2894087ce 100644 (file)
@@ -3946,7 +3946,7 @@ static ssize_t domains_used_show(struct device *dev,
                                 struct device_attribute *attr, char *buf)
 {
        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)));
 }
 static DEVICE_ATTR_RO(domains_used);
index 42c96c9d7fb16d1432afde6b3cefad765331d4c4..af054a3808caee89d624e53fec91ba829b041ac8 100644 (file)
@@ -463,7 +463,7 @@ int mlx4_QUERY_FUNC_CAP_wrapper(struct mlx4_dev *dev, int slave,
 
                field = min(
                        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);
 
                size = dev->caps.function_caps; /* set PF behaviours */
index b3ed65e5c4da81f62bb6f4519ed2015fa0c62459..d32056c4ee1d8cab664f872abf4d7176797e5c99 100644 (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);
        len = scnprintf(buf, sizeof(buf),
                        "TX slot bitmap : %*pb\n"
-                       "Used slots     : %d\n",
+                       "Used slots     : %ld\n",
                        MAX_TX_BUF_NUM, priv->tx.tx_slot,
                        bitmap_weight(priv->tx.tx_slot, MAX_TX_BUF_NUM));
        spin_unlock_bh(&priv->tx.tx_lock);
index bb40889d7c720d4ebfe4713540f273d8a3394665..7e88882b87d9c20a5cdf6e0eda797e0af9f0ea4b 100644 (file)
@@ -221,7 +221,7 @@ static char *carl9170_debugfs_mem_usage_read(struct ar9170 *ar, char *buf,
        ADD(buf, *len, bufsize, "jar: [%*pb]\n",
            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),
            ar->fw.mem_blocks, atomic_read(&ar->mem_allocs));
 
index e1a438bdda52bcc24711fd9534af753a4e0a5b55..035d4ac666419dc616e7cfdc2325a54e200690ad 100644 (file)
@@ -163,7 +163,7 @@ bool __bitmap_intersects(const unsigned long *bitmap1,
                         const unsigned long *bitmap2, unsigned int nbits);
 bool __bitmap_subset(const unsigned long *bitmap1,
                     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_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;
 }
 
-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))
                return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
index 9bc80f5bf149c8bf27d8c39f5e077944981b6f07..2b67cd65769243400ebd2f1f1f273b2bbddab4d7 100644 (file)
@@ -333,10 +333,9 @@ bool __bitmap_subset(const unsigned long *bitmap1,
 }
 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;
-       int w = 0;
+       unsigned long k, w = 0, lim = bits/BITS_PER_LONG;
 
        for (k = 0; k < lim; k++)
                w += hweight_long(bitmap[k]);
index 2ae7ab8ed7d16ee1d60a193e694c515c36811dcf..ae1852e39142307c0541cc7cb01c73d2526ad117 100644 (file)
@@ -11,7 +11,7 @@
 #define DECLARE_BITMAP(name,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,
                 const unsigned long *bitmap2, int bits);
 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;
 }
 
-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))
                return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
index 2e351d63fdbaeaf89c1750ceb85fa3ca0e52f443..e1fafc131a49c2aecef6846be1f9accd062b5a75 100644 (file)
@@ -5,9 +5,9 @@
  */
 #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++)
                w += hweight_long(bitmap[k]);