Coverage Report

Created: 2026-03-11 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/u-boot/drivers/net/sandbox-raw-bus.c
Line
Count
Source
1
// SPDX-License-Identifier: GPL-2.0+
2
/*
3
 * Copyright (c) 2018 National Instruments
4
 * Copyright (c) 2018 Joe Hershberger <joe.hershberger@ni.com>
5
 */
6
7
#include <asm/eth-raw-os.h>
8
#include <dm.h>
9
#include <errno.h>
10
#include <malloc.h>
11
#include <dm/device-internal.h>
12
#include <dm/lists.h>
13
14
static int eth_raw_bus_post_bind(struct udevice *dev)
15
0
{
16
0
  struct sandbox_eth_raw_if_nameindex *ni, *i;
17
0
  struct udevice *child;
18
0
  struct eth_sandbox_raw_priv *priv;
19
0
  char *ub_ifname;
20
0
  static const char ub_ifname_pfx[] = "host_";
21
0
  u32 skip_localhost = 0;
22
23
0
  ni = sandbox_eth_raw_if_nameindex();
24
0
  if (!ni)
25
0
    return -EINVAL;
26
27
0
  dev_read_u32(dev, "skip-localhost", &skip_localhost);
28
0
  for (i = ni; !(i->if_index == 0 && !i->if_name); i++) {
29
0
    int local = sandbox_eth_raw_os_is_local(i->if_name);
30
31
0
    if (local < 0)
32
0
      continue;
33
0
    if (skip_localhost && local)
34
0
      continue;
35
36
0
    ub_ifname = calloc(IFNAMSIZ + sizeof(ub_ifname_pfx), 1);
37
0
    strcpy(ub_ifname, ub_ifname_pfx);
38
0
    strncat(ub_ifname, i->if_name, IFNAMSIZ);
39
0
    device_bind_driver(dev, "eth_sandbox_raw", ub_ifname, &child);
40
41
0
    device_set_name_alloced(child);
42
0
    device_probe(child);
43
0
    priv = dev_get_priv(child);
44
0
    if (priv) {
45
0
      strlcpy(priv->host_ifname, i->if_name, IFNAMSIZ);
46
0
      priv->host_ifindex = i->if_index;
47
0
      priv->local = local;
48
0
    }
49
0
  }
50
51
0
  sandbox_eth_raw_if_freenameindex(ni);
52
53
0
  return 0;
54
0
}
55
56
static const struct udevice_id sandbox_eth_raw_bus_ids[] = {
57
  { .compatible = "sandbox,eth-raw-bus" },
58
  { }
59
};
60
61
U_BOOT_DRIVER(sandbox_eth_raw_bus) = {
62
  .name       = "sb_eth_raw_bus",
63
  .id         = UCLASS_SIMPLE_BUS,
64
  .of_match   = sandbox_eth_raw_bus_ids,
65
  .bind       = eth_raw_bus_post_bind,
66
};