Skip to content

Commit a928fdd

Browse files
carlo-galcodebot
authored andcommitted
sched: fix possible use of pointer from deleted cfg
Signed-off-by: Carlo Galiotto <[email protected]>
1 parent 93c94f8 commit a928fdd

File tree

2 files changed

+52
-39
lines changed

2 files changed

+52
-39
lines changed

lib/scheduler/pucch_scheduling/pucch_allocator_impl.cpp

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,24 @@ pucch_allocator_impl::get_pucch_res_pre_multiplexing(slot_point
13051305
// There is already a PUCCH resource for HARQ-ACK; if so, we use the info and configuration from this resource.
13061306
if (ue_current_grants.pucch_grants.harq_resource.has_value() and
13071307
ue_current_grants.pucch_grants.harq_resource.value().harq_id.pucch_set_idx == pucch_set_idx) {
1308-
harq_candidate_grant = ue_current_grants.pucch_grants.harq_resource.value();
1308+
const pucch_resource* pucch_res =
1309+
pucch_set_idx == pucch_res_set_idx::set_0
1310+
? resource_manager.reserve_f1_res_by_res_indicator(
1311+
sl_tx,
1312+
ue_current_grants.rnti,
1313+
ue_current_grants.pucch_grants.harq_resource.value().harq_id.pucch_res_ind,
1314+
pucch_cfg)
1315+
: resource_manager.reserve_f2_res_by_res_indicator(
1316+
sl_tx,
1317+
ue_current_grants.rnti,
1318+
ue_current_grants.pucch_grants.harq_resource.value().harq_id.pucch_res_ind,
1319+
pucch_cfg);
1320+
if (pucch_res == nullptr) {
1321+
srsran_assertion_failure("rnti={}: PUCCH HARQ-ACK resource previously reserved not available anymore",
1322+
ue_current_grants.rnti);
1323+
return std::nullopt;
1324+
}
1325+
harq_candidate_grant.pucch_res_cfg = pucch_res;
13091326
}
13101327
// Get a new PUCCH resource for HARQ-ACK from the correct PUCCH resource set.
13111328
else {
@@ -1338,22 +1355,19 @@ pucch_allocator_impl::get_pucch_res_pre_multiplexing(slot_point
13381355
candidate_resources.sr_resource.emplace(pucch_grant{.type = pucch_grant_type::sr});
13391356
pucch_grant& sr_candidate_grant = candidate_resources.sr_resource.value();
13401357

1341-
// There is already a PUCCH resource for SR; if so, we use the info and configuration from this resource.
1342-
if (ue_current_grants.pucch_grants.sr_resource.has_value()) {
1343-
sr_candidate_grant = ue_current_grants.pucch_grants.sr_resource.value();
1344-
}
1345-
// Get the new resource from the resource manager; the UCI bits will be added later.
1346-
else {
1347-
// TODO: handle case in which the resource is already used by the same UE.
1348-
const pucch_resource* sr_resource =
1349-
resource_manager.reserve_sr_res_available(sl_tx, ue_current_grants.rnti, pucch_cfg);
1350-
// Save the resources that have been generated; if at some point the allocation fails, we need to release them.
1351-
resource_manager.set_new_resource_allocation(ue_current_grants.rnti, pucch_resource_usage::SR);
1352-
if (sr_resource == nullptr) {
1353-
return std::nullopt;
1354-
}
1355-
sr_candidate_grant.pucch_res_cfg = sr_resource;
1358+
// Get the resource from the resource manager; the UCI bits will be added later.
1359+
// NOTE: if the SR resource was already assigned to this UE, the resource manager will only return the PUCCH config
1360+
// that was reserved previously.
1361+
const pucch_resource* sr_resource =
1362+
resource_manager.reserve_sr_res_available(sl_tx, ue_current_grants.rnti, pucch_cfg);
1363+
// Save the resources that have been generated; if at some point the allocation fails, we need to release them.
1364+
resource_manager.set_new_resource_allocation(ue_current_grants.rnti, pucch_resource_usage::SR);
1365+
if (sr_resource == nullptr) {
1366+
srsran_assertion_failure("rnti={}: PUCCH SR resource previously reserved not available anymore",
1367+
ue_current_grants.rnti);
1368+
return std::nullopt;
13561369
}
1370+
sr_candidate_grant.pucch_res_cfg = sr_resource;
13571371
// Only copy the SR bits, as at this stage we only need to consider the UCI bits assuming the resources still
13581372
// need to be multiplexed.
13591373
sr_candidate_grant.bits.harq_ack_nof_bits = 0U;
@@ -1365,22 +1379,19 @@ pucch_allocator_impl::get_pucch_res_pre_multiplexing(slot_point
13651379
candidate_resources.csi_resource.emplace(pucch_grant{.type = pucch_grant_type::csi});
13661380
pucch_grant& csi_candidate_grant = candidate_resources.csi_resource.value();
13671381

1368-
// There is already a PUCCH resource for SR; if so, we use the info and configuration from this resource.
1369-
if (ue_current_grants.pucch_grants.csi_resource.has_value()) {
1370-
csi_candidate_grant = ue_current_grants.pucch_grants.csi_resource.value();
1371-
}
1372-
// Get the new resource from the resource manager; the UCI bits will be added later.
1373-
else {
1374-
// TODO: handle case in which the resource is already used by the same UE.
1375-
const pucch_resource* csi_resource =
1376-
resource_manager.reserve_csi_resource(sl_tx, ue_current_grants.rnti, ue_cell_cfg);
1377-
// Save the resources that have been generated; if at some point the allocation fails, we need to release them.
1378-
resource_manager.set_new_resource_allocation(ue_current_grants.rnti, pucch_resource_usage::CSI);
1379-
if (csi_resource == nullptr) {
1380-
return std::nullopt;
1381-
}
1382-
csi_candidate_grant.pucch_res_cfg = csi_resource;
1382+
// Get the resource from the resource manager; the UCI bits will be added later.
1383+
// NOTE: if the CSI resource was already assigned to this UE, the resource manager will only return the PUCCH config
1384+
// that was reserved previously.
1385+
const pucch_resource* csi_resource =
1386+
resource_manager.reserve_csi_resource(sl_tx, ue_current_grants.rnti, ue_cell_cfg);
1387+
// Save the resources that have been generated; if at some point the allocation fails, we need to release them.
1388+
resource_manager.set_new_resource_allocation(ue_current_grants.rnti, pucch_resource_usage::CSI);
1389+
if (csi_resource == nullptr) {
1390+
srsran_assertion_failure("rnti={}: PUCCH CSI resource previously reserved not available anymore",
1391+
ue_current_grants.rnti);
1392+
return std::nullopt;
13831393
}
1394+
csi_candidate_grant.pucch_res_cfg = csi_resource;
13841395
// Only copy the HARQ-ACK bits, as at this stage we only need to consider the UCI bits assuming the resources still
13851396
// need to be multiplexed.
13861397
csi_candidate_grant.bits.harq_ack_nof_bits = 0U;

lib/scheduler/pucch_scheduling/pucch_allocator_impl.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ class pucch_allocator_impl final : public pucch_allocator
108108
public:
109109
pucch_grant_type type;
110110
// Only relevant for HARQ-ACK resources.
111-
harq_res_id harq_id;
112-
pucch_uci_bits bits;
111+
harq_res_id harq_id;
112+
pucch_uci_bits bits;
113+
// NOTE: The pointer to the PUCCH resource configuration can only be used within the same slot; this is to prevent
114+
// the possibility that the re-configurations can null the pointer before an allocation and the next.
113115
const pucch_resource* pucch_res_cfg = nullptr;
114116

115117
[[nodiscard]] pucch_format get_format() const
@@ -237,12 +239,12 @@ class pucch_allocator_impl final : public pucch_allocator
237239
// \brief Ring of PUCCH allocations indexed by slot.
238240
circular_array<slot_pucch_grants, cell_resource_allocator::RING_ALLOCATOR_SIZE> pucch_grants_alloc_grid;
239241

240-
constexpr static unsigned PUCCH_FORMAT_1_NOF_PRBS{1};
241-
const cell_configuration& cell_cfg;
242-
const unsigned max_pucch_grants_per_slot;
243-
const unsigned max_ul_grants_per_slot;
244-
slot_point last_sl_ind;
245-
pucch_resource_manager resource_manager;
242+
constexpr static unsigned PUCCH_FORMAT_1_NOF_PRBS{1};
243+
const cell_configuration& cell_cfg;
244+
const unsigned max_pucch_grants_per_slot;
245+
const unsigned max_ul_grants_per_slot;
246+
slot_point last_sl_ind;
247+
pucch_resource_manager resource_manager;
246248

247249
srslog::basic_logger& logger;
248250
};

0 commit comments

Comments
 (0)