arm_adi_v5: prevent possibly endless recursion in dap_dp_init()
[fw/openocd] / src / target / openrisc / jsp_server.c
index 83e03ae3e2d0eb59fa4d45591312aa84a4a01a67..b4b25665dae598269323ea3f26e88b553e6e1c63 100644 (file)
@@ -15,9 +15,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 <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -59,7 +57,7 @@ static int telnet_write(struct connection *connection, const void *data, int len
        return ERROR_SERVER_REMOTE_CLOSED;
 }
 
-int jsp_poll_read(void *priv)
+static int jsp_poll_read(void *priv)
 {
        struct jsp_service *jsp_service = (struct jsp_service *)priv;
        unsigned char out_buffer[10];
@@ -90,7 +88,6 @@ static int jsp_new_connection(struct connection *connection)
        telnet_connection->closed = 0;
        telnet_connection->line_size = 0;
        telnet_connection->line_cursor = 0;
-       telnet_connection->option_size = 0;
        telnet_connection->state = TELNET_STATE_DATA;
 
        /* negotiate telnet options */
@@ -104,7 +101,8 @@ static int jsp_new_connection(struct connection *connection)
 
        jsp_service->connection = connection;
 
-       int retval = target_register_timer_callback(&jsp_poll_read, 1, 1, jsp_service);
+       int retval = target_register_timer_callback(&jsp_poll_read, 1,
+               TARGET_TIMER_TYPE_PERIODIC, jsp_service);
        if (ERROR_OK != retval)
                return retval;
 
@@ -186,24 +184,14 @@ static int jsp_input(struct connection *connection)
 
 static int jsp_connection_closed(struct connection *connection)
 {
-       struct telnet_connection *t_con = connection->priv;
        struct jsp_service *jsp_service = connection->service->priv;
 
-       if (t_con->prompt) {
-               free(t_con->prompt);
-               t_con->prompt = NULL;
-       }
-
        int retval = target_unregister_timer_callback(&jsp_poll_read, jsp_service);
        if (ERROR_OK != retval)
                return retval;
 
-       if (connection->priv) {
-               free(connection->priv);
-               connection->priv = NULL;
-       } else
-               LOG_ERROR("BUG: connection->priv == NULL");
-
+       free(connection->priv);
+       connection->priv = NULL;
        return ERROR_OK;
 }
 
@@ -219,7 +207,8 @@ int jsp_init(struct or1k_jtag *jtag_info, char *banner)
                jsp_new_connection,
                jsp_input,
                jsp_connection_closed,
-               jsp_service);
+               jsp_service,
+               NULL);
 }
 
 COMMAND_HANDLER(handle_jsp_port_command)
@@ -245,3 +234,7 @@ int jsp_register_commands(struct command_context *cmd_ctx)
        return register_commands(cmd_ctx, NULL, jsp_command_handlers);
 }
 
+void jsp_service_free(void)
+{
+       free(jsp_port);
+}