net: fec: add fuse check
[oweals/u-boot.git] / drivers / net / netconsole.c
index e9dbedf32680ec05143e63d70cfa335261fafbf2..73005ff94d9f27635317b183271c25f5124dd186 100644 (file)
@@ -1,17 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2004
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <command.h>
+#include <env.h>
 #include <stdio_dev.h>
 #include <net.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 #ifndef CONFIG_NETCONSOLE_BUFFER_SIZE
 #define CONFIG_NETCONSOLE_BUFFER_SIZE 512
 #endif
@@ -58,7 +56,7 @@ static int is_broadcast(struct in_addr ip)
        static struct in_addr netmask;
        static struct in_addr our_ip;
        static int env_changed_id;
-       int env_id = get_env_id();
+       int env_id = env_get_id();
 
        /* update only when the environment has changed */
        if (env_changed_id != env_id) {
@@ -78,7 +76,7 @@ static int refresh_settings_from_env(void)
 {
        const char *p;
        static int env_changed_id;
-       int env_id = get_env_id();
+       int env_id = env_get_id();
 
        /* update only when the environment has changed */
        if (env_changed_id != env_id) {
@@ -153,14 +151,17 @@ int nc_input_packet(uchar *pkt, struct in_addr src_ip, unsigned dest_port,
                len = sizeof(input_buffer) - input_size;
 
        end = input_offset + input_size;
-       if (end > sizeof(input_buffer))
+       if (end >= sizeof(input_buffer))
                end -= sizeof(input_buffer);
 
        chunk = len;
-       if (end + len > sizeof(input_buffer)) {
+       /* Check if packet will wrap in input_buffer */
+       if (end + len >= sizeof(input_buffer)) {
                chunk = sizeof(input_buffer) - end;
+               /* Copy the second part of the pkt to start of input_buffer */
                memcpy(input_buffer, pkt + chunk, len - chunk);
        }
+       /* Copy first (or only) part of pkt after end of current valid input*/
        memcpy(input_buffer + end, pkt, chunk);
 
        input_size += len;