X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=blobdiff_plain;f=src%2Fftdi.c;h=6de60bee189ad902ad59753a3f91124cf0e12507;hp=1e92dc585d66be0a5da7b3b43a040ad64e513c0b;hb=200bd3ed2e1d2389217be44c0adc728909a2a100;hpb=17431287ffa37d2085dbe7cb30afa17487e456a2 diff --git a/src/ftdi.c b/src/ftdi.c index 1e92dc5..6de60be 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -2,7 +2,7 @@ ftdi.c - description ------------------- begin : Fri Apr 4 2003 - copyright : (C) 2003-2010 by Intra2net AG + copyright : (C) 2003-2011 by Intra2net AG and the libftdi developers email : opensource@intra2net.com ***************************************************************************/ @@ -1376,19 +1376,22 @@ static void ftdi_write_data_cb(struct libusb_transfer *transfer) struct ftdi_transfer_control *ftdi_write_data_submit(struct ftdi_context *ftdi, unsigned char *buf, int size) { struct ftdi_transfer_control *tc; - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer; int write_size, ret; if (ftdi == NULL || ftdi->usb_dev == NULL) - { - libusb_free_transfer(transfer); return NULL; - } tc = (struct ftdi_transfer_control *) malloc (sizeof (*tc)); + if (!tc) + return NULL; - if (!tc || !transfer) + transfer = libusb_alloc_transfer(0); + if (!transfer) + { + free(tc); return NULL; + } tc->ftdi = ftdi; tc->completed = 0; @@ -1410,8 +1413,7 @@ struct ftdi_transfer_control *ftdi_write_data_submit(struct ftdi_context *ftdi, if (ret < 0) { libusb_free_transfer(transfer); - tc->completed = 1; - tc->transfer = NULL; + free(tc); return NULL; } tc->transfer = transfer; @@ -2310,6 +2312,7 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi) case TYPE_2232H: // six extra config bytes + 4 bytes PnP stuff case TYPE_4232H: user_area_size = 86; + break; default: user_area_size = 0; break; @@ -2941,7 +2944,6 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose) "IOMODE","BB_WR","BB_RD" }; char *cbus_BB[] = {"RXF","TXE","RD", "WR"}; - int i; if (eeprom->invert) { @@ -2976,12 +2978,12 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose) /** Get a value from the decoded EEPROM structure - \\param ftdi pointer to ftdi_context - \\param value_name Enum of the value to query - \\param Pointer to store read value + \param ftdi pointer to ftdi_context + \param value_name Enum of the value to query + \param value Pointer to store read value - \\retval 0: all fine - \\retval -1: Value doesn't exist + \retval 0: all fine + \retval -1: Value doesn't exist */ int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int* value) { @@ -3111,13 +3113,13 @@ int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value valu Set a value in the decoded EEPROM Structure No parameter checking is performed - \\param ftdi pointer to ftdi_context - \\param value_name Enum of the value to query - \\param Value to set + \param ftdi pointer to ftdi_context + \param value_name Enum of the value to set + \param value to set - \\retval 0: all fine - \\retval -1: Value doesn't exist - \\retval -2: Value not user settable + \retval 0: all fine + \retval -1: Value doesn't exist + \retval -2: Value not user settable */ int ftdi_set_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int value) { @@ -3245,17 +3247,27 @@ int ftdi_set_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value valu /** Get the read-only buffer to the binary EEPROM content \param ftdi pointer to ftdi_context - \param ftdi buffer to receive EEPROM content + \param buf buffer to receive EEPROM content \param size Size of receiving buffer \retval 0: All fine \retval -1: struct ftdi_contxt or ftdi_eeprom missing + \retval -2: Not enough room to store eeprom */ int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, int size) { if (!ftdi || !(ftdi->eeprom)) ftdi_error_return(-1, "No appropriate structure"); + + if (!buf || size < ftdi->eeprom->size) + ftdi_error_return(-1, "Not enough room to store eeprom"); + + // Only copy up to FTDI_MAX_EEPROM_SIZE bytes + if (size > FTDI_MAX_EEPROM_SIZE) + size = FTDI_MAX_EEPROM_SIZE; + memcpy(buf, ftdi->eeprom->buf, size); + return 0; }