Hello Drasko,

The end goal it's to have a safe state of the used JTAG adapter at the end of the executable file.

With this patch => Fix: Correctly exit function: ft2232_init when an error occurred I wish correct the status at the end of ft2232_init function when an error occured. At this moment, in function: ft2232_init the JTAG handle is acquire with the funtion: ft2232_init_ftd2xx or ft2232_init_libftdi and 131072 bytes are allocate for the variable: ft2232_buffer. But when an error occured, the JTAG handle isn't free and all allocate bytes aren't free.

To correct this on the layer ft2232, it's better to clarify the function: ft2232_init.
And for the end goal, I follow that as speack Laurent:

Open
   Init

   Deinit
Close

Open it's to acquire the JTAG handle.
Init it's to set all parameters and the pinning of the JTAG adapter.
Deinit it's to be on a safe state with the JTAG adapter.
Close it's to free the JTAG handle.


With this first patch, I have only divided functions and add the part to close handle and free the bytes of the variable: ft2232_buffer when an error occured.


So I have take the first part of the function: ft2232_init_ftd2xx and put to the function: ft2232_open_ftd2xx (from line: 2118 to line: 2230)
And I have remove the unnecessary variables.

The second part of the function: ft2232_init_ftd2xx stay on this function (from line: 2231 to line: 2278)
I have add the necessary variables.


It's the same work with the function: ft2232_init_libftdi.
So I have take the first part of the function: ft2232_init_libftdi and put to the function: ft2232_open_libftdi (from line: 2296 to line: 2332)
And I have remove the unnecessary variables.

The second part of the function: ft2232_init_libftdi stay on this function (from line: 2333 to line: 2366)
I have add the necessary variables.


To not make a lot of change on the function: ft2232_init, I have only divide the function on two parts and add the part to close handle and free the bytes of the variable: ft2232_buffer when an error occured. So the first part of the function: ft2232_init stay on this function (from line: 2421 to line: 2466)
I have remove the unnecessary variables.
I have change the functions: ft2232_init_ftd2xx and ft2232_init_libftdi by the functions: ft2232_open_ftd2xx and ft2232_open_libftdi (because it's the first part of the functions: ft2232_init_ftd2xx and ft2232_init_libftdi)

I have take the second part of the function: ft2232_init and put to the function: ft2232_init_sub (from line: 2467 to line: 2508)
I have add the necessary variables.
I have add the call of functions: ft2232_init_ftd2xx and ft2232_init_libftdi (because it's the second part of these functions)

And to identify the case of an error occured before the JTAG handle be acquire, I have add:
        if (retval != ERROR_OK)
                return retval;
(Because if an error occured during the acquire of the JTAG handle, I think that the JTAG handle stay free.)

To correctly free the JTAG handle and free the bytes of the variable: ft2232_buffer when an error occured. I have add:
        retval = ft2232_init_sub();
        if (retval != ERROR_OK)
        {
#if BUILD_FT2232_FTD2XX == 1
                FT_Close(ftdih);
#elif BUILD_FT2232_LIBFTDI == 1
                ftdi_usb_close(&ftdic);
                ftdi_deinit(&ftdic);
#endif

                if(ft2232_buffer)
                        free(ft2232_buffer);
                ft2232_buffer = NULL;

                return retval;
        }
(That is the content of the function: ft2232_quit (from line: 3231 to line: 3242)) The little modification of the free for the variable: ft2232_buffer, it's to only free the memory when is necessary (and possible).



--
Regards,
Sébastien Farquet
  http://www.amontec.com/
  Amontec JTAGkey-2 : High speed USB JTAG interface
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to