Skip to content

Commit 2ae0bf6

Browse files
kaberDavid S. Miller
authored andcommitted
[VLAN]: Return proper error codes in register_vlan_device
The returned device is unused, return proper error codes instead and avoid having the ioctl handler guess the error. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e89fe42 commit 2ae0bf6

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

net/8021q/vlan.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -493,25 +493,26 @@ static int register_vlan_dev(struct net_device *dev)
493493
}
494494

495495
/* Attach a VLAN device to a mac address (ie Ethernet Card).
496-
* Returns the device that was created, or NULL if there was
497-
* an error of some kind.
496+
* Returns 0 if the device was created or a negative error code otherwise.
498497
*/
499-
static struct net_device *register_vlan_device(struct net_device *real_dev,
500-
unsigned short VLAN_ID)
498+
static int register_vlan_device(struct net_device *real_dev,
499+
unsigned short VLAN_ID)
501500
{
502501
struct net_device *new_dev;
503502
char name[IFNAMSIZ];
503+
int err;
504504

505505
#ifdef VLAN_DEBUG
506506
printk(VLAN_DBG "%s: if_name -:%s:- vid: %i\n",
507507
__FUNCTION__, eth_IF_name, VLAN_ID);
508508
#endif
509509

510510
if (VLAN_ID >= VLAN_VID_MASK)
511-
goto out_ret_null;
511+
return -ERANGE;
512512

513-
if (vlan_check_real_dev(real_dev, VLAN_ID) < 0)
514-
goto out_ret_null;
513+
err = vlan_check_real_dev(real_dev, VLAN_ID);
514+
if (err < 0)
515+
return err;
515516

516517
/* Gotta set up the fields for the device. */
517518
#ifdef VLAN_DEBUG
@@ -547,7 +548,7 @@ static struct net_device *register_vlan_device(struct net_device *real_dev,
547548
vlan_setup);
548549

549550
if (new_dev == NULL)
550-
goto out_ret_null;
551+
return -ENOBUFS;
551552

552553
/* need 4 bytes for extra VLAN header info,
553554
* hope the underlying device can handle it.
@@ -566,21 +567,20 @@ static struct net_device *register_vlan_device(struct net_device *real_dev,
566567
VLAN_DEV_INFO(new_dev)->dent = NULL;
567568
VLAN_DEV_INFO(new_dev)->flags = 1;
568569

569-
if (register_vlan_dev(new_dev) < 0)
570+
err = register_vlan_dev(new_dev);
571+
if (err < 0)
570572
goto out_free_newdev;
571573

572574
/* Account for reference in struct vlan_dev_info */
573575
dev_hold(real_dev);
574576
#ifdef VLAN_DEBUG
575577
printk(VLAN_DBG "Allocated new device successfully, returning.\n");
576578
#endif
577-
return new_dev;
579+
return 0;
578580

579581
out_free_newdev:
580582
free_netdev(new_dev);
581-
582-
out_ret_null:
583-
return NULL;
583+
return err;
584584
}
585585

586586
static int vlan_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
@@ -753,11 +753,7 @@ static int vlan_ioctl_handler(void __user *arg)
753753
err = -EPERM;
754754
if (!capable(CAP_NET_ADMIN))
755755
break;
756-
if (register_vlan_device(dev, args.u.VID)) {
757-
err = 0;
758-
} else {
759-
err = -EINVAL;
760-
}
756+
err = register_vlan_device(dev, args.u.VID);
761757
break;
762758

763759
case DEL_VLAN_CMD:

0 commit comments

Comments
 (0)