aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Dennedy <dan@dennedy.org>2008-07-06 12:06:40 -0700
committerDan Dennedy <dan@dennedy.org>2008-07-06 12:06:40 -0700
commit8f942654d9c2b9cd957e8e1f7eb1f29a05bbf64a (patch)
tree3cdb6f52867ee18af06f7e478fcaa9e15e7a8510
parent4ce429a797a7790d5c42cb4398b54b549a01d625 (diff)
downloadlibraw1394-8f942654d9c2b9cd957e8e1f7eb1f29a05bbf64a.tar.gz
Change handle validation to prevent segfault and be more informative.
-rw-r--r--src/dispatch.c298
-rw-r--r--src/errors.c5
-rw-r--r--src/eventloop.c24
-rw-r--r--src/main.c42
-rw-r--r--src/raw1394.h14
5 files changed, 314 insertions, 69 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
diff --git a/src/errors.c b/src/errors.c
index e69c131..10f1a32 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -19,7 +19,10 @@
raw1394_errcode_t raw1394_get_errcode(struct raw1394_handle *handle)
{
- if (handle && handle->is_fw)
+ if (!handle) {
+ return RAW1394_ERROR_INVALID_ARG;
+ }
+ if (handle->is_fw)
return handle->mode.fw->err;
else
return handle->mode.ieee1394->err;
diff --git a/src/eventloop.c b/src/eventloop.c
index 78e581a..43a9519 100644
--- a/src/eventloop.c
+++ b/src/eventloop.c
@@ -97,7 +97,11 @@ bus_reset_handler_t raw1394_set_bus_reset_handler(struct raw1394_handle *handle,
bus_reset_handler_t new)
{
bus_reset_handler_t old;
- if (handle && handle->is_fw) {
+ if (!handle) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if (handle->is_fw) {
old = handle->mode.fw->bus_reset_handler;
handle->mode.fw->bus_reset_handler = new;
}
@@ -112,7 +116,11 @@ tag_handler_t raw1394_set_tag_handler(struct raw1394_handle *handle,
tag_handler_t new)
{
tag_handler_t old;
- if (handle && handle->is_fw) {
+ if (!handle) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if (handle->is_fw) {
old = handle->mode.fw->tag_handler;
handle->mode.fw->tag_handler = new;
}
@@ -127,7 +135,11 @@ arm_tag_handler_t raw1394_set_arm_tag_handler(struct raw1394_handle *handle,
arm_tag_handler_t new)
{
arm_tag_handler_t old;
- if (handle && handle->is_fw) {
+ if (!handle) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if (handle->is_fw) {
old = handle->mode.fw->arm_tag_handler;
handle->mode.fw->arm_tag_handler = new;
}
@@ -142,7 +154,11 @@ fcp_handler_t raw1394_set_fcp_handler(struct raw1394_handle *handle,
fcp_handler_t new)
{
fcp_handler_t old;
- if (handle && handle->is_fw) {
+ if (!handle) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if (handle->is_fw) {
old = handle->mode.fw->fcp_handler;
handle->mode.fw->fcp_handler = new;
}
diff --git a/src/main.c b/src/main.c
index 01b715a..55b4fbc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,6 +28,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <netinet/in.h>
+#include <limits.h>
#include "raw1394.h"
#include "csr.h"
@@ -178,7 +179,11 @@ int ieee1394_get_fd(struct ieee1394_handle *handle)
unsigned int raw1394_get_generation(struct raw1394_handle *handle)
{
- if (handle && handle->is_fw)
+ if (!handle) {
+ errno = EINVAL;
+ return UINT_MAX;
+ }
+ if (handle->is_fw)
return handle->mode.fw->generation;
else
return handle->mode.ieee1394->generation;
@@ -186,7 +191,10 @@ unsigned int raw1394_get_generation(struct raw1394_handle *handle)
void raw1394_update_generation(struct raw1394_handle *handle, unsigned int gen)
{
- if (handle && handle->is_fw)
+ if (!handle) {
+ return;
+ }
+ if (handle->is_fw)
handle->mode.fw->generation = gen;
else
handle->mode.ieee1394->generation = gen;
@@ -194,22 +202,37 @@ void raw1394_update_generation(struct raw1394_handle *handle, unsigned int gen)
int ieee1394_get_nodecount(struct ieee1394_handle *handle)
{
- return handle->num_of_nodes;
+ if (!handle) {
+ errno = EINVAL;
+ return UINT_MAX;
+ }
+ return handle->num_of_nodes;
}
nodeid_t ieee1394_get_local_id(struct ieee1394_handle *handle)
{
- return handle->local_id;
+ if (!handle) {
+ errno = EINVAL;
+ return 0xFFFF;
+ }
+ return handle->local_id;
}
nodeid_t ieee1394_get_irm_id(struct ieee1394_handle *handle)
{
- return handle->irm_id;
+ if (!handle) {
+ errno = EINVAL;
+ return 0xFFFF;
+ }
+ return handle->irm_id;
}
void raw1394_set_userdata(struct raw1394_handle *handle, void *data)
{
- if (handle && handle->is_fw)
+ if (!handle) {
+ return;
+ }
+ if (handle->is_fw)
handle->mode.fw->userdata = data;
else
handle->mode.ieee1394->userdata = data;
@@ -217,7 +240,11 @@ void raw1394_set_userdata(struct raw1394_handle *handle, void *data)
void *raw1394_get_userdata(struct raw1394_handle *handle)
{
- if (handle && handle->is_fw)
+ if (!handle) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if (handle->is_fw)
return handle->mode.fw->userdata;
else
return handle->mode.ieee1394->userdata;
@@ -503,4 +530,3 @@ int ieee1394_channel_modify (raw1394handle_t handle, unsigned int channel,
return 0;
}
-
diff --git a/src/raw1394.h b/src/raw1394.h
index 7cc07e6..c489c20 100644
--- a/src/raw1394.h
+++ b/src/raw1394.h
@@ -458,7 +458,8 @@ int raw1394_busreset_notify (raw1394handle_t handle, int off_on_switch);
* the blocking behaviour in raw1394_loop_iterate(). It must not be used for
* anything else.
*
- * Returns: the fd used for communication with the raw1394 kernel module.
+ * Returns: the fd used for communication with the raw1394 kernel module or -1
+ * on failure (sets errno).
**/
int raw1394_get_fd(raw1394handle_t handle);
@@ -603,7 +604,7 @@ typedef int (*bus_reset_handler_t)(raw1394handle_t, unsigned int generation);
* Sets the handler to be called on every bus reset to @new_h.
* The default handler just calls raw1394_update_generation().
*
- * Returns: the old handler
+ * Returns: the old handler or NULL on failure (sets errno)
**/
bus_reset_handler_t raw1394_set_bus_reset_handler(raw1394handle_t handle,
bus_reset_handler_t new_h);
@@ -618,7 +619,8 @@ bus_reset_handler_t raw1394_set_bus_reset_handler(raw1394handle_t handle,
* The generation number of the handle is not automatically updated,
* raw1394_update_generation() has to be used for this.
*
- * Returns: the generation number associated with the handle
+ * Returns: the generation number associated with the handle or UINT_MAX on
+* failure.
**/
unsigned int raw1394_get_generation(raw1394handle_t handle);
@@ -654,7 +656,7 @@ typedef int (*tag_handler_t)(raw1394handle_t, unsigned long tag,
* raw1394_lock()) since these do pass pointers to &struct
* raw1394_reqhandle as the tag and expect the callback to be invoked.
*
- * Returns: the old handler
+ * Returns: the old handler or NULL on failure (sets errno)
**/
tag_handler_t raw1394_set_tag_handler(raw1394handle_t handle,
tag_handler_t new_h);
@@ -672,7 +674,7 @@ typedef int (*arm_tag_handler_t)(raw1394handle_t handle, unsigned long arm_tag,
* arrived. The default action is to call the arm_callback in the
* raw1394_arm_reqhandle pointed to by arm_tag.
*
- * Returns: old handler
+ * Returns: old handler or NULL on failure (sets errno)
**/
arm_tag_handler_t raw1394_set_arm_tag_handler(raw1394handle_t handle,
arm_tag_handler_t new_h);
@@ -692,7 +694,7 @@ typedef int (*fcp_handler_t)(raw1394handle_t, nodeid_t nodeid, int response,
* In order to actually get FCP events, you have to enable it with
* raw1394_start_fcp_listen() and can stop it with raw1394_stop_fcp_listen().
*
- * Returns: the old handler
+ * Returns: the old handler or NULL on failure (sets errno)
**/
fcp_handler_t raw1394_set_fcp_handler(raw1394handle_t handle, fcp_handler_t new_h);