<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 10, 2016 at 10:35 AM, Joel Sherrill <span dir="ltr"><<a href="mailto:joel@rtems.org" target="_blank">joel@rtems.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Wed, Mar 9, 2016 at 8:15 PM, Gedare Bloom <span dir="ltr"><<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>On Wed, Mar 9, 2016 at 5:24 PM, Joel Sherrill <<a href="mailto:joel@rtems.org" target="_blank">joel@rtems.org</a>> wrote:<br>
> ---<br>
> c/src/lib/libbsp/shared/console.c | 49 ++++++++++++++++++++++++++++-----------<br>
> 1 file changed, 36 insertions(+), 13 deletions(-)<br>
><br>
> diff --git a/c/src/lib/libbsp/shared/console.c b/c/src/lib/libbsp/shared/console.c<br>
> index 81a70b1..d030065 100644<br>
> --- a/c/src/lib/libbsp/shared/console.c<br>
> +++ b/c/src/lib/libbsp/shared/console.c<br>
> @@ -7,7 +7,7 @@<br>
> */<br>
><br>
> /*<br>
> - * COPYRIGHT (c) 1989-2011.<br>
> + * COPYRIGHT (c) 1989-2011, 2016.<br>
> * On-Line Applications Research Corporation (OAR).<br>
> *<br>
> * The license and distribution terms for this file may be<br>
> @@ -46,13 +46,28 @@ void console_initialize_data(void)<br>
> if ( Console_Port_Tbl )<br>
> return;<br>
><br>
> + /*<br>
> + * Allocate memory for the table of device pointers.<br>
> + */<br>
> Console_Port_Count = Console_Configuration_Count;<br>
> Console_Port_Tbl = malloc( Console_Port_Count * sizeof( console_tbl * ) );<br>
> if (Console_Port_Tbl == NULL)<br>
> bsp_fatal( BSP_FATAL_CONSOLE_NO_MEMORY_0 );<br>
><br>
> - for (i=0 ; i < Console_Port_Count ; i++)<br>
> + /*<br>
> + * Allocate memory for the table of device specific data pointers.<br>
> + */<br>
> + Console_Port_Data = calloc( Console_Port_Count, sizeof( console_data ) );<br>
</div></div>why calloc ...<br>
<span><br></span></blockquote><div><br></div></div></div><div>Good catch. Likely already there but just wasted time. Changing to malloc().</div></div></div></div></blockquote><div><br></div><div>I think we both misread it. The calloc() is for data per port. The copy is copying</div><div>the per port configuration data. They are different. Notice Console_Port_Data</div><div>vs Console_Port_Tbl.</div><div><br></div><div>I think this is OK on closer look.</div><div><br></div><div>Anything else.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>
> + if ( Console_Port_Data == NULL ) {<br>
> + bsp_fatal( BSP_FATAL_CONSOLE_NO_MEMORY_3 );<br>
> + }<br>
> +<br>
> + /*<br>
> + * Fill in the Console Table<br>
> + */<br>
> + for (i=0 ; i < Console_Port_Count ; i++) {<br>
> Console_Port_Tbl[i] = &Console_Configuration_Ports[i];<br>
> + }<br>
</span>... if you will immediately initialize it<br>
<div><div><br>
> }<br>
><br>
> /*<br>
> @@ -69,10 +84,13 @@ void console_register_devices(<br>
> int old_number_of_ports;<br>
> int i;<br>
><br>
> + /*<br>
> + * Initialize the console data elements<br>
> + */<br>
> console_initialize_data();<br>
><br>
> /*<br>
> - * console_initialize has been invoked so it is now too late to<br>
> + * console_initialize() has been invoked so it is now too late to<br>
> * register devices.<br>
> */<br>
> if ( console_initialized ) {<br>
> @@ -86,23 +104,31 @@ void console_register_devices(<br>
> Console_Port_Count += number_of_ports;<br>
> Console_Port_Tbl = realloc(<br>
> Console_Port_Tbl,<br>
> - Console_Port_Count * sizeof( console_tbl * )<br>
> + Console_Port_Count * sizeof(console_tbl *)<br>
> );<br>
> if ( Console_Port_Tbl == NULL ) {<br>
> bsp_fatal( BSP_FATAL_CONSOLE_NO_MEMORY_1 );<br>
> }<br>
><br>
> - Console_Port_Data = calloc( Console_Port_Count, sizeof( console_data ) );<br>
> + /*<br>
> + * Since we can only add devices before console_initialize(),<br>
> + * the data area will contain no information and must be zero<br>
> + * before it is used. So extend the area and zero it out.<br>
> + */<br>
> + Console_Port_Data = realloc(<br>
> + Console_Port_Data,<br>
> + Console_Port_Count * sizeof(console_tbl *)<br>
> + );<br>
> if ( Console_Port_Data == NULL ) {<br>
> bsp_fatal( BSP_FATAL_CONSOLE_NO_MEMORY_2 );<br>
> }<br>
> + memset(&Console_Port_Data, '\0', Console_Port_Count * sizeof(console_tbl *));<br>
><br>
> /*<br>
> * Now add the new devices at the end.<br>
> */<br>
> -<br>
> for (i=0 ; i < number_of_ports ; i++) {<br>
> - Console_Port_Tbl[old_number_of_ports + i] = &new_ports[i];<br>
> + Console_Port_Tbl[old_number_of_ports + i] = &new_ports[i];<br>
> }<br>
> }<br>
><br>
> @@ -249,14 +275,11 @@ rtems_device_driver console_initialize(<br>
><br>
> /*<br>
> * If we have no devices which were registered earlier then we<br>
> - * must still initialize pointers and set Console_Port_Data.<br>
> + * must still initialize pointers for Console_Port_Tbl and<br>
> + * Console_Port_Data.<br>
> */<br>
> - if ( ! Console_Port_Tbl ) {<br>
> + if ( !Console_Port_Tbl ) {<br>
> console_initialize_data();<br>
> - Console_Port_Data = calloc( Console_Port_Count, sizeof( console_data ) );<br>
> - if ( Console_Port_Data == NULL ) {<br>
> - bsp_fatal( BSP_FATAL_CONSOLE_NO_MEMORY_3 );<br>
> - }<br>
> }<br>
><br>
> /*<br>
> --<br>
> 1.8.3.1<br>
><br>
</div></div>> _______________________________________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>