pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bsc/+/38081?usp=email )
Change subject: Clarify code around bts->loc_list ......................................................................
Clarify code around bts->loc_list
In set_bts_loc(): * Comment stating the entry was appended to the list was wrong. * location_equal() could be called with lastloc containing poisoned pointers (INIT_LLIST_HEAD), which is not that nice.
Change-Id: I5b706dfd3a96f5e9b61907a727ef5887338e66c6 --- M src/osmo-bsc/bsc_vty.c M src/osmo-bsc/bts_ctrl.c 2 files changed, 6 insertions(+), 6 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/81/38081/1
diff --git a/src/osmo-bsc/bsc_vty.c b/src/osmo-bsc/bsc_vty.c index aa31505..777807b 100644 --- a/src/osmo-bsc/bsc_vty.c +++ b/src/osmo-bsc/bsc_vty.c @@ -3289,12 +3289,12 @@ char timestr[50];
llist_for_each_entry(bts, &bsc_gsmnet->bts_list, list) { - if (llist_empty(&bts->loc_list)) { + curloc = llist_first_entry_or_null(&bts->loc_list, struct bts_location, list); + if (!curloc) { vty_out(vty, "BTS Nr: %d position invalid%s", bts->nr, VTY_NEWLINE); continue; } - curloc = llist_entry(bts->loc_list.next, struct bts_location, list); if (gmtime_r(&curloc->tstamp, &time) == NULL) { vty_out(vty, "Time conversion failed for BTS %d%s", bts->nr, VTY_NEWLINE); diff --git a/src/osmo-bsc/bts_ctrl.c b/src/osmo-bsc/bts_ctrl.c index f10ba29..48b1b8a 100644 --- a/src/osmo-bsc/bts_ctrl.c +++ b/src/osmo-bsc/bts_ctrl.c @@ -128,7 +128,7 @@ return CTRL_CMD_REPLY; }
- curloc = llist_entry(bts->loc_list.next, struct bts_location, list); + curloc = llist_first_entry(&bts->loc_list, struct bts_location, list);
cmd->reply = talloc_asprintf(cmd, "%lu,%s,%f,%f,%f", curloc->tstamp, get_value_string(bts_loc_fix_names, curloc->valid), curloc->lat, curloc->lon, curloc->height); @@ -183,14 +183,14 @@ curloc->height = atof(height); talloc_free(tmp);
- lastloc = llist_entry(bts->loc_list.next, struct bts_location, list); + lastloc = llist_first_entry_or_null(&bts->loc_list, struct bts_location, list);
- /* Add location to the end of the list */ + /* Add location to the start of the list */ llist_add(&curloc->list, &bts->loc_list);
ret = get_bts_loc(cmd, data);
- if (!location_equal(curloc, lastloc)) + if (!lastloc || !location_equal(curloc, lastloc)) bsc_gen_location_state_trap(bts);
cleanup_locations(&bts->loc_list);