Skip to content

Commit 37ace20

Browse files
musicakcdavem330
authored andcommitted
dmascc: Return correct error codes
This change has been made with the goal that kernel functions should return something more descriptive than -1 on failure. A variable `err` has been introduced for storing error codes. The return value of kzalloc on failure should return a -1 and not a -ENOMEM. This was found using Coccinelle. A simplified version of the semantic patch used is: //<smpl> @@ expression *e; identifier l1; @@ e = kzalloc(...); if (e == NULL) { ... goto l1; } l1: ... return -1 + -ENOMEM ; //</smpl Furthermore, set `err` to -ENOMEM on failure of alloc_netdev(), and to -ENODEV on failure of register_netdev() and probe_irq_off(). The single call site only checks that the return value is not 0, hence no change is required at the call site. Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 31d035a commit 37ace20

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/net/hamradio/dmascc.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static const struct net_device_ops scc_netdev_ops = {
451451

452452
static int __init setup_adapter(int card_base, int type, int n)
453453
{
454-
int i, irq, chip;
454+
int i, irq, chip, err;
455455
struct scc_info *info;
456456
struct net_device *dev;
457457
struct scc_priv *priv;
@@ -463,14 +463,17 @@ static int __init setup_adapter(int card_base, int type, int n)
463463

464464
/* Initialize what is necessary for write_scc and write_scc_data */
465465
info = kzalloc(sizeof(struct scc_info), GFP_KERNEL | GFP_DMA);
466-
if (!info)
466+
if (!info) {
467+
err = -ENOMEM;
467468
goto out;
469+
}
468470

469471
info->dev[0] = alloc_netdev(0, "", NET_NAME_UNKNOWN, dev_setup);
470472
if (!info->dev[0]) {
471473
printk(KERN_ERR "dmascc: "
472474
"could not allocate memory for %s at %#3x\n",
473475
hw[type].name, card_base);
476+
err = -ENOMEM;
474477
goto out1;
475478
}
476479

@@ -479,6 +482,7 @@ static int __init setup_adapter(int card_base, int type, int n)
479482
printk(KERN_ERR "dmascc: "
480483
"could not allocate memory for %s at %#3x\n",
481484
hw[type].name, card_base);
485+
err = -ENOMEM;
482486
goto out2;
483487
}
484488
spin_lock_init(&info->register_lock);
@@ -549,6 +553,7 @@ static int __init setup_adapter(int card_base, int type, int n)
549553
printk(KERN_ERR
550554
"dmascc: could not find irq of %s at %#3x (irq=%d)\n",
551555
hw[type].name, card_base, irq);
556+
err = -ENODEV;
552557
goto out3;
553558
}
554559

@@ -585,11 +590,13 @@ static int __init setup_adapter(int card_base, int type, int n)
585590
if (register_netdev(info->dev[0])) {
586591
printk(KERN_ERR "dmascc: could not register %s\n",
587592
info->dev[0]->name);
593+
err = -ENODEV;
588594
goto out3;
589595
}
590596
if (register_netdev(info->dev[1])) {
591597
printk(KERN_ERR "dmascc: could not register %s\n",
592598
info->dev[1]->name);
599+
err = -ENODEV;
593600
goto out4;
594601
}
595602

@@ -612,7 +619,7 @@ static int __init setup_adapter(int card_base, int type, int n)
612619
out1:
613620
kfree(info);
614621
out:
615-
return -1;
622+
return err;
616623
}
617624

618625

0 commit comments

Comments
 (0)