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

perf/smmuv3: Don't cast parameter in bit operations

While in this particular case it would not be a (critical) issue,
the pattern itself is bad and error prone in case somebody blindly
copies to their code.

Don't cast parameter to unsigned long pointer in the bit operations.
Instead copy to a local variable on stack of a proper type and use.

Note, new compilers might warn on this line for potential outbound access.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/20220209184758.56578-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Andy Shevchenko and committed by
Will Deacon
8ddf4eff 30de2b54

+3 -1
+3 -1
drivers/perf/arm_smmuv3_pmu.c
··· 654 654 static irqreturn_t smmu_pmu_handle_irq(int irq_num, void *data) 655 655 { 656 656 struct smmu_pmu *smmu_pmu = data; 657 + DECLARE_BITMAP(ovs, BITS_PER_TYPE(u64)); 657 658 u64 ovsr; 658 659 unsigned int idx; 659 660 ··· 664 663 665 664 writeq(ovsr, smmu_pmu->reloc_base + SMMU_PMCG_OVSCLR0); 666 665 667 - for_each_set_bit(idx, (unsigned long *)&ovsr, smmu_pmu->num_counters) { 666 + bitmap_from_u64(ovs, ovsr); 667 + for_each_set_bit(idx, ovs, smmu_pmu->num_counters) { 668 668 struct perf_event *event = smmu_pmu->events[idx]; 669 669 struct hw_perf_event *hwc; 670 670