diff options
author | Amitoj Kaur Chawla <amitoj1606@gmail.com> | 2016-02-09 13:42:36 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-02-16 15:32:34 -0500 |
commit | 37ace20a3c99c54ebffb4b13671a01adb20926ca (patch) | |
tree | 61cebd374f01c3957f462ce8f5819d15849734e3 | |
parent | 31d035a0d323d34acbab1b9cc250b443c5c02297 (diff) |
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>
-rw-r--r-- | drivers/net/hamradio/dmascc.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/drivers/net/hamradio/dmascc.c b/drivers/net/hamradio/dmascc.c index c3d377770616..e4137c1b3df9 100644 --- a/drivers/net/hamradio/dmascc.c +++ b/drivers/net/hamradio/dmascc.c | |||
@@ -451,7 +451,7 @@ static const struct net_device_ops scc_netdev_ops = { | |||
451 | 451 | ||
452 | static int __init setup_adapter(int card_base, int type, int n) | 452 | static int __init setup_adapter(int card_base, int type, int n) |
453 | { | 453 | { |
454 | int i, irq, chip; | 454 | int i, irq, chip, err; |
455 | struct scc_info *info; | 455 | struct scc_info *info; |
456 | struct net_device *dev; | 456 | struct net_device *dev; |
457 | struct scc_priv *priv; | 457 | struct scc_priv *priv; |
@@ -463,14 +463,17 @@ static int __init setup_adapter(int card_base, int type, int n) | |||
463 | 463 | ||
464 | /* Initialize what is necessary for write_scc and write_scc_data */ | 464 | /* Initialize what is necessary for write_scc and write_scc_data */ |
465 | info = kzalloc(sizeof(struct scc_info), GFP_KERNEL | GFP_DMA); | 465 | info = kzalloc(sizeof(struct scc_info), GFP_KERNEL | GFP_DMA); |
466 | if (!info) | 466 | if (!info) { |
467 | err = -ENOMEM; | ||
467 | goto out; | 468 | goto out; |
469 | } | ||
468 | 470 | ||
469 | info->dev[0] = alloc_netdev(0, "", NET_NAME_UNKNOWN, dev_setup); | 471 | info->dev[0] = alloc_netdev(0, "", NET_NAME_UNKNOWN, dev_setup); |
470 | if (!info->dev[0]) { | 472 | if (!info->dev[0]) { |
471 | printk(KERN_ERR "dmascc: " | 473 | printk(KERN_ERR "dmascc: " |
472 | "could not allocate memory for %s at %#3x\n", | 474 | "could not allocate memory for %s at %#3x\n", |
473 | hw[type].name, card_base); | 475 | hw[type].name, card_base); |
476 | err = -ENOMEM; | ||
474 | goto out1; | 477 | goto out1; |
475 | } | 478 | } |
476 | 479 | ||
@@ -479,6 +482,7 @@ static int __init setup_adapter(int card_base, int type, int n) | |||
479 | printk(KERN_ERR "dmascc: " | 482 | printk(KERN_ERR "dmascc: " |
480 | "could not allocate memory for %s at %#3x\n", | 483 | "could not allocate memory for %s at %#3x\n", |
481 | hw[type].name, card_base); | 484 | hw[type].name, card_base); |
485 | err = -ENOMEM; | ||
482 | goto out2; | 486 | goto out2; |
483 | } | 487 | } |
484 | spin_lock_init(&info->register_lock); | 488 | spin_lock_init(&info->register_lock); |
@@ -549,6 +553,7 @@ static int __init setup_adapter(int card_base, int type, int n) | |||
549 | printk(KERN_ERR | 553 | printk(KERN_ERR |
550 | "dmascc: could not find irq of %s at %#3x (irq=%d)\n", | 554 | "dmascc: could not find irq of %s at %#3x (irq=%d)\n", |
551 | hw[type].name, card_base, irq); | 555 | hw[type].name, card_base, irq); |
556 | err = -ENODEV; | ||
552 | goto out3; | 557 | goto out3; |
553 | } | 558 | } |
554 | 559 | ||
@@ -585,11 +590,13 @@ static int __init setup_adapter(int card_base, int type, int n) | |||
585 | if (register_netdev(info->dev[0])) { | 590 | if (register_netdev(info->dev[0])) { |
586 | printk(KERN_ERR "dmascc: could not register %s\n", | 591 | printk(KERN_ERR "dmascc: could not register %s\n", |
587 | info->dev[0]->name); | 592 | info->dev[0]->name); |
593 | err = -ENODEV; | ||
588 | goto out3; | 594 | goto out3; |
589 | } | 595 | } |
590 | if (register_netdev(info->dev[1])) { | 596 | if (register_netdev(info->dev[1])) { |
591 | printk(KERN_ERR "dmascc: could not register %s\n", | 597 | printk(KERN_ERR "dmascc: could not register %s\n", |
592 | info->dev[1]->name); | 598 | info->dev[1]->name); |
599 | err = -ENODEV; | ||
593 | goto out4; | 600 | goto out4; |
594 | } | 601 | } |
595 | 602 | ||
@@ -612,7 +619,7 @@ static int __init setup_adapter(int card_base, int type, int n) | |||
612 | out1: | 619 | out1: |
613 | kfree(info); | 620 | kfree(info); |
614 | out: | 621 | out: |
615 | return -1; | 622 | return err; |
616 | } | 623 | } |
617 | 624 | ||
618 | 625 | ||