From 3bf08eceb117d921214a72673d691a4485150282 Mon Sep 17 00:00:00 2001 From: Yi-Shin Li Date: Sun, 11 Jul 2010 23:08:11 +0800 Subject: [PATCH] bug fix for async write and read * In ftdi_write_data_cb(), the tc->offset should be accumulated with transfer->actual_length. * In ftdi_transfer_data_done(), the tc->transfer could be NULL if "(size <= ftdi->readbuffer_remaining)" at ftdi_read_data_submit(). Therefore, has to check if it's NULL before accessing it. * add autogen.sh * add "./m4" to .gitignore --- .gitignore | 1 + autogen.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/ftdi.c | 31 ++++++++++++++++++------------- 3 files changed, 67 insertions(+), 13 deletions(-) create mode 100755 autogen.sh diff --git a/.gitignore b/.gitignore index 4bacdb7..e1a8385 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ build/ # Automake +m4/ Makefile Makefile.in autom4te.cache diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..cd18fbd --- /dev/null +++ b/autogen.sh @@ -0,0 +1,48 @@ +#! /bin/sh + +# $Id: autogen.sh,v 1.4 2002/12/02 01:39:49 murrayc Exp $ +# +# Copyright (c) 2002 Daniel Elstner +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License VERSION 2 as +# published by the Free Software Foundation. You are not allowed to +# use any other version of the license; unless you got the explicit +# permission from the author to do so. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +dir=`echo "$0" | sed 's,[^/]*$,,'` +test "x${dir}" = "x" && dir='.' + +if test "x`cd "${dir}" 2>/dev/null && pwd`" != "x`pwd`" +then + echo "This script must be executed directly from the source directory." + exit 1 +fi + +rm -f config.cache acconfig.h + +echo "- libtoolize." && \ +libtoolize --force --copy && \ +echo "- aclocal." && \ +aclocal && \ +echo "- autoconf." && \ +autoconf && \ +echo "- autoheader." && \ +autoheader && \ +echo "- automake." && \ +automake --add-missing --copy --gnu && \ +echo && \ +./configure "$@" && exit 0 + +exit 1 + diff --git a/src/ftdi.c b/src/ftdi.c index b22a55b..4a57957 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -1322,9 +1322,9 @@ static void ftdi_write_data_cb(struct libusb_transfer *transfer) { struct ftdi_transfer_control *tc = (struct ftdi_transfer_control *) transfer->user_data; struct ftdi_context *ftdi = tc->ftdi; - - tc->offset = transfer->actual_length; - + + tc->offset += transfer->actual_length; + if (tc->offset == tc->size) { tc->completed = 1; @@ -1387,10 +1387,12 @@ struct ftdi_transfer_control *ftdi_write_data_submit(struct ftdi_context *ftdi, write_size = size; else write_size = ftdi->writebuffer_chunksize; - - libusb_fill_bulk_transfer(transfer, ftdi->usb_dev, ftdi->in_ep, buf, write_size, ftdi_write_data_cb, tc, ftdi->usb_write_timeout); + + libusb_fill_bulk_transfer(transfer, ftdi->usb_dev, ftdi->in_ep, buf, + write_size, ftdi_write_data_cb, tc, + ftdi->usb_write_timeout); transfer->type = LIBUSB_TRANSFER_TYPE_BULK; - + ret = libusb_submit_transfer(transfer); if (ret < 0) { @@ -1514,17 +1516,20 @@ int ftdi_transfer_data_done(struct ftdi_transfer_control *tc) break; libusb_free_transfer(tc->transfer); free (tc); - tc = NULL; return ret; } } - if (tc->transfer->status == LIBUSB_TRANSFER_COMPLETED) - ret = tc->offset; - else - ret = -1; - - libusb_free_transfer(tc->transfer); + ret = tc->offset; + /** + * tc->transfer could be NULL if "(size <= ftdi->readbuffer_remaining)" + * at ftdi_read_data_submit(). Therefore, has to check it here. + **/ + if (tc->transfer) { + if (tc->transfer->status != LIBUSB_TRANSFER_COMPLETED) + ret = -1; + libusb_free_transfer(tc->transfer); + } free(tc); return ret; } -- 1.7.0.4