summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2019-09-11 01:48:11 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2019-09-11 01:55:38 +0200
commit9655ed5cf542d903570420fb95d7702f9af6ae05 (patch)
tree3951dacfe74b2d2d25b2d49802efedcd66727e4c /src
parent097b5099c4a06626b3f3b1380cb56706431cfeac (diff)
tdef: fixup osmo_tdef_set()
I missed code review, so here are my comments in form of a follow-up patch for Id56a1226d724a374f04231df85fe5b49ffd2c43c. - Fix 'as_unit' arg name to 'val_unit' as in the C file and API doc. - Explain rounding-up behavior of value conversion in API doc. - Use osmo_tdef_get_entry() instead of a loop. Related: OS#4190 Change-Id: Ia91c2f17e40fb9e79ffa5a7f28ce9c3605664402
Diffstat (limited to 'src')
-rw-r--r--src/tdef.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/tdef.c b/src/tdef.c
index dfb47f68..ab6a51b4 100644
--- a/src/tdef.c
+++ b/src/tdef.c
@@ -212,6 +212,7 @@ struct osmo_tdef *osmo_tdef_get_entry(struct osmo_tdef *tdefs, int T)
}
/*! Set value in entry matching T, converting val from val_unit to unit of T.
+ * The converted value is rounded up to the next integer value of T's unit and clamped to ULONG_MAX, or 0 if val == 0.
* \param[in] tdefs Array of timer definitions, last entry being fully zero.
* \param[in] T Timer number to set the value for.
* \param[in] val The new timer value to set.
@@ -220,14 +221,11 @@ struct osmo_tdef *osmo_tdef_get_entry(struct osmo_tdef *tdefs, int T)
*/
int osmo_tdef_set(struct osmo_tdef *tdefs, int T, unsigned long val, enum osmo_tdef_unit val_unit)
{
- struct osmo_tdef *t;
- osmo_tdef_for_each(t, tdefs) {
- if (t->T == T) {
- t->val = osmo_tdef_round(val, val_unit, t->unit);
- return 0;
- }
- }
- return -EEXIST;
+ struct osmo_tdef *t = osmo_tdef_get_entry(tdefs, T);
+ if (!t)
+ return -EEXIST;
+ t->val = osmo_tdef_round(val, val_unit, t->unit);
+ return 0;
}
/*! Using osmo_tdef for osmo_fsm_inst: find a given state's osmo_tdef_state_timeout entry.