Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Orangefs: fix sloppy cleanups of debugfs and sysfs init failures.

Signed-off-by: Mike Marshall <hubcap@omnibond.com>

+76 -62
+9 -11
fs/orangefs/orangefs-debugfs.c
··· 101 101 int rc = -ENOMEM; 102 102 103 103 debug_dir = debugfs_create_dir("orangefs", NULL); 104 - if (!debug_dir) 104 + if (!debug_dir) { 105 + pr_info("%s: debugfs_create_dir failed.\n", __func__); 105 106 goto out; 107 + } 106 108 107 109 help_file_dentry = debugfs_create_file(ORANGEFS_KMOD_DEBUG_HELP_FILE, 108 110 0444, 109 111 debug_dir, 110 112 debug_help_string, 111 113 &debug_help_fops); 112 - if (!help_file_dentry) 114 + if (!help_file_dentry) { 115 + pr_info("%s: debugfs_create_file failed.\n", __func__); 113 116 goto out; 117 + } 114 118 115 119 orangefs_debug_disabled = 0; 116 120 rc = 0; 117 121 118 122 out: 119 - if (rc) 120 - orangefs_debugfs_cleanup(); 121 123 122 124 return rc; 123 125 } 124 126 125 127 void orangefs_debugfs_cleanup(void) 126 128 { 127 - debugfs_remove_recursive(debug_dir); 129 + if (debug_dir) 130 + debugfs_remove_recursive(debug_dir); 128 131 } 129 132 130 133 /* open ORANGEFS_KMOD_DEBUG_HELP_FILE */ ··· 201 198 */ 202 199 int orangefs_kernel_debug_init(void) 203 200 { 204 - 205 201 int rc = -ENOMEM; 206 202 struct dentry *ret; 207 203 char *k_buffer = NULL; ··· 234 232 rc = 0; 235 233 236 234 out: 237 - if (rc) 238 - orangefs_debugfs_cleanup(); 239 235 240 236 gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: rc:%d:\n", __func__, rc); 241 237 return rc; ··· 268 268 c_buffer, 269 269 &kernel_debug_fops); 270 270 if (!client_debug_dentry) { 271 - pr_info("%s: failed to create %s.\n", 271 + pr_info("%s: failed to create updated %s.\n", 272 272 __func__, 273 273 ORANGEFS_CLIENT_DEBUG_FILE); 274 274 goto out; ··· 277 277 rc = 0; 278 278 279 279 out: 280 - if (rc) 281 - orangefs_debugfs_cleanup(); 282 280 283 281 gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: rc:%d:\n", __func__, rc); 284 282 return rc;
+23 -6
fs/orangefs/orangefs-mod.c
··· 185 185 */ 186 186 ret = orangefs_prepare_debugfs_help_string(1); 187 187 if (ret) 188 - goto out; 188 + goto prepare_helpstring_failed; 189 189 190 - orangefs_debugfs_init(); 191 - orangefs_kernel_debug_init(); 192 - orangefs_sysfs_init(); 190 + ret = orangefs_debugfs_init(); 191 + if (ret) 192 + goto debugfs_init_failed; 193 + 194 + ret = orangefs_kernel_debug_init(); 195 + if (ret) 196 + goto kernel_debug_init_failed; 197 + 198 + ret = orangefs_sysfs_init(); 199 + if (ret) 200 + goto sysfs_init_failed; 193 201 194 202 ret = register_filesystem(&orangefs_fs_type); 195 203 if (ret == 0) { 196 204 pr_info("orangefs: module version %s loaded\n", ORANGEFS_VERSION); 197 - return 0; 205 + ret = 0; 206 + goto out; 198 207 } 199 208 200 - orangefs_debugfs_cleanup(); 201 209 orangefs_sysfs_exit(); 202 210 fsid_key_table_finalize(); 211 + 212 + sysfs_init_failed: 213 + 214 + kernel_debug_init_failed: 215 + 216 + debugfs_init_failed: 217 + orangefs_debugfs_cleanup(); 218 + 219 + prepare_helpstring_failed: 203 220 204 221 cleanup_progress_table: 205 222 kfree(htable_ops_in_progress);
+44 -45
fs/orangefs/orangefs-sysfs.c
··· 1611 1611 1612 1612 int orangefs_sysfs_init(void) 1613 1613 { 1614 - int rc; 1614 + int rc = -EINVAL; 1615 1615 1616 1616 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_init: start\n"); 1617 1617 1618 1618 /* create /sys/fs/orangefs. */ 1619 1619 orangefs_obj = kzalloc(sizeof(*orangefs_obj), GFP_KERNEL); 1620 - if (!orangefs_obj) { 1621 - rc = -EINVAL; 1620 + if (!orangefs_obj) 1622 1621 goto out; 1623 - } 1624 1622 1625 1623 rc = kobject_init_and_add(&orangefs_obj->kobj, 1626 1624 &orangefs_ktype, 1627 1625 fs_kobj, 1628 1626 ORANGEFS_KOBJ_ID); 1629 1627 1630 - if (rc) { 1631 - kobject_put(&orangefs_obj->kobj); 1632 - rc = -EINVAL; 1633 - goto out; 1634 - } 1628 + if (rc) 1629 + goto ofs_obj_bail; 1635 1630 1636 1631 kobject_uevent(&orangefs_obj->kobj, KOBJ_ADD); 1637 1632 ··· 1634 1639 acache_orangefs_obj = kzalloc(sizeof(*acache_orangefs_obj), GFP_KERNEL); 1635 1640 if (!acache_orangefs_obj) { 1636 1641 rc = -EINVAL; 1637 - goto out; 1642 + goto ofs_obj_bail; 1638 1643 } 1639 1644 1640 1645 rc = kobject_init_and_add(&acache_orangefs_obj->kobj, ··· 1642 1647 &orangefs_obj->kobj, 1643 1648 ACACHE_KOBJ_ID); 1644 1649 1645 - if (rc) { 1646 - kobject_put(&acache_orangefs_obj->kobj); 1647 - rc = -EINVAL; 1648 - goto out; 1649 - } 1650 + if (rc) 1651 + goto acache_obj_bail; 1650 1652 1651 1653 kobject_uevent(&acache_orangefs_obj->kobj, KOBJ_ADD); 1652 1654 ··· 1652 1660 kzalloc(sizeof(*capcache_orangefs_obj), GFP_KERNEL); 1653 1661 if (!capcache_orangefs_obj) { 1654 1662 rc = -EINVAL; 1655 - goto out; 1663 + goto acache_obj_bail; 1656 1664 } 1657 1665 1658 1666 rc = kobject_init_and_add(&capcache_orangefs_obj->kobj, 1659 1667 &capcache_orangefs_ktype, 1660 1668 &orangefs_obj->kobj, 1661 1669 CAPCACHE_KOBJ_ID); 1662 - if (rc) { 1663 - kobject_put(&capcache_orangefs_obj->kobj); 1664 - rc = -EINVAL; 1665 - goto out; 1666 - } 1670 + if (rc) 1671 + goto capcache_obj_bail; 1667 1672 1668 1673 kobject_uevent(&capcache_orangefs_obj->kobj, KOBJ_ADD); 1669 1674 ··· 1669 1680 kzalloc(sizeof(*ccache_orangefs_obj), GFP_KERNEL); 1670 1681 if (!ccache_orangefs_obj) { 1671 1682 rc = -EINVAL; 1672 - goto out; 1683 + goto capcache_obj_bail; 1673 1684 } 1674 1685 1675 1686 rc = kobject_init_and_add(&ccache_orangefs_obj->kobj, 1676 1687 &ccache_orangefs_ktype, 1677 1688 &orangefs_obj->kobj, 1678 1689 CCACHE_KOBJ_ID); 1679 - if (rc) { 1680 - kobject_put(&ccache_orangefs_obj->kobj); 1681 - rc = -EINVAL; 1682 - goto out; 1683 - } 1690 + if (rc) 1691 + goto ccache_obj_bail; 1684 1692 1685 1693 kobject_uevent(&ccache_orangefs_obj->kobj, KOBJ_ADD); 1686 1694 ··· 1685 1699 ncache_orangefs_obj = kzalloc(sizeof(*ncache_orangefs_obj), GFP_KERNEL); 1686 1700 if (!ncache_orangefs_obj) { 1687 1701 rc = -EINVAL; 1688 - goto out; 1702 + goto ccache_obj_bail; 1689 1703 } 1690 1704 1691 1705 rc = kobject_init_and_add(&ncache_orangefs_obj->kobj, ··· 1693 1707 &orangefs_obj->kobj, 1694 1708 NCACHE_KOBJ_ID); 1695 1709 1696 - if (rc) { 1697 - kobject_put(&ncache_orangefs_obj->kobj); 1698 - rc = -EINVAL; 1699 - goto out; 1700 - } 1710 + if (rc) 1711 + goto ncache_obj_bail; 1701 1712 1702 1713 kobject_uevent(&ncache_orangefs_obj->kobj, KOBJ_ADD); 1703 1714 ··· 1702 1719 pc_orangefs_obj = kzalloc(sizeof(*pc_orangefs_obj), GFP_KERNEL); 1703 1720 if (!pc_orangefs_obj) { 1704 1721 rc = -EINVAL; 1705 - goto out; 1722 + goto ncache_obj_bail; 1706 1723 } 1707 1724 1708 1725 rc = kobject_init_and_add(&pc_orangefs_obj->kobj, ··· 1710 1727 &orangefs_obj->kobj, 1711 1728 "perf_counters"); 1712 1729 1713 - if (rc) { 1714 - kobject_put(&pc_orangefs_obj->kobj); 1715 - rc = -EINVAL; 1716 - goto out; 1717 - } 1730 + if (rc) 1731 + goto pc_obj_bail; 1718 1732 1719 1733 kobject_uevent(&pc_orangefs_obj->kobj, KOBJ_ADD); 1720 1734 ··· 1719 1739 stats_orangefs_obj = kzalloc(sizeof(*stats_orangefs_obj), GFP_KERNEL); 1720 1740 if (!stats_orangefs_obj) { 1721 1741 rc = -EINVAL; 1722 - goto out; 1742 + goto pc_obj_bail; 1723 1743 } 1724 1744 1725 1745 rc = kobject_init_and_add(&stats_orangefs_obj->kobj, ··· 1727 1747 &orangefs_obj->kobj, 1728 1748 STATS_KOBJ_ID); 1729 1749 1730 - if (rc) { 1731 - kobject_put(&stats_orangefs_obj->kobj); 1732 - rc = -EINVAL; 1733 - goto out; 1734 - } 1750 + if (rc) 1751 + goto stats_obj_bail; 1735 1752 1736 1753 kobject_uevent(&stats_orangefs_obj->kobj, KOBJ_ADD); 1754 + goto out; 1755 + 1756 + stats_obj_bail: 1757 + kobject_put(&stats_orangefs_obj->kobj); 1758 + 1759 + pc_obj_bail: 1760 + kobject_put(&pc_orangefs_obj->kobj); 1761 + 1762 + ncache_obj_bail: 1763 + kobject_put(&ncache_orangefs_obj->kobj); 1764 + 1765 + ccache_obj_bail: 1766 + kobject_put(&ccache_orangefs_obj->kobj); 1767 + 1768 + capcache_obj_bail: 1769 + kobject_put(&capcache_orangefs_obj->kobj); 1770 + 1771 + acache_obj_bail: 1772 + kobject_put(&acache_orangefs_obj->kobj); 1773 + 1774 + ofs_obj_bail: 1775 + kobject_put(&orangefs_obj->kobj); 1737 1776 out: 1738 1777 return rc; 1739 1778 }