diff options
| author | 2008-07-06 12:06:40 -0700 | |
|---|---|---|
| committer | 2008-07-06 12:06:40 -0700 | |
| commit | 8f942654d9c2b9cd957e8e1f7eb1f29a05bbf64a (patch) | |
| tree | 3cdb6f52867ee18af06f7e478fcaa9e15e7a8510 /src/dispatch.c | |
| parent | Fix raw1394_read_cycle_timer after juju integration (diff) | |
Change handle validation to prevent segfault and be more informative.
Diffstat (limited to 'src/dispatch.c')
| -rw-r--r-- | src/dispatch.c | 298 |
1 files changed, 248 insertions, 50 deletions
diff --git a/src/dispatch.c b/src/dispatch.c index aa40071..b15e8c5 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -9,6 +9,7 @@ */ #include <config.h> +#include <errno.h> #include "raw1394.h" #include "csr.h" @@ -54,7 +55,10 @@ raw1394handle_t raw1394_new_handle(void) void raw1394_destroy_handle(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + return; + } + if (handle->is_fw) fw_destroy_handle(handle->mode.fw); else ieee1394_destroy_handle(handle->mode.ieee1394);; @@ -85,7 +89,11 @@ raw1394handle_t raw1394_new_handle_on_port(int port) int raw1394_busreset_notify (raw1394handle_t handle, int off_on_switch) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_busreset_notify(handle->mode.fw, off_on_switch); else return ieee1394_busreset_notify(handle->mode.ieee1394, off_on_switch); @@ -93,7 +101,11 @@ int raw1394_busreset_notify (raw1394handle_t handle, int off_on_switch) int raw1394_get_fd(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_get_fd(handle->mode.fw); else return ieee1394_get_fd(handle->mode.ieee1394); @@ -101,7 +113,11 @@ int raw1394_get_fd(raw1394handle_t handle) nodeid_t raw1394_get_local_id(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return 0xFFFF; + } + if (handle->is_fw) return fw_get_local_id(handle->mode.fw); else return ieee1394_get_local_id(handle->mode.ieee1394); @@ -109,7 +125,11 @@ nodeid_t raw1394_get_local_id(raw1394handle_t handle) nodeid_t raw1394_get_irm_id(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return 0xFFFF; + } + if (handle->is_fw) return fw_get_irm_id(handle->mode.fw); else return ieee1394_get_irm_id(handle->mode.ieee1394); @@ -117,7 +137,11 @@ nodeid_t raw1394_get_irm_id(raw1394handle_t handle) int raw1394_get_nodecount(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_get_nodecount(handle->mode.fw); else return ieee1394_get_nodecount(handle->mode.ieee1394); @@ -126,7 +150,11 @@ int raw1394_get_nodecount(raw1394handle_t handle) int raw1394_get_port_info(raw1394handle_t handle, struct raw1394_portinfo *pinf, int maxports) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_get_port_info(handle->mode.fw, pinf, maxports); else return ieee1394_get_port_info(handle->mode.ieee1394, pinf, maxports); @@ -134,7 +162,11 @@ int raw1394_get_port_info(raw1394handle_t handle, struct raw1394_portinfo *pinf, int raw1394_set_port(raw1394handle_t handle, int port) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_set_port(handle->mode.fw, port); else return ieee1394_set_port(handle->mode.ieee1394, port); @@ -142,7 +174,11 @@ int raw1394_set_port(raw1394handle_t handle, int port) int raw1394_reset_bus_new(raw1394handle_t handle, int type) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_reset_bus_new(handle->mode.fw, type); else return ieee1394_reset_bus_new(handle->mode.ieee1394, type); @@ -150,7 +186,11 @@ int raw1394_reset_bus_new(raw1394handle_t handle, int type) int raw1394_loop_iterate(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_loop_iterate(handle); else return ieee1394_loop_iterate(handle); @@ -162,7 +202,11 @@ int raw1394_arm_register(raw1394handle_t handle, nodeaddr_t start, arm_options_t notification_options, arm_options_t client_transactions) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_arm_register(handle->mode.fw, start, length, initial_value, arm_tag, access_rights, notification_options, client_transactions); else @@ -173,7 +217,11 @@ int raw1394_arm_register(raw1394handle_t handle, nodeaddr_t start, int raw1394_arm_unregister(raw1394handle_t handle, nodeaddr_t start) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_arm_unregister(handle->mode.fw, start); else return ieee1394_arm_unregister(handle->mode.ieee1394, start); @@ -182,7 +230,11 @@ int raw1394_arm_unregister(raw1394handle_t handle, nodeaddr_t start) int raw1394_arm_set_buf (raw1394handle_t handle, nodeaddr_t start, size_t length, void *buf) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_arm_set_buf(handle->mode.fw, start, length, buf); else return ieee1394_arm_set_buf(handle->mode.ieee1394, start, length, buf); @@ -191,7 +243,11 @@ int raw1394_arm_set_buf (raw1394handle_t handle, nodeaddr_t start, int raw1394_arm_get_buf (raw1394handle_t handle, nodeaddr_t start, size_t length, void *buf) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_arm_get_buf(handle->mode.fw, start, length, buf); else return ieee1394_arm_get_buf(handle->mode.ieee1394, start, length, buf); @@ -199,7 +255,11 @@ int raw1394_arm_get_buf (raw1394handle_t handle, nodeaddr_t start, int raw1394_echo_request(raw1394handle_t handle, quadlet_t data) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_echo_request(handle->mode.fw, data); else return ieee1394_echo_request(handle->mode.ieee1394, data); @@ -207,7 +267,11 @@ int raw1394_echo_request(raw1394handle_t handle, quadlet_t data) int raw1394_wake_up(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_wake_up(handle->mode.fw); else return ieee1394_wake_up(handle->mode.ieee1394); @@ -215,7 +279,11 @@ int raw1394_wake_up(raw1394handle_t handle) int raw1394_phy_packet_write (raw1394handle_t handle, quadlet_t data) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_phy_packet_write(handle->mode.fw, data); else return ieee1394_phy_packet_write(handle, data); @@ -224,7 +292,11 @@ int raw1394_phy_packet_write (raw1394handle_t handle, quadlet_t data) int raw1394_start_phy_packet_write(raw1394handle_t handle, quadlet_t data, unsigned long tag) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_start_phy_packet_write(handle->mode.fw, data, tag); else return ieee1394_start_phy_packet_write(handle->mode.ieee1394, data, tag); @@ -233,7 +305,11 @@ int raw1394_start_phy_packet_write(raw1394handle_t handle, int raw1394_start_read(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr, size_t length, quadlet_t *buffer, unsigned long tag) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_start_read(handle->mode.fw, node, addr, length, buffer, tag); else return ieee1394_start_read(handle->mode.ieee1394, node, addr, length, buffer, tag); @@ -242,7 +318,11 @@ int raw1394_start_read(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr, int raw1394_start_write(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr, size_t length, quadlet_t *data, unsigned long tag) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_start_write(handle->mode.fw, node, addr, length, data, tag); else return ieee1394_start_write(handle->mode.ieee1394, node, addr, length, data, tag); @@ -252,7 +332,11 @@ int raw1394_start_lock(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr, unsigned int extcode, quadlet_t data, quadlet_t arg, quadlet_t *result, unsigned long tag) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_start_lock(handle->mode.fw, node, addr, extcode, data, arg, result, tag); else return ieee1394_start_lock(handle->mode.ieee1394, node, addr, extcode, data, arg, result, tag); @@ -262,7 +346,11 @@ int raw1394_start_lock64(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr, unsigned int extcode, octlet_t data, octlet_t arg, octlet_t *result, unsigned long tag) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_start_lock64(handle->mode.fw, node, addr, extcode, data, arg, result, tag); else return ieee1394_start_lock64(handle->mode.ieee1394, node, addr, extcode, data, arg, result, tag); @@ -273,7 +361,11 @@ int raw1394_start_async_stream(raw1394handle_t handle, unsigned int channel, unsigned int speed, size_t length, quadlet_t *data, unsigned long rawtag) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_start_async_stream(handle->mode.fw, channel, tag, sy, speed, length, data, rawtag); else return ieee1394_start_async_stream(handle->mode.ieee1394, channel, tag, sy, speed, length, data, rawtag); @@ -284,7 +376,11 @@ int raw1394_start_async_send(raw1394handle_t handle, unsigned int expect_response, quadlet_t *data, unsigned long rawtag) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_start_async_send(handle->mode.fw, length, header_length, expect_response, data, rawtag); else @@ -295,7 +391,11 @@ int raw1394_start_async_send(raw1394handle_t handle, int raw1394_read(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr, size_t length, quadlet_t *buffer) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_read(handle, node, addr, length, buffer); else return ieee1394_read(handle, node, addr, length, buffer); @@ -304,7 +404,11 @@ int raw1394_read(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr, int raw1394_write(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr, size_t length, quadlet_t *data) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_write(handle, node, addr, length, data); else return ieee1394_write(handle, node, addr, length, data); @@ -314,7 +418,11 @@ int raw1394_lock(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr, unsigned int extcode, quadlet_t data, quadlet_t arg, quadlet_t *result) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_lock(handle, node, addr, extcode, data, arg, result); else return ieee1394_lock(handle, node, addr, extcode, data, arg, result); @@ -324,7 +432,11 @@ int raw1394_lock64(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr, unsigned int extcode, octlet_t data, octlet_t arg, octlet_t *result) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_lock64(handle, node, addr, extcode, data, arg, result); else return ieee1394_lock64(handle, node, addr, extcode, data, arg, result); @@ -334,7 +446,11 @@ int raw1394_async_stream(raw1394handle_t handle, unsigned int channel, unsigned int tag, unsigned int sy, unsigned int speed, size_t length, quadlet_t *data) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_async_stream(handle->mode.fw, channel, tag, sy, speed, length, data); else return ieee1394_async_stream(handle, channel, tag, sy, speed, length, data); @@ -345,7 +461,11 @@ int raw1394_async_send(raw1394handle_t handle, unsigned int expect_response, quadlet_t *data) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_async_send(handle->mode.fw, length, header_length, expect_response, data); else @@ -355,7 +475,11 @@ int raw1394_async_send(raw1394handle_t handle, int raw1394_start_fcp_listen(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_start_fcp_listen(handle->mode.fw); else return ieee1394_start_fcp_listen(handle); @@ -363,7 +487,11 @@ int raw1394_start_fcp_listen(raw1394handle_t handle) int raw1394_stop_fcp_listen(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_stop_fcp_listen(handle->mode.fw); else return ieee1394_stop_fcp_listen(handle); @@ -372,7 +500,11 @@ int raw1394_stop_fcp_listen(raw1394handle_t handle) int raw1394_update_config_rom(raw1394handle_t handle, const quadlet_t *new_rom, size_t size, unsigned char rom_version) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_update_config_rom(handle->mode.fw, new_rom, size, rom_version); else return ieee1394_update_config_rom(handle->mode.ieee1394, @@ -382,7 +514,11 @@ int raw1394_update_config_rom(raw1394handle_t handle, const quadlet_t int raw1394_get_config_rom(raw1394handle_t handle, quadlet_t *buffer, size_t buffersize, size_t *rom_size, unsigned char *rom_version) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_get_config_rom(handle->mode.fw, buffer, buffersize, rom_size, rom_version); else @@ -393,7 +529,11 @@ int raw1394_get_config_rom(raw1394handle_t handle, quadlet_t *buffer, int raw1394_bandwidth_modify (raw1394handle_t handle, unsigned int bandwidth, enum raw1394_modify_mode mode) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_bandwidth_modify(handle, bandwidth, mode); else return ieee1394_bandwidth_modify(handle, bandwidth, mode); @@ -402,7 +542,11 @@ int raw1394_bandwidth_modify (raw1394handle_t handle, unsigned int bandwidth, int raw1394_channel_modify (raw1394handle_t handle, unsigned int channel, enum raw1394_modify_mode mode) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_channel_modify(handle, channel, mode); else return ieee1394_channel_modify(handle, channel, mode); @@ -416,7 +560,11 @@ int raw1394_iso_xmit_init(raw1394handle_t handle, enum raw1394_iso_speed speed, int irq_interval) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_iso_xmit_init(handle->mode.fw, handler, buf_packets, max_packet_size, channel, speed, irq_interval); else @@ -432,7 +580,11 @@ int raw1394_iso_recv_init(raw1394handle_t handle, enum raw1394_iso_dma_recv_mode mode, int irq_interval) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_iso_recv_init(handle->mode.fw, handler, buf_packets, max_packet_size, channel, mode, irq_interval); else @@ -446,7 +598,11 @@ int raw1394_iso_multichannel_recv_init(raw1394handle_t handle, unsigned int max_packet_size, int irq_interval) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_iso_multichannel_recv_init(handle->mode.fw, handler, buf_packets, max_packet_size, irq_interval); else @@ -457,7 +613,11 @@ int raw1394_iso_multichannel_recv_init(raw1394handle_t handle, int raw1394_iso_recv_listen_channel(raw1394handle_t handle, unsigned char channel) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_iso_recv_listen_channel(handle->mode.fw, channel); else return ieee1394_iso_recv_listen_channel(handle->mode.ieee1394, channel); @@ -466,7 +626,11 @@ int raw1394_iso_recv_listen_channel(raw1394handle_t handle, int raw1394_iso_recv_unlisten_channel(raw1394handle_t handle, unsigned char channel) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_iso_recv_unlisten_channel(handle->mode.fw, channel); else return ieee1394_iso_recv_unlisten_channel(handle->mode.ieee1394, channel); @@ -474,7 +638,11 @@ int raw1394_iso_recv_unlisten_channel(raw1394handle_t handle, int raw1394_iso_recv_set_channel_mask(raw1394handle_t handle, u_int64_t mask) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_iso_recv_set_channel_mask(handle->mode.fw, mask); else return ieee1394_iso_recv_set_channel_mask(handle->mode.ieee1394, mask); @@ -483,7 +651,11 @@ int raw1394_iso_recv_set_channel_mask(raw1394handle_t handle, u_int64_t mask) int raw1394_iso_xmit_start(raw1394handle_t handle, int start_on_cycle, int prebuffer_packets) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_iso_xmit_start(handle, start_on_cycle, prebuffer_packets); else @@ -494,7 +666,11 @@ int raw1394_iso_xmit_start(raw1394handle_t handle, int start_on_cycle, int raw1394_iso_recv_start(raw1394handle_t handle, int start_on_cycle, int tag_mask, int sync) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_iso_recv_start(handle->mode.fw, start_on_cycle, tag_mask, sync); else @@ -506,7 +682,11 @@ int raw1394_iso_xmit_write(raw1394handle_t handle, unsigned char *data, unsigned int len, unsigned char tag, unsigned char sy) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_iso_xmit_write(handle, data, len, tag, sy); else return ieee1394_iso_xmit_write(handle, data, len, tag, sy); @@ -514,7 +694,11 @@ int raw1394_iso_xmit_write(raw1394handle_t handle, unsigned char *data, int raw1394_iso_xmit_sync(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_iso_xmit_sync(handle); else return ieee1394_iso_xmit_sync(handle->mode.ieee1394); @@ -522,7 +706,11 @@ int raw1394_iso_xmit_sync(raw1394handle_t handle) int raw1394_iso_recv_flush(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_iso_recv_flush(handle->mode.fw); else return ieee1394_iso_recv_flush(handle->mode.ieee1394); @@ -530,7 +718,10 @@ int raw1394_iso_recv_flush(raw1394handle_t handle) void raw1394_iso_stop(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + return; + } + if (handle->is_fw) fw_iso_stop(handle->mode.fw); else ieee1394_iso_stop(handle->mode.ieee1394); @@ -538,7 +729,10 @@ void raw1394_iso_stop(raw1394handle_t handle) void raw1394_iso_shutdown(raw1394handle_t handle) { - if (handle && handle->is_fw) + if (!handle) { + return; + } + if (handle->is_fw) fw_iso_shutdown(handle->mode.fw); else ieee1394_iso_shutdown(handle->mode.ieee1394); @@ -547,7 +741,11 @@ void raw1394_iso_shutdown(raw1394handle_t handle) int raw1394_read_cycle_timer(raw1394handle_t handle, u_int32_t *cycle_timer, u_int64_t *local_time) { - if (handle && handle->is_fw) + if (!handle) { + errno = EINVAL; + return -1; + } + if (handle->is_fw) return fw_read_cycle_timer(handle->mode.fw, cycle_timer, local_time); else |
