diff --git a/drivers/net/tun.c b/drivers/net/tun.c index d7b0cec6007..0a678f53464 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1231,6 +1231,13 @@ static int tun_dev_init(FAR struct tun_device_s *priv, FAR struct file *filep, tun_ifdown(&priv->dev); + /* Assign d_ifname if specified. */ + + if (devfmt) + { + strncpy(priv->dev.d_ifname, devfmt, IFNAMSIZ); + } + /* Register the device with the OS so that socket IOCTLs can be performed */ ret = netdev_register(&priv->dev, NET_LL_TUN); @@ -1242,13 +1249,6 @@ static int tun_dev_init(FAR struct tun_device_s *priv, FAR struct file *filep, return ret; } - /* Assign d_ifname if specified. This must be done after registration */ - - if (devfmt) - { - strncpy(priv->dev.d_ifname, devfmt, IFNAMSIZ); - } - priv->filep = filep; /* Set link to file */ filep->f_priv = priv; /* Set link to TUN device */