diff options
author | Mariusz Kozlowski <m.kozlowski@tuxland.pl> | 2007-08-11 16:34:30 -0400 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2007-08-11 16:34:48 -0400 |
commit | 2e4934aa4586832c35e077191849a06f93e4a9a0 (patch) | |
tree | a548f2408b19ed634e49520e995bffe279a303a7 /drivers/block/cpqarray.c | |
parent | 1aebe18787ca2e915eb8204d365ba2484d53223b (diff) |
drivers/block/cpqarray.c: better error handling and kmalloc + memset conversion to k[cz]alloc
This patch removes some redundant casts, does the kmalloc + memset to
k[cz]alloc conversion and it changes the error path to use goto (to avoid code
duplication).
drivers/block/cpqarray.c | 49567 -> 48623 (-944 bytes)
drivers/block/cpqarray.o | 178820 -> 178288 (-532 bytes)
Signed-off-by: Mariusz Kozlowski <m.kozlowski@tuxland.pl>
Acked-by: Mike Miller <mike.miller@hp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'drivers/block/cpqarray.c')
-rw-r--r-- | drivers/block/cpqarray.c | 78 |
1 files changed, 26 insertions, 52 deletions
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c index be4e3477d83b..eb9799acf65b 100644 --- a/drivers/block/cpqarray.c +++ b/drivers/block/cpqarray.c | |||
@@ -420,18 +420,17 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev) | |||
420 | goto Enomem2; | 420 | goto Enomem2; |
421 | } | 421 | } |
422 | 422 | ||
423 | hba[i]->cmd_pool = (cmdlist_t *)pci_alloc_consistent( | 423 | hba[i]->cmd_pool = pci_alloc_consistent( |
424 | hba[i]->pci_dev, NR_CMDS * sizeof(cmdlist_t), | 424 | hba[i]->pci_dev, NR_CMDS * sizeof(cmdlist_t), |
425 | &(hba[i]->cmd_pool_dhandle)); | 425 | &(hba[i]->cmd_pool_dhandle)); |
426 | hba[i]->cmd_pool_bits = kmalloc( | 426 | hba[i]->cmd_pool_bits = kcalloc( |
427 | ((NR_CMDS+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long), | 427 | (NR_CMDS+BITS_PER_LONG-1)/BITS_PER_LONG, sizeof(unsigned long), |
428 | GFP_KERNEL); | 428 | GFP_KERNEL); |
429 | 429 | ||
430 | if (!hba[i]->cmd_pool_bits || !hba[i]->cmd_pool) | 430 | if (!hba[i]->cmd_pool_bits || !hba[i]->cmd_pool) |
431 | goto Enomem1; | 431 | goto Enomem1; |
432 | 432 | ||
433 | memset(hba[i]->cmd_pool, 0, NR_CMDS * sizeof(cmdlist_t)); | 433 | memset(hba[i]->cmd_pool, 0, NR_CMDS * sizeof(cmdlist_t)); |
434 | memset(hba[i]->cmd_pool_bits, 0, ((NR_CMDS+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long)); | ||
435 | printk(KERN_INFO "cpqarray: Finding drives on %s", | 434 | printk(KERN_INFO "cpqarray: Finding drives on %s", |
436 | hba[i]->devname); | 435 | hba[i]->devname); |
437 | 436 | ||
@@ -1660,45 +1659,30 @@ static void getgeometry(int ctlr) | |||
1660 | 1659 | ||
1661 | info_p->log_drv_map = 0; | 1660 | info_p->log_drv_map = 0; |
1662 | 1661 | ||
1663 | id_ldrive = kmalloc(sizeof(id_log_drv_t), GFP_KERNEL); | 1662 | id_ldrive = kzalloc(sizeof(id_log_drv_t), GFP_KERNEL); |
1664 | if(id_ldrive == NULL) | 1663 | if (!id_ldrive) { |
1665 | { | ||
1666 | printk( KERN_ERR "cpqarray: out of memory.\n"); | 1664 | printk( KERN_ERR "cpqarray: out of memory.\n"); |
1667 | return; | 1665 | goto err_0; |
1668 | } | 1666 | } |
1669 | 1667 | ||
1670 | id_ctlr_buf = kmalloc(sizeof(id_ctlr_t), GFP_KERNEL); | 1668 | id_ctlr_buf = kzalloc(sizeof(id_ctlr_t), GFP_KERNEL); |
1671 | if(id_ctlr_buf == NULL) | 1669 | if (!id_ctlr_buf) { |
1672 | { | ||
1673 | kfree(id_ldrive); | ||
1674 | printk( KERN_ERR "cpqarray: out of memory.\n"); | 1670 | printk( KERN_ERR "cpqarray: out of memory.\n"); |
1675 | return; | 1671 | goto err_1; |
1676 | } | 1672 | } |
1677 | 1673 | ||
1678 | id_lstatus_buf = kmalloc(sizeof(sense_log_drv_stat_t), GFP_KERNEL); | 1674 | id_lstatus_buf = kzalloc(sizeof(sense_log_drv_stat_t), GFP_KERNEL); |
1679 | if(id_lstatus_buf == NULL) | 1675 | if (!id_lstatus_buf) { |
1680 | { | ||
1681 | kfree(id_ctlr_buf); | ||
1682 | kfree(id_ldrive); | ||
1683 | printk( KERN_ERR "cpqarray: out of memory.\n"); | 1676 | printk( KERN_ERR "cpqarray: out of memory.\n"); |
1684 | return; | 1677 | goto err_2; |
1685 | } | 1678 | } |
1686 | 1679 | ||
1687 | sense_config_buf = kmalloc(sizeof(config_t), GFP_KERNEL); | 1680 | sense_config_buf = kzalloc(sizeof(config_t), GFP_KERNEL); |
1688 | if(sense_config_buf == NULL) | 1681 | if (!sense_config_buf) { |
1689 | { | ||
1690 | kfree(id_lstatus_buf); | ||
1691 | kfree(id_ctlr_buf); | ||
1692 | kfree(id_ldrive); | ||
1693 | printk( KERN_ERR "cpqarray: out of memory.\n"); | 1682 | printk( KERN_ERR "cpqarray: out of memory.\n"); |
1694 | return; | 1683 | goto err_3; |
1695 | } | 1684 | } |
1696 | 1685 | ||
1697 | memset(id_ldrive, 0, sizeof(id_log_drv_t)); | ||
1698 | memset(id_ctlr_buf, 0, sizeof(id_ctlr_t)); | ||
1699 | memset(id_lstatus_buf, 0, sizeof(sense_log_drv_stat_t)); | ||
1700 | memset(sense_config_buf, 0, sizeof(config_t)); | ||
1701 | |||
1702 | info_p->phys_drives = 0; | 1686 | info_p->phys_drives = 0; |
1703 | info_p->log_drv_map = 0; | 1687 | info_p->log_drv_map = 0; |
1704 | info_p->drv_assign_map = 0; | 1688 | info_p->drv_assign_map = 0; |
@@ -1712,13 +1696,8 @@ static void getgeometry(int ctlr) | |||
1712 | * so the idastubopen will fail on all logical drives | 1696 | * so the idastubopen will fail on all logical drives |
1713 | * on the controller. | 1697 | * on the controller. |
1714 | */ | 1698 | */ |
1715 | /* Free all the buffers and return */ | ||
1716 | printk(KERN_ERR "cpqarray: error sending ID controller\n"); | 1699 | printk(KERN_ERR "cpqarray: error sending ID controller\n"); |
1717 | kfree(sense_config_buf); | 1700 | goto err_4; |
1718 | kfree(id_lstatus_buf); | ||
1719 | kfree(id_ctlr_buf); | ||
1720 | kfree(id_ldrive); | ||
1721 | return; | ||
1722 | } | 1701 | } |
1723 | 1702 | ||
1724 | info_p->log_drives = id_ctlr_buf->nr_drvs; | 1703 | info_p->log_drives = id_ctlr_buf->nr_drvs; |
@@ -1764,12 +1743,7 @@ static void getgeometry(int ctlr) | |||
1764 | " failed to report status of logical drive %d\n" | 1743 | " failed to report status of logical drive %d\n" |
1765 | "Access to this controller has been disabled\n", | 1744 | "Access to this controller has been disabled\n", |
1766 | ctlr, log_unit); | 1745 | ctlr, log_unit); |
1767 | /* Free all the buffers and return */ | 1746 | goto err_4; |
1768 | kfree(sense_config_buf); | ||
1769 | kfree(id_lstatus_buf); | ||
1770 | kfree(id_ctlr_buf); | ||
1771 | kfree(id_ldrive); | ||
1772 | return; | ||
1773 | } | 1747 | } |
1774 | /* | 1748 | /* |
1775 | Make sure the logical drive is configured | 1749 | Make sure the logical drive is configured |
@@ -1798,14 +1772,8 @@ static void getgeometry(int ctlr) | |||
1798 | sizeof(config_t), 0, 0, log_unit); | 1772 | sizeof(config_t), 0, 0, log_unit); |
1799 | if (ret_code == IO_ERROR) { | 1773 | if (ret_code == IO_ERROR) { |
1800 | info_p->log_drv_map = 0; | 1774 | info_p->log_drv_map = 0; |
1801 | /* Free all the buffers and return */ | ||
1802 | printk(KERN_ERR "cpqarray: error sending sense config\n"); | 1775 | printk(KERN_ERR "cpqarray: error sending sense config\n"); |
1803 | kfree(sense_config_buf); | 1776 | goto err_4; |
1804 | kfree(id_lstatus_buf); | ||
1805 | kfree(id_ctlr_buf); | ||
1806 | kfree(id_ldrive); | ||
1807 | return; | ||
1808 | |||
1809 | } | 1777 | } |
1810 | 1778 | ||
1811 | info_p->phys_drives = | 1779 | info_p->phys_drives = |
@@ -1820,12 +1788,18 @@ static void getgeometry(int ctlr) | |||
1820 | log_index = log_index + 1; | 1788 | log_index = log_index + 1; |
1821 | } /* end of if logical drive configured */ | 1789 | } /* end of if logical drive configured */ |
1822 | } /* end of for log_unit */ | 1790 | } /* end of for log_unit */ |
1791 | |||
1792 | /* Free all the buffers and return */ | ||
1793 | err_4: | ||
1823 | kfree(sense_config_buf); | 1794 | kfree(sense_config_buf); |
1824 | kfree(id_ldrive); | 1795 | err_3: |
1825 | kfree(id_lstatus_buf); | 1796 | kfree(id_lstatus_buf); |
1797 | err_2: | ||
1826 | kfree(id_ctlr_buf); | 1798 | kfree(id_ctlr_buf); |
1799 | err_1: | ||
1800 | kfree(id_ldrive); | ||
1801 | err_0: | ||
1827 | return; | 1802 | return; |
1828 | |||
1829 | } | 1803 | } |
1830 | 1804 | ||
1831 | static void __exit cpqarray_exit(void) | 1805 | static void __exit cpqarray_exit(void) |