From 879dc0bfb4b81e8e17a5436009b70d95d9485870 Mon Sep 17 00:00:00 2001 From: Tau Date: Sun, 3 Nov 2019 11:02:54 -0500 Subject: [PATCH] Use new iohook_open_nul_fd() API Makes error handling more consistent --- amex/ds.c | 6 +++++- amex/gpio.c | 7 ++++++- amex/jvs.c | 7 ++++++- board/io4.c | 17 +++++++++++++++-- platform/hwmon.c | 16 ++++++++++++++-- platform/nusec.c | 7 ++++++- 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/amex/ds.c b/amex/ds.c index 4c69f69..15b7d3b 100644 --- a/amex/ds.c +++ b/amex/ds.c @@ -85,7 +85,11 @@ HRESULT ds_hook_init(const struct ds_config *cfg) return hr; } - ds_fd = iohook_open_dummy_fd(); + hr = iohook_open_nul_fd(&ds_fd); + + if (FAILED(hr)) { + return hr; + } return S_OK; } diff --git a/amex/gpio.c b/amex/gpio.c index cba3b7d..3e8ac3e 100644 --- a/amex/gpio.c +++ b/amex/gpio.c @@ -89,7 +89,12 @@ HRESULT gpio_hook_init(const struct gpio_config *cfg) memcpy(&gpio_config, cfg, sizeof(*cfg)); - gpio_fd = iohook_open_dummy_fd(); + hr = iohook_open_nul_fd(&gpio_fd); + + if (FAILED(hr)) { + return hr; + } + hr = iohook_push_handler(gpio_handle_irp); if (FAILED(hr)) { diff --git a/amex/jvs.c b/amex/jvs.c index 4f7c2b4..1097267 100644 --- a/amex/jvs.c +++ b/amex/jvs.c @@ -50,7 +50,12 @@ HRESULT jvs_hook_init(const struct jvs_config *cfg) return S_FALSE; } - jvs_fd = iohook_open_dummy_fd(); + hr = iohook_open_nul_fd(&jvs_fd); + + if (FAILED(hr)) { + return hr; + } + hr = iohook_push_handler(jvs_handle_irp); if (FAILED(hr)) { diff --git a/board/io4.c b/board/io4.c index a549620..9140ee4 100644 --- a/board/io4.c +++ b/board/io4.c @@ -99,17 +99,30 @@ static void *io4_ops_ctx; HRESULT io4_hook_init(const struct io4_ops *ops, void *ctx) { + HRESULT hr; + assert(ops != NULL); async_init(&io4_async, NULL); - io4_fd = iohook_open_dummy_fd(); + hr = iohook_open_nul_fd(&io4_fd); + + if (FAILED(hr)) { + return hr; + } + io4_ops = ops; io4_ops_ctx = ctx; io4_system_status = 0x02; /* idk */ iohook_push_handler(io4_handle_irp); - return setupapi_add_phantom_dev(&hid_guid, io4_path); + hr = setupapi_add_phantom_dev(&hid_guid, io4_path); + + if (FAILED(hr)) { + return hr; + } + + return S_OK; } static HRESULT io4_handle_irp(struct irp *irp) diff --git a/platform/hwmon.c b/platform/hwmon.c index 8b4560b..7f1ea7b 100644 --- a/platform/hwmon.c +++ b/platform/hwmon.c @@ -26,15 +26,27 @@ static HANDLE hwmon_fd; HRESULT hwmon_hook_init(const struct hwmon_config *cfg) { + HRESULT hr; + assert(cfg != NULL); if (!cfg->enable) { return S_FALSE; } - hwmon_fd = iohook_open_dummy_fd(); + hr = iohook_open_nul_fd(&hwmon_fd); - return iohook_push_handler(hwmon_handle_irp); + if (FAILED(hr)) { + return hr; + } + + hr = iohook_push_handler(hwmon_handle_irp); + + if (FAILED(hr)) { + return hr; + } + + return S_OK; } static HRESULT hwmon_handle_irp(struct irp *irp) diff --git a/platform/nusec.c b/platform/nusec.c index cf2a19f..f9ff413 100644 --- a/platform/nusec.c +++ b/platform/nusec.c @@ -139,7 +139,12 @@ HRESULT nusec_hook_init( nusec_nearfull = 0x00010200; nusec_play_count = 0; nusec_play_limit = 1024; - nusec_fd = iohook_open_dummy_fd(); + + hr = iohook_open_nul_fd(&nusec_fd); + + if (FAILED(hr)) { + return hr; + } hr = iohook_push_handler(nusec_handle_irp);