From ea70b9480d40206373fe5c8fbc50f97813196a4c Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Mon, 2 Jul 2018 09:42:31 -0700 Subject: [PATCH] qcacld-3.0: Introduce hdd_handle_to_context() Currently direct typecasting is used to convert an HDD handle to HDD context. Typecasting has the disadvantage that it does not allow the compiler to validate that the input item being typecast really is an hdd_handle_t. In order to allow the compiler to typecheck the input item introduce a converter API, and update the current existing typecasts to use the converter. Change-Id: Ifc7c3e062af234b378f1fb806cae0814ac52e423 CRs-Fixed: 2273915 --- core/hdd/inc/wlan_hdd_main.h | 11 +++++++++++ core/hdd/src/wlan_hdd_main.c | 2 +- core/hdd/src/wlan_hdd_stats.c | 7 +------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/core/hdd/inc/wlan_hdd_main.h b/core/hdd/inc/wlan_hdd_main.h index 3d7a0b9611f9..2ba4595eb1d6 100644 --- a/core/hdd/inc/wlan_hdd_main.h +++ b/core/hdd/inc/wlan_hdd_main.h @@ -3385,4 +3385,15 @@ mac_handle_t hdd_adapter_get_mac_handle(struct hdd_adapter *adapter) hdd_context_get_mac_handle(adapter->hdd_ctx) : NULL; } +/** + * hdd_handle_to_context() - turn an HDD handle into an HDD context + * @hdd_handle: HDD handle to be converted + * + * Return: HDD context referenced by @hdd_handle + */ +static inline +struct hdd_context *hdd_handle_to_context(hdd_handle_t hdd_handle) +{ + return (struct hdd_context *)hdd_handle; +} #endif /* end #if !defined(WLAN_HDD_MAIN_H) */ diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c index 7111a7c396c2..076f20537b26 100644 --- a/core/hdd/src/wlan_hdd_main.c +++ b/core/hdd/src/wlan_hdd_main.c @@ -1907,7 +1907,7 @@ static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx, void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg) { int ret; - struct hdd_context *hdd_ctx = (struct hdd_context *)hdd_handle; + struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle); uint8_t temp_band_cap; struct cds_config_info *cds_cfg = cds_get_ini_config(); uint8_t antenna_mode; diff --git a/core/hdd/src/wlan_hdd_stats.c b/core/hdd/src/wlan_hdd_stats.c index 14c0e53b42c7..228b4fd5d40a 100644 --- a/core/hdd/src/wlan_hdd_stats.c +++ b/core/hdd/src/wlan_hdd_stats.c @@ -2296,17 +2296,12 @@ void wlan_hdd_cfg80211_link_layer_stats_ext_callback(hdd_handle_t ctx, hdd_enter(); - if (!ctx) { - hdd_err("Invalid HDD context."); - return; - } - if (!rsp) { hdd_err("Invalid result."); return; } - hdd_ctx = (struct hdd_context *)ctx; + hdd_ctx = hdd_handle_to_context(ctx); linkLayer_stats_results = rsp; status = wlan_hdd_validate_context(hdd_ctx);