Skip to content

Commit

Permalink
snull: fix error handling in device registeration
Browse files Browse the repository at this point in the history
If the first device registration fails, the second iteration of the loop
will set the ret to zero. Also, jumping to snull_cleanup() will put the
device into unreg queue which is unnecessary.
  • Loading branch information
ImanSeyed committed Oct 20, 2024
1 parent ecdb794 commit 1670c58
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions snull/snull.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,28 +752,29 @@ static void snull_cleanup(void)

static int snull_init_module(void)
{
int result, i, ret = -ENOMEM;
int result, i, ret = 0;

snull_interrupt = use_napi ? snull_napi_interrupt : snull_regular_interrupt;

/* Allocate the devices */
snull_devs[0] = alloc_netdev(sizeof(struct snull_priv), "sn%d",
NET_NAME_UNKNOWN, snull_init);
snull_devs[1] = alloc_netdev(sizeof(struct snull_priv), "sn%d",
/* Allocate and register the devices */
for (i = 0; i < 2; i++) {
snull_devs[i] = alloc_netdev(sizeof(struct snull_priv), "sn%d",
NET_NAME_UNKNOWN, snull_init);
if (snull_devs[0] == NULL || snull_devs[1] == NULL)
goto out;

ret = -ENODEV;
for (i = 0; i < 2; i++)
if ((result = register_netdev(snull_devs[i])))
if (snull_devs[i] == NULL) {
ret = -ENOMEM;
break;
}

if ((result = register_netdev(snull_devs[i]))) {
printk("snull: error %i registering device \"%s\"\n",
result, snull_devs[i]->name);
else
ret = 0;
out:
if (ret)
snull_cleanup();
free_netdev(snull_devs[i]);
ret = -ENODEV;
break;
}
}

return ret;
}

Expand Down

0 comments on commit 1670c58

Please sign in to comment.