diff mbox series

[U-Boot] net: Protect net_state from reentrant net_loop()

Message ID CAGdPep8U0ePoK1o=tpxnonAe+A=w2W8F7g=izOewu__JZGdLVg@mail.gmail.com
State Accepted
Commit 60177b2
Delegated to: Joe Hershberger
Headers show
Series [U-Boot] net: Protect net_state from reentrant net_loop() | expand

Commit Message

Leonid Iziumtsev May 8, 2018, 1:55 p.m. UTC
Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
---
 net/net.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Joe Hershberger May 8, 2018, 3:40 p.m. UTC | #1
On Tue, May 8, 2018 at 8:55 AM, Leonid Iziumtsev
<leonid.iziumtsev@gmail.com> wrote:
> Global variable "net_state" is used in net_loop() state-machine.
> But it happens that some times the net_loop() can be called
> multiple times in the same call stack. For example when the
> netconsole is enabled and we print the message while some other
> net protocol is in action. Netconsole will overwrite the "net_state"
> and that will break the logic for earlier started protocol.
>
> To protect the state save and restore "net_state" variable each
> time when we enter and exit net_loop().
>
> Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Joe Hershberger June 13, 2018, 7:01 p.m. UTC | #2
Hi Leonid,

https://patchwork.ozlabs.org/patch/910202/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe
diff mbox series

Patch

diff --git a/net/net.c b/net/net.c
index c3adba2..cb34c3b 100644
--- a/net/net.c
+++ b/net/net.c
@@ -417,6 +417,7 @@  void net_init(void)
 int net_loop(enum proto_t protocol)
 {
        int ret = -EINVAL;
+       enum net_loop_state prev_net_state = net_state;

        net_restarted = 0;
        net_dev_exists = 0;
@@ -454,6 +455,7 @@  restart:
        case 1:
                /* network not configured */
                eth_halt();
+               net_set_state(prev_net_state);
                return -ENODEV;

        case 2:
@@ -674,6 +676,7 @@  done:
        net_set_udp_handler(NULL);
        net_set_icmp_handler(NULL);
 #endif
+       net_set_state(prev_net_state);
        return ret;
 }