diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2020-06-17 12:00:07 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-06-18 09:05:13 -0700 |
commit | 7f0ee3d8e2ae99ae21305c647cd501565846cf8f (patch) | |
tree | 825bd6bdea246460f33b8cf98e639e01c96c1a8b | |
parent | 14c37ba7337da108f23dd8cba98c2a9d52bd4099 (diff) | |
download | subsurface-7f0ee3d8e2ae99ae21305c647cd501565846cf8f.tar.gz |
core: fix libdivecomputer dc_custom callbacks structures
The last time those changed, we forgot to update serial_ftdi. In that change
set_latency had been removed from libdivecomputer and poll and ioctl had been
added. This caused the callbacks to no longer be aligned correctly and the
functions were called with the wrong arguments through the wrong function
pointers, leading to crashes.
Instead of the fragile assumptions about order and type of function pointers,
use named initializers. And while we are at it, fix that for the bluetooth
implementation as well.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | core/qtserialbluetooth.cpp | 46 | ||||
-rw-r--r-- | core/serial_ftdi.c | 29 |
3 files changed, 30 insertions, 46 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f1879cad5..cc5baab5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +core: fix crashes when using user space FTDI driver mobile: add information about the cloud sync state to the Subsurface plate in the menu --- diff --git a/core/qtserialbluetooth.cpp b/core/qtserialbluetooth.cpp index 1c0270ff9..16dec0ee7 100644 --- a/core/qtserialbluetooth.cpp +++ b/core/qtserialbluetooth.cpp @@ -283,21 +283,13 @@ ble_packet_open(dc_iostream_t **iostream, dc_context_t *context, const char* dev void *io = NULL; static const dc_custom_cbs_t callbacks = { - qt_ble_set_timeout, /* set_timeout */ - NULL, /* set_break */ - NULL, /* set_dtr */ - NULL, /* set_rts */ - NULL, /* get_lines */ - NULL, /* get_received */ - NULL, /* configure */ - qt_ble_poll, /* poll */ - qt_ble_read, /* read */ - qt_ble_write, /* write */ - qt_ble_ioctl, /* ioctl */ - NULL, /* flush */ - NULL, /* purge */ - qt_custom_sleep, /* sleep */ - qt_ble_close, /* close */ + .set_timeout = qt_ble_set_timeout, + .poll = qt_ble_poll, + .read = qt_ble_read, + .write = qt_ble_write, + .ioctl = qt_ble_ioctl, + .sleep = qt_custom_sleep, + .close = qt_ble_close, }; rc = qt_ble_open(&io, context, devaddr, (dc_user_device_t *) userdata); @@ -317,21 +309,15 @@ rfcomm_stream_open(dc_iostream_t **iostream, dc_context_t *context, const char* qt_serial_t *io = NULL; static const dc_custom_cbs_t callbacks = { - qt_serial_set_timeout, /* set_timeout */ - NULL, /* set_break */ - NULL, /* set_dtr */ - NULL, /* set_rts */ - NULL, /* get_lines */ - qt_serial_get_available, /* get_received */ - NULL, /* configure */ - qt_serial_poll, /* poll */ - qt_serial_read, /* read */ - qt_serial_write, /* write */ - qt_serial_ioctl, /* ioctl */ - NULL, /* flush */ - qt_serial_purge, /* purge */ - qt_custom_sleep, /* sleep */ - qt_serial_close, /* close */ + .set_timeout = qt_serial_set_timeout, + .get_available = qt_serial_get_available, + .poll = qt_serial_poll, + .read = qt_serial_read, + .write = qt_serial_write, + .ioctl = qt_serial_ioctl, + .purge = qt_serial_purge, + .sleep = qt_custom_sleep, + .close = qt_serial_close, }; rc = qt_serial_open(&io, context, devaddr); diff --git a/core/serial_ftdi.c b/core/serial_ftdi.c index 89f48f01d..7bc7f2805 100644 --- a/core/serial_ftdi.c +++ b/core/serial_ftdi.c @@ -78,7 +78,7 @@ typedef struct ftdi_serial_t { unsigned int parity; } ftdi_serial_t; -static dc_status_t serial_ftdi_get_received (void *io, size_t *value) +static dc_status_t serial_ftdi_get_available (void *io, size_t *value) { ftdi_serial_t *device = io; @@ -471,7 +471,7 @@ static dc_status_t serial_ftdi_purge (void *io, dc_direction_t queue) return DC_STATUS_INVALIDARGS; size_t input; - serial_ftdi_get_received (io, &input); + serial_ftdi_get_available (io, &input); INFO (device->context, "Flush: queue=%u, input=%lu, output=%i", queue, input, serial_ftdi_get_transmitted (device)); @@ -557,20 +557,17 @@ dc_status_t ftdi_open(dc_iostream_t **iostream, dc_context_t *context) void *io = NULL; static const dc_custom_cbs_t callbacks = { - serial_ftdi_set_timeout, /* set_timeout */ - NULL, /* set_latency */ - serial_ftdi_set_break, /* set_break */ - serial_ftdi_set_dtr, /* set_dtr */ - serial_ftdi_set_rts, /* set_rts */ - NULL, /* get_lines */ - serial_ftdi_get_received, /* get_received */ - serial_ftdi_configure, /* configure */ - serial_ftdi_read, /* read */ - serial_ftdi_write, /* write */ - NULL, /* flush */ - serial_ftdi_purge, /* purge */ - serial_ftdi_sleep, /* sleep */ - serial_ftdi_close, /* close */ + .set_timeout = serial_ftdi_set_timeout, + .set_break = serial_ftdi_set_break, + .set_dtr = serial_ftdi_set_dtr, + .set_rts = serial_ftdi_set_rts, + .get_available = serial_ftdi_get_available, + .configure = serial_ftdi_configure, + .read = serial_ftdi_read, + .write = serial_ftdi_write, + .purge = serial_ftdi_purge, + .sleep = serial_ftdi_sleep, + .close = serial_ftdi_close, }; INFO(device->contxt, "%s", "in ftdi_open"); |