X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fjtag%2Fcommands.c;h=ed40755b73a5a7dcb45410f56ad5a42b547782cd;hp=d2106da0257eb64e28e723c34f1663fa1ea23a03;hb=cc2d4f015f72d7c30d613b50572eb9f31fac515a;hpb=08d4411b59dd8bd0e7d8009003b71d23acbf6eee diff --git a/src/jtag/commands.c b/src/jtag/commands.c index d2106da025..ed40755b73 100644 --- a/src/jtag/commands.c +++ b/src/jtag/commands.c @@ -23,9 +23,7 @@ * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + * along with this program. If not, see . * ***************************************************************************/ #ifdef HAVE_CONFIG_H @@ -36,13 +34,14 @@ #include "commands.h" struct cmd_queue_page { + struct cmd_queue_page *next; void *address; size_t used; - struct cmd_queue_page *next; }; #define CMD_QUEUE_PAGE_SIZE (1024 * 1024) static struct cmd_queue_page *cmd_queue_pages; +static struct cmd_queue_page *cmd_queue_pages_tail; struct jtag_command *jtag_command_queue; static struct jtag_command **next_command_pointer = &jtag_command_queue; @@ -100,8 +99,7 @@ void *cmd_queue_alloc(size_t size) /* Done... */ if (*p_page) { - while ((*p_page)->next) - p_page = &((*p_page)->next); + p_page = &cmd_queue_pages_tail; if (CMD_QUEUE_PAGE_SIZE - (*p_page)->used < size) p_page = &((*p_page)->next); } @@ -109,14 +107,17 @@ void *cmd_queue_alloc(size_t size) if (!*p_page) { *p_page = malloc(sizeof(struct cmd_queue_page)); (*p_page)->used = 0; - (*p_page)->address = malloc(CMD_QUEUE_PAGE_SIZE); + size_t alloc_size = (size < CMD_QUEUE_PAGE_SIZE) ? + CMD_QUEUE_PAGE_SIZE : size; + (*p_page)->address = malloc(alloc_size); (*p_page)->next = NULL; + cmd_queue_pages_tail = *p_page; } offset = (*p_page)->used; (*p_page)->used += size; - t = (uint8_t *)((*p_page)->address); + t = (*p_page)->address; return t + offset; } @@ -132,6 +133,7 @@ static void cmd_queue_free(void) } cmd_queue_pages = NULL; + cmd_queue_pages_tail = NULL; } void jtag_command_queue_reset(void)