diff --git a/include/hardware/audio.h b/include/hardware/audio.h index 3b734f77..b49dce62 100644 --- a/include/hardware/audio.h +++ b/include/hardware/audio.h @@ -682,7 +682,7 @@ static inline int audio_hw_device_open(const struct hw_module_t* module, struct audio_hw_device** device) { return module->methods->open(module, AUDIO_HARDWARE_INTERFACE, - (struct hw_device_t**)device); + TO_HW_DEVICE_T_OPEN(device)); } static inline int audio_hw_device_close(struct audio_hw_device* device) diff --git a/include/hardware/fb.h b/include/hardware/fb.h index 9df94165..65720a39 100644 --- a/include/hardware/fb.h +++ b/include/hardware/fb.h @@ -160,7 +160,7 @@ typedef struct framebuffer_device_t { static inline int framebuffer_open(const struct hw_module_t* module, struct framebuffer_device_t** device) { return module->methods->open(module, - GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device); + GRALLOC_HARDWARE_FB0, TO_HW_DEVICE_T_OPEN(device)); } static inline int framebuffer_close(struct framebuffer_device_t* device) { diff --git a/include/hardware/gralloc.h b/include/hardware/gralloc.h index 779915c8..3d5b91fa 100644 --- a/include/hardware/gralloc.h +++ b/include/hardware/gralloc.h @@ -372,7 +372,7 @@ typedef struct alloc_device_t { static inline int gralloc_open(const struct hw_module_t* module, struct alloc_device_t** device) { return module->methods->open(module, - GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device); + GRALLOC_HARDWARE_GPU0, TO_HW_DEVICE_T_OPEN(device)); } static inline int gralloc_close(struct alloc_device_t* device) { diff --git a/include/hardware/gralloc1.h b/include/hardware/gralloc1.h index 58c0e334..a1a2d696 100644 --- a/include/hardware/gralloc1.h +++ b/include/hardware/gralloc1.h @@ -290,7 +290,7 @@ typedef struct gralloc1_device { static inline int gralloc1_open(const struct hw_module_t* module, gralloc1_device_t** device) { return module->methods->open(module, GRALLOC_HARDWARE_MODULE_ID, - (struct hw_device_t**) device); + TO_HW_DEVICE_T_OPEN(device)); } static inline int gralloc1_close(gralloc1_device_t* device) { diff --git a/include/hardware/hardware.h b/include/hardware/hardware.h index 74f57aa4..bf076f6c 100644 --- a/include/hardware/hardware.h +++ b/include/hardware/hardware.h @@ -201,6 +201,12 @@ typedef struct hw_device_t { } hw_device_t; +#ifdef __cplusplus +#define TO_HW_DEVICE_T_OPEN(x) reinterpret_cast(x) +#else +#define TO_HW_DEVICE_T_OPEN(x) (struct hw_device_t**)(x) +#endif + /** * Name of the hal_module_info */ diff --git a/include/hardware/hdmi_cec.h b/include/hardware/hdmi_cec.h index ab70f92e..aa06384e 100644 --- a/include/hardware/hdmi_cec.h +++ b/include/hardware/hdmi_cec.h @@ -417,7 +417,7 @@ typedef struct hdmi_cec_device { static inline int hdmi_cec_open(const struct hw_module_t* module, struct hdmi_cec_device** device) { return module->methods->open(module, - HDMI_CEC_HARDWARE_INTERFACE, (struct hw_device_t**)device); + HDMI_CEC_HARDWARE_INTERFACE, TO_HW_DEVICE_T_OPEN(device)); } static inline int hdmi_cec_close(struct hdmi_cec_device* device) { diff --git a/include/hardware/hwcomposer.h b/include/hardware/hwcomposer.h index 61218bba..7eca7c1b 100644 --- a/include/hardware/hwcomposer.h +++ b/include/hardware/hwcomposer.h @@ -783,7 +783,7 @@ typedef struct hwc_composer_device_1 { static inline int hwc_open_1(const struct hw_module_t* module, hwc_composer_device_1_t** device) { return module->methods->open(module, - HWC_HARDWARE_COMPOSER, (struct hw_device_t**)device); + HWC_HARDWARE_COMPOSER, TO_HW_DEVICE_T_OPEN(device)); } static inline int hwc_close_1(hwc_composer_device_1_t* device) { diff --git a/include/hardware/hwcomposer2.h b/include/hardware/hwcomposer2.h index f4f6093d..35eedb08 100644 --- a/include/hardware/hwcomposer2.h +++ b/include/hardware/hwcomposer2.h @@ -740,7 +740,7 @@ typedef struct hwc2_device { static inline int hwc2_open(const struct hw_module_t* module, hwc2_device_t** device) { return module->methods->open(module, HWC_HARDWARE_COMPOSER, - (struct hw_device_t**) device); + TO_HW_DEVICE_T_OPEN(device)); } static inline int hwc2_close(hwc2_device_t* device) { diff --git a/include/hardware/keymaster0.h b/include/hardware/keymaster0.h index f020e5b1..52ac64b6 100644 --- a/include/hardware/keymaster0.h +++ b/include/hardware/keymaster0.h @@ -134,7 +134,7 @@ static inline int keymaster0_open(const struct hw_module_t* module, keymaster0_device_t** device) { int rc = module->methods->open(module, KEYSTORE_KEYMASTER, - (struct hw_device_t**) device); + TO_HW_DEVICE_T_OPEN(device)); return rc; } diff --git a/include/hardware/keymaster1.h b/include/hardware/keymaster1.h index afd202c0..99693806 100644 --- a/include/hardware/keymaster1.h +++ b/include/hardware/keymaster1.h @@ -536,7 +536,7 @@ typedef struct keymaster1_device keymaster1_device_t; /* Convenience API for opening and closing keymaster devices */ static inline int keymaster1_open(const struct hw_module_t* module, keymaster1_device_t** device) { - return module->methods->open(module, KEYSTORE_KEYMASTER, (struct hw_device_t**)device); + return module->methods->open(module, KEYSTORE_KEYMASTER, TO_HW_DEVICE_T_OPEN(device)); } static inline int keymaster1_close(keymaster1_device_t* device) { diff --git a/include/hardware/keymaster2.h b/include/hardware/keymaster2.h index 565ad2e3..f1993f88 100644 --- a/include/hardware/keymaster2.h +++ b/include/hardware/keymaster2.h @@ -420,7 +420,7 @@ typedef struct keymaster2_device keymaster2_device_t; /* Convenience API for opening and closing keymaster devices */ static inline int keymaster2_open(const struct hw_module_t* module, keymaster2_device_t** device) { - return module->methods->open(module, KEYSTORE_KEYMASTER, (struct hw_device_t**)device); + return module->methods->open(module, KEYSTORE_KEYMASTER, TO_HW_DEVICE_T_OPEN(device)); } static inline int keymaster2_close(keymaster2_device_t* device) { diff --git a/include/hardware/local_time_hal.h b/include/hardware/local_time_hal.h index 946e7997..1bbbf116 100644 --- a/include/hardware/local_time_hal.h +++ b/include/hardware/local_time_hal.h @@ -109,7 +109,7 @@ static inline int local_time_hw_device_open( struct local_time_hw_device** device) { return module->methods->open(module, LOCAL_TIME_HARDWARE_INTERFACE, - (struct hw_device_t**)device); + TO_HW_DEVICE_T_OPEN(device)); } static inline int local_time_hw_device_close(struct local_time_hw_device* device) diff --git a/include/hardware/nvram.h b/include/hardware/nvram.h index 859ea471..0654afef 100644 --- a/include/hardware/nvram.h +++ b/include/hardware/nvram.h @@ -326,7 +326,7 @@ typedef struct nvram_device nvram_device_t; static inline int nvram_open(const struct hw_module_t* module, nvram_device_t** device) { return module->methods->open(module, NVRAM_HARDWARE_DEVICE_ID, - (struct hw_device_t**)device); + TO_HW_DEVICE_T_OPEN(device)); } static inline int nvram_close(nvram_device_t* device) { diff --git a/include/hardware/radio.h b/include/hardware/radio.h index 145deb57..413f4133 100644 --- a/include/hardware/radio.h +++ b/include/hardware/radio.h @@ -285,7 +285,7 @@ static inline int radio_hw_device_open(const struct hw_module_t* module, struct radio_hw_device** device) { return module->methods->open(module, RADIO_HARDWARE_DEVICE, - (struct hw_device_t**)device); + TO_HW_DEVICE_T_OPEN(device)); } static inline int radio_hw_device_close(const struct radio_hw_device* device) diff --git a/include/hardware/sensors.h b/include/hardware/sensors.h index a883960c..d98c623f 100644 --- a/include/hardware/sensors.h +++ b/include/hardware/sensors.h @@ -1395,7 +1395,7 @@ typedef struct sensors_poll_device_1 { static inline int sensors_open(const struct hw_module_t* module, struct sensors_poll_device_t** device) { return module->methods->open(module, - SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); + SENSORS_HARDWARE_POLL, TO_HW_DEVICE_T_OPEN(device)); } static inline int sensors_close(struct sensors_poll_device_t* device) { @@ -1405,7 +1405,7 @@ static inline int sensors_close(struct sensors_poll_device_t* device) { static inline int sensors_open_1(const struct hw_module_t* module, sensors_poll_device_1_t** device) { return module->methods->open(module, - SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); + SENSORS_HARDWARE_POLL, TO_HW_DEVICE_T_OPEN(device)); } static inline int sensors_close_1(sensors_poll_device_1_t* device) { diff --git a/include/hardware/sound_trigger.h b/include/hardware/sound_trigger.h index e1abbc9e..d7828acd 100644 --- a/include/hardware/sound_trigger.h +++ b/include/hardware/sound_trigger.h @@ -124,7 +124,7 @@ static inline int sound_trigger_hw_device_open(const struct hw_module_t* module, struct sound_trigger_hw_device** device) { return module->methods->open(module, SOUND_TRIGGER_HARDWARE_INTERFACE, - (struct hw_device_t**)device); + TO_HW_DEVICE_T_OPEN(device)); } static inline int sound_trigger_hw_device_close(struct sound_trigger_hw_device* device) diff --git a/include/hardware/vibrator.h b/include/hardware/vibrator.h index 200adf09..361085f4 100644 --- a/include/hardware/vibrator.h +++ b/include/hardware/vibrator.h @@ -65,7 +65,7 @@ typedef struct vibrator_device { static inline int vibrator_open(const struct hw_module_t* module, vibrator_device_t** device) { - return module->methods->open(module, VIBRATOR_DEVICE_ID_MAIN, (struct hw_device_t**)device); + return module->methods->open(module, VIBRATOR_DEVICE_ID_MAIN, TO_HW_DEVICE_T_OPEN(device)); } __END_DECLS