Skip to content

Commit 2ccc2e8

Browse files
committed
telemetry: fix lock leak on slot alloc failure
During allocation of a counter slot, spinlock isn't released in case of failure. This could lead to deadlock in case of failed allocation. This change fixes that by adding the missing release operation. Signed-off-by: Wojciech Jablonski <wojciech.jablonski@intel.com>
1 parent de318aa commit 2ccc2e8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/debug/telemetry/performance_monitor.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ struct perf_data_item_comp *perf_data_getnext(void)
138138
* ,and always set bit on bitmap alloc.
139139
*/
140140
ret = perf_bitmap_setbit(&performance_data_bitmap, idx);
141-
if (ret < 0)
141+
if (ret < 0) {
142+
perf_bitmap_free(&performance_data_bitmap, idx);
142143
return NULL;
144+
}
143145
return &perf_data[idx];
144146
}
145147

@@ -451,18 +453,24 @@ static struct io_perf_data_item *io_perf_monitor_get_next_slot(struct io_perf_mo
451453

452454
ret = perf_bitmap_alloc(&self->io_performance_data_bitmap, &idx);
453455
if (ret < 0)
454-
return NULL;
456+
goto out_unlock;
455457
/* ref. FW did not set the bits, but here we do it to not have to use
456458
* isFree() check that the bitarray does not provide yet. Instead we will use isClear
457459
* ,and always set bit on bitmap alloc.
458460
*/
459461

460462
ret = perf_bitmap_setbit(&self->io_performance_data_bitmap, idx);
461-
if (ret < 0)
462-
return NULL;
463+
if (ret < 0) {
464+
perf_bitmap_free(&self->io_performance_data_bitmap, idx);
465+
goto out_unlock;
466+
}
463467

464468
k_spin_unlock(&self->lock, key);
465469
return &self->io_perf_data[idx];
470+
471+
out_unlock:
472+
k_spin_unlock(&self->lock, key);
473+
return NULL;
466474
}
467475

468476
int io_perf_monitor_release_slot(struct io_perf_data_item *item)

0 commit comments

Comments
 (0)