Message ID | 20231212022749.625238-11-yury.norov@gmail.com (mailing list archive) |
---|---|
State | Handled Elsewhere |
Headers | show |
Series | bitops: add atomic find_bit() operations | expand |
On 12/11/23 18:27, Yury Norov wrote: > The function searches used_mask for a set bit in a for-loop bit by bit. > Simplify it by using atomic find_and_set_bit(), and make a nice > one-liner. > > Signed-off-by: Yury Norov <yury.norov@gmail.com> > Reviewed-by: Dave Jiang <dave.jiang@intel.com> > Acked-by: Vinod Koul <vkoul@kernel.org> Reviewed-by: Fenghua Yu <fenghua.yu@intel.com> Thanks. -Fenghua
diff --git a/drivers/dma/idxd/perfmon.c b/drivers/dma/idxd/perfmon.c index fdda6d604262..4dd9c0d979c3 100644 --- a/drivers/dma/idxd/perfmon.c +++ b/drivers/dma/idxd/perfmon.c @@ -134,13 +134,9 @@ static void perfmon_assign_hw_event(struct idxd_pmu *idxd_pmu, static int perfmon_assign_event(struct idxd_pmu *idxd_pmu, struct perf_event *event) { - int i; - - for (i = 0; i < IDXD_PMU_EVENT_MAX; i++) - if (!test_and_set_bit(i, idxd_pmu->used_mask)) - return i; + int i = find_and_set_bit(idxd_pmu->used_mask, IDXD_PMU_EVENT_MAX); - return -EINVAL; + return i < IDXD_PMU_EVENT_MAX ? i : -EINVAL; } /*