From bd1f01fd2770c893592f94c5449a9c23b5871c63 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Thu, 27 Oct 2022 15:19:39 +0200 Subject: Fix mess with struct tbf types passed to LOGPTBF macro It is quite common in all osmo-pcu code to have to convert between parent class "tbf" and children "dl_tbf"/"ul_tbf", or other way around. This commit adds new helper static inline functions to cast between those while doing type checks. This is used by new LOGPTBFDL and LOGPTBFUL macros to now expect the proper subclass and cast securely inside the macro itself, hence sparing all code calling those macros to have to cast explicitly the pointer to the parent "tbf" class. Change-Id: I7e4489ad4b93c9c8442213947e53c10b61fdc5e9 --- src/tbf_ul.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/tbf_ul.h') diff --git a/src/tbf_ul.h b/src/tbf_ul.h index 62b94567..d69220d6 100644 --- a/src/tbf_ul.h +++ b/src/tbf_ul.h @@ -143,7 +143,17 @@ bool ul_tbf_contention_resolution_done(const struct gprs_rlcmac_ul_tbf *tbf); struct osmo_fsm_inst *tbf_ul_ack_fi(const struct gprs_rlcmac_ul_tbf *tbf); void ul_tbf_contention_resolution_success(struct gprs_rlcmac_ul_tbf *tbf); -#define LOGPTBFUL(tbf, level, fmt, args...) LOGP(DTBFUL, level, "%s " fmt, tbf_name(tbf), ## args) +static inline struct gprs_rlcmac_tbf *ul_tbf_as_tbf(struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + return (struct gprs_rlcmac_tbf *)ul_tbf; +} + +static inline const struct gprs_rlcmac_tbf *ul_tbf_as_tbf_const(const struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + return (const struct gprs_rlcmac_tbf *)ul_tbf; +} + +#define LOGPTBFUL(ul_tbf, level, fmt, args...) LOGP(DTBFUL, level, "%s " fmt, tbf_name(ul_tbf_as_tbf_const(ul_tbf)), ## args) #ifdef __cplusplus } #endif -- cgit v1.2.3