diff mbox series

[2/3] soc: ti: knav_qmss_queue: do device_node auto cleanup

Message ID 20240510071432.62913-3-five231003@gmail.com (mailing list archive)
State New
Headers show
Series Use scope based cleanup in drivers/soc/ti/ | expand

Commit Message

Kousik Sanagavarapu May 10, 2024, 7:13 a.m. UTC
Use scope based cleanup, instead of manual of_node_put() calls, which
automatically free()s "struct device_node".

Doing the cleanup this way has the advantage of reducing the chance of
memory leaks in case we need to read from new OF nodes in the future
when we probe.

Suggested-by: Julia Lawall <julia.lawall@inria.fr>
Signed-off-by: Kousik Sanagavarapu <five231003@gmail.com>
---
 drivers/soc/ti/knav_qmss_queue.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

Comments

kernel test robot May 11, 2024, 10:12 a.m. UTC | #1
Hi Kousik,

kernel test robot noticed the following build errors:

[auto build test ERROR on clk/clk-next]
[also build test ERROR on soc/for-next linus/master v6.9-rc7 next-20240510]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kousik-Sanagavarapu/soc-ti-pruss-do-device_node-auto-cleanup/20240510-151656
base:   https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
patch link:    https://lore.kernel.org/r/20240510071432.62913-3-five231003%40gmail.com
patch subject: [PATCH 2/3] soc: ti: knav_qmss_queue: do device_node auto cleanup
config: arm-defconfig (https://download.01.org/0day-ci/archive/20240511/202405111846.3m9z398l-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240511/202405111846.3m9z398l-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202405111846.3m9z398l-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/soc/ti/knav_qmss_queue.c:1853:3: error: cannot jump from this goto statement to its label
                   goto err;
                   ^
   drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *regions __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1840:3: error: cannot jump from this goto statement to its label
                   goto err;
                   ^
   drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *regions __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1835:3: error: cannot jump from this goto statement to its label
                   goto err;
                   ^
   drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *regions __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1831:3: error: cannot jump from this goto statement to its label
                   goto err;
                   ^
   drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *regions __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1822:4: error: cannot jump from this goto statement to its label
                           goto err;
                           ^
   drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *regions __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *queue_pools __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1818:4: error: cannot jump from this goto statement to its label
                           goto err;
                           ^
   drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *regions __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *queue_pools __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1810:3: error: cannot jump from this goto statement to its label
                   goto err;
                   ^
   drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *regions __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *queue_pools __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1813:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *pdsps __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1806:3: error: cannot jump from this goto statement to its label
                   goto err;
                   ^
   drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *regions __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *queue_pools __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1813:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *pdsps __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1795:3: error: cannot jump from this goto statement to its label
                   goto err;
                   ^
   drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *regions __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *queue_pools __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1813:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *pdsps __free(device_node) =
                               ^
   drivers/soc/ti/knav_qmss_queue.c:1801:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
           struct device_node *qmgrs __free(device_node) =
                               ^
   9 errors generated.


vim +1853 drivers/soc/ti/knav_qmss_queue.c

350601b4f7ab45 Murali Karicheri    2018-04-17  1754  
41f93af900a20d Sandeep Nair        2014-02-28  1755  static int knav_queue_probe(struct platform_device *pdev)
41f93af900a20d Sandeep Nair        2014-02-28  1756  {
41f93af900a20d Sandeep Nair        2014-02-28  1757  	struct device_node *node = pdev->dev.of_node;
41f93af900a20d Sandeep Nair        2014-02-28  1758  	struct device *dev = &pdev->dev;
41f93af900a20d Sandeep Nair        2014-02-28  1759  	u32 temp[2];
41f93af900a20d Sandeep Nair        2014-02-28  1760  	int ret;
41f93af900a20d Sandeep Nair        2014-02-28  1761  
41f93af900a20d Sandeep Nair        2014-02-28  1762  	if (!node) {
41f93af900a20d Sandeep Nair        2014-02-28  1763  		dev_err(dev, "device tree info unavailable\n");
41f93af900a20d Sandeep Nair        2014-02-28  1764  		return -ENODEV;
41f93af900a20d Sandeep Nair        2014-02-28  1765  	}
41f93af900a20d Sandeep Nair        2014-02-28  1766  
41f93af900a20d Sandeep Nair        2014-02-28  1767  	kdev = devm_kzalloc(dev, sizeof(struct knav_device), GFP_KERNEL);
41f93af900a20d Sandeep Nair        2014-02-28  1768  	if (!kdev) {
41f93af900a20d Sandeep Nair        2014-02-28  1769  		dev_err(dev, "memory allocation failed\n");
41f93af900a20d Sandeep Nair        2014-02-28  1770  		return -ENOMEM;
41f93af900a20d Sandeep Nair        2014-02-28  1771  	}
41f93af900a20d Sandeep Nair        2014-02-28  1772  
50c01a942b2874 Rob Herring         2023-10-09  1773  	if (device_get_match_data(dev))
350601b4f7ab45 Murali Karicheri    2018-04-17  1774  		kdev->version = QMSS_66AK2G;
350601b4f7ab45 Murali Karicheri    2018-04-17  1775  
41f93af900a20d Sandeep Nair        2014-02-28  1776  	platform_set_drvdata(pdev, kdev);
41f93af900a20d Sandeep Nair        2014-02-28  1777  	kdev->dev = dev;
41f93af900a20d Sandeep Nair        2014-02-28  1778  	INIT_LIST_HEAD(&kdev->queue_ranges);
41f93af900a20d Sandeep Nair        2014-02-28  1779  	INIT_LIST_HEAD(&kdev->qmgrs);
41f93af900a20d Sandeep Nair        2014-02-28  1780  	INIT_LIST_HEAD(&kdev->pools);
41f93af900a20d Sandeep Nair        2014-02-28  1781  	INIT_LIST_HEAD(&kdev->regions);
41f93af900a20d Sandeep Nair        2014-02-28  1782  	INIT_LIST_HEAD(&kdev->pdsps);
41f93af900a20d Sandeep Nair        2014-02-28  1783  
41f93af900a20d Sandeep Nair        2014-02-28  1784  	pm_runtime_enable(&pdev->dev);
12eeb74925da70 Minghao Chi         2022-04-18  1785  	ret = pm_runtime_resume_and_get(&pdev->dev);
41f93af900a20d Sandeep Nair        2014-02-28  1786  	if (ret < 0) {
e961c0f19450fd Zhang Qilong        2022-11-08  1787  		pm_runtime_disable(&pdev->dev);
41f93af900a20d Sandeep Nair        2014-02-28  1788  		dev_err(dev, "Failed to enable QMSS\n");
41f93af900a20d Sandeep Nair        2014-02-28  1789  		return ret;
41f93af900a20d Sandeep Nair        2014-02-28  1790  	}
41f93af900a20d Sandeep Nair        2014-02-28  1791  
41f93af900a20d Sandeep Nair        2014-02-28  1792  	if (of_property_read_u32_array(node, "queue-range", temp, 2)) {
41f93af900a20d Sandeep Nair        2014-02-28  1793  		dev_err(dev, "queue-range not specified\n");
41f93af900a20d Sandeep Nair        2014-02-28  1794  		ret = -ENODEV;
41f93af900a20d Sandeep Nair        2014-02-28  1795  		goto err;
41f93af900a20d Sandeep Nair        2014-02-28  1796  	}
41f93af900a20d Sandeep Nair        2014-02-28  1797  	kdev->base_id    = temp[0];
41f93af900a20d Sandeep Nair        2014-02-28  1798  	kdev->num_queues = temp[1];
41f93af900a20d Sandeep Nair        2014-02-28  1799  
41f93af900a20d Sandeep Nair        2014-02-28  1800  	/* Initialize queue managers using device tree configuration */
10e6f93cca367b Kousik Sanagavarapu 2024-05-10  1801  	struct device_node *qmgrs __free(device_node) =
10e6f93cca367b Kousik Sanagavarapu 2024-05-10  1802  			of_get_child_by_name(node, "qmgrs");
41f93af900a20d Sandeep Nair        2014-02-28  1803  	if (!qmgrs) {
41f93af900a20d Sandeep Nair        2014-02-28  1804  		dev_err(dev, "queue manager info not specified\n");
41f93af900a20d Sandeep Nair        2014-02-28  1805  		ret = -ENODEV;
41f93af900a20d Sandeep Nair        2014-02-28  1806  		goto err;
41f93af900a20d Sandeep Nair        2014-02-28  1807  	}
41f93af900a20d Sandeep Nair        2014-02-28  1808  	ret = knav_queue_init_qmgrs(kdev, qmgrs);
41f93af900a20d Sandeep Nair        2014-02-28  1809  	if (ret)
41f93af900a20d Sandeep Nair        2014-02-28  1810  		goto err;
41f93af900a20d Sandeep Nair        2014-02-28  1811  
41f93af900a20d Sandeep Nair        2014-02-28  1812  	/* get pdsp configuration values from device tree */
10e6f93cca367b Kousik Sanagavarapu 2024-05-10  1813  	struct device_node *pdsps __free(device_node) =
10e6f93cca367b Kousik Sanagavarapu 2024-05-10  1814  			of_get_child_by_name(node, "pdsps");
41f93af900a20d Sandeep Nair        2014-02-28  1815  	if (pdsps) {
41f93af900a20d Sandeep Nair        2014-02-28  1816  		ret = knav_queue_init_pdsps(kdev, pdsps);
41f93af900a20d Sandeep Nair        2014-02-28  1817  		if (ret)
41f93af900a20d Sandeep Nair        2014-02-28  1818  			goto err;
41f93af900a20d Sandeep Nair        2014-02-28  1819  
41f93af900a20d Sandeep Nair        2014-02-28  1820  		ret = knav_queue_start_pdsps(kdev);
41f93af900a20d Sandeep Nair        2014-02-28  1821  		if (ret)
41f93af900a20d Sandeep Nair        2014-02-28  1822  			goto err;
41f93af900a20d Sandeep Nair        2014-02-28  1823  	}
41f93af900a20d Sandeep Nair        2014-02-28  1824  
41f93af900a20d Sandeep Nair        2014-02-28  1825  	/* get usable queue range values from device tree */
10e6f93cca367b Kousik Sanagavarapu 2024-05-10  1826  	struct device_node *queue_pools __free(device_node) =
10e6f93cca367b Kousik Sanagavarapu 2024-05-10  1827  			of_get_child_by_name(node, "queue-pools");
41f93af900a20d Sandeep Nair        2014-02-28  1828  	if (!queue_pools) {
41f93af900a20d Sandeep Nair        2014-02-28  1829  		dev_err(dev, "queue-pools not specified\n");
41f93af900a20d Sandeep Nair        2014-02-28  1830  		ret = -ENODEV;
41f93af900a20d Sandeep Nair        2014-02-28  1831  		goto err;
41f93af900a20d Sandeep Nair        2014-02-28  1832  	}
41f93af900a20d Sandeep Nair        2014-02-28  1833  	ret = knav_setup_queue_pools(kdev, queue_pools);
41f93af900a20d Sandeep Nair        2014-02-28  1834  	if (ret)
41f93af900a20d Sandeep Nair        2014-02-28  1835  		goto err;
41f93af900a20d Sandeep Nair        2014-02-28  1836  
41f93af900a20d Sandeep Nair        2014-02-28  1837  	ret = knav_get_link_ram(kdev, "linkram0", &kdev->link_rams[0]);
41f93af900a20d Sandeep Nair        2014-02-28  1838  	if (ret) {
41f93af900a20d Sandeep Nair        2014-02-28  1839  		dev_err(kdev->dev, "could not setup linking ram\n");
41f93af900a20d Sandeep Nair        2014-02-28  1840  		goto err;
41f93af900a20d Sandeep Nair        2014-02-28  1841  	}
41f93af900a20d Sandeep Nair        2014-02-28  1842  
41f93af900a20d Sandeep Nair        2014-02-28  1843  	ret = knav_get_link_ram(kdev, "linkram1", &kdev->link_rams[1]);
41f93af900a20d Sandeep Nair        2014-02-28  1844  	if (ret) {
41f93af900a20d Sandeep Nair        2014-02-28  1845  		/*
41f93af900a20d Sandeep Nair        2014-02-28  1846  		 * nothing really, we have one linking ram already, so we just
41f93af900a20d Sandeep Nair        2014-02-28  1847  		 * live within our means
41f93af900a20d Sandeep Nair        2014-02-28  1848  		 */
41f93af900a20d Sandeep Nair        2014-02-28  1849  	}
41f93af900a20d Sandeep Nair        2014-02-28  1850  
41f93af900a20d Sandeep Nair        2014-02-28  1851  	ret = knav_queue_setup_link_ram(kdev);
41f93af900a20d Sandeep Nair        2014-02-28  1852  	if (ret)
41f93af900a20d Sandeep Nair        2014-02-28 @1853  		goto err;
41f93af900a20d Sandeep Nair        2014-02-28  1854  
10e6f93cca367b Kousik Sanagavarapu 2024-05-10  1855  	struct device_node *regions __free(device_node) =
10e6f93cca367b Kousik Sanagavarapu 2024-05-10  1856  			of_get_child_by_name(node, "descriptor-regions");
41f93af900a20d Sandeep Nair        2014-02-28  1857  	if (!regions) {
41f93af900a20d Sandeep Nair        2014-02-28  1858  		dev_err(dev, "descriptor-regions not specified\n");
4cba398f37f868 Zhihao Cheng        2020-11-21  1859  		ret = -ENODEV;
41f93af900a20d Sandeep Nair        2014-02-28  1860  		goto err;
41f93af900a20d Sandeep Nair        2014-02-28  1861  	}
41f93af900a20d Sandeep Nair        2014-02-28  1862  	ret = knav_queue_setup_regions(kdev, regions);
41f93af900a20d Sandeep Nair        2014-02-28  1863  	if (ret)
41f93af900a20d Sandeep Nair        2014-02-28  1864  		goto err;
41f93af900a20d Sandeep Nair        2014-02-28  1865  
41f93af900a20d Sandeep Nair        2014-02-28  1866  	ret = knav_queue_init_queues(kdev);
41f93af900a20d Sandeep Nair        2014-02-28  1867  	if (ret < 0) {
41f93af900a20d Sandeep Nair        2014-02-28  1868  		dev_err(dev, "hwqueue initialization failed\n");
41f93af900a20d Sandeep Nair        2014-02-28  1869  		goto err;
41f93af900a20d Sandeep Nair        2014-02-28  1870  	}
41f93af900a20d Sandeep Nair        2014-02-28  1871  
41f93af900a20d Sandeep Nair        2014-02-28  1872  	debugfs_create_file("qmss", S_IFREG | S_IRUGO, NULL, NULL,
74e0e43a09cea3 Qinglang Miao       2020-09-20  1873  			    &knav_queue_debug_fops);
a2dd6877b43ef1 Murali Karicheri    2018-04-17  1874  	device_ready = true;
41f93af900a20d Sandeep Nair        2014-02-28  1875  	return 0;
41f93af900a20d Sandeep Nair        2014-02-28  1876  
41f93af900a20d Sandeep Nair        2014-02-28  1877  err:
41f93af900a20d Sandeep Nair        2014-02-28  1878  	knav_queue_stop_pdsps(kdev);
41f93af900a20d Sandeep Nair        2014-02-28  1879  	knav_queue_free_regions(kdev);
41f93af900a20d Sandeep Nair        2014-02-28  1880  	knav_free_queue_ranges(kdev);
41f93af900a20d Sandeep Nair        2014-02-28  1881  	pm_runtime_put_sync(&pdev->dev);
41f93af900a20d Sandeep Nair        2014-02-28  1882  	pm_runtime_disable(&pdev->dev);
41f93af900a20d Sandeep Nair        2014-02-28  1883  	return ret;
41f93af900a20d Sandeep Nair        2014-02-28  1884  }
41f93af900a20d Sandeep Nair        2014-02-28  1885
Kousik Sanagavarapu May 12, 2024, 10:26 a.m. UTC | #2
On Sat, May 11, 2024 at 06:12:39PM +0800, kernel test robot wrote:
> Hi Kousik,
> 
> kernel test robot noticed the following build errors:
> 

[...]

> All errors (new ones prefixed by >>):
> 
> >> drivers/soc/ti/knav_qmss_queue.c:1853:3: error: cannot jump from this goto statement to its label
>                    goto err;
>                    ^
>    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *regions __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1840:3: error: cannot jump from this goto statement to its label
>                    goto err;
>                    ^
>    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *regions __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1835:3: error: cannot jump from this goto statement to its label
>                    goto err;
>                    ^
>    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *regions __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1831:3: error: cannot jump from this goto statement to its label
>                    goto err;
>                    ^
>    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *regions __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1822:4: error: cannot jump from this goto statement to its label
>                            goto err;
>                            ^
>    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *regions __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *queue_pools __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1818:4: error: cannot jump from this goto statement to its label
>                            goto err;
>                            ^
>    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *regions __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *queue_pools __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1810:3: error: cannot jump from this goto statement to its label
>                    goto err;
>                    ^
>    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *regions __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *queue_pools __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1813:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *pdsps __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1806:3: error: cannot jump from this goto statement to its label
>                    goto err;
>                    ^
>    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *regions __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *queue_pools __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1813:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *pdsps __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1795:3: error: cannot jump from this goto statement to its label
>                    goto err;
>                    ^
>    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *regions __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *queue_pools __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1813:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *pdsps __free(device_node) =
>                                ^
>    drivers/soc/ti/knav_qmss_queue.c:1801:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
>            struct device_node *qmgrs __free(device_node) =
>                                ^
>    9 errors generated.

Seems like gcc didn't catch this when I compiled locally.

Normally, this would be fixed if we placed braces around the individual
initialization blocks, that is, say

	{
		struct device_node *qmgrs __free(device_node) =
			of_get_child_by_name(node, "qmgrs");
		...
	}


That would make the code look a lot more dirty though and is purely
unnecessary.  So I'd say I'd drop this patch and do a v2 with the
remaining two patches.  Thoughts?

There's also some stuff with classes but that too is not really worth
doing because the code will end up looking very ugly.

Thanks
Julia Lawall May 12, 2024, 10:36 a.m. UTC | #3
On Sun, 12 May 2024, Kousik Sanagavarapu wrote:

> On Sat, May 11, 2024 at 06:12:39PM +0800, kernel test robot wrote:
> > Hi Kousik,
> >
> > kernel test robot noticed the following build errors:
> >
>
> [...]
>
> > All errors (new ones prefixed by >>):
> >
> > >> drivers/soc/ti/knav_qmss_queue.c:1853:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1840:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1835:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1831:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1822:4: error: cannot jump from this goto statement to its label
> >                            goto err;
> >                            ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *queue_pools __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1818:4: error: cannot jump from this goto statement to its label
> >                            goto err;
> >                            ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *queue_pools __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1810:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *queue_pools __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1813:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *pdsps __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1806:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *queue_pools __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1813:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *pdsps __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1795:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *queue_pools __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1813:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *pdsps __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1801:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *qmgrs __free(device_node) =
> >                                ^
> >    9 errors generated.
>
> Seems like gcc didn't catch this when I compiled locally.
>
> Normally, this would be fixed if we placed braces around the individual
> initialization blocks, that is, say
>
> 	{
> 		struct device_node *qmgrs __free(device_node) =
> 			of_get_child_by_name(node, "qmgrs");
> 		...
> 	}
>
>
> That would make the code look a lot more dirty though and is purely
> unnecessary.  So I'd say I'd drop this patch and do a v2 with the
> remaining two patches.  Thoughts?
>
> There's also some stuff with classes but that too is not really worth
> doing because the code will end up looking very ugly.

Please include the patch in such a message so that one can see everything
at once.  I'm not sure it's necessary to show all the error messages
either.  Just a few that help illustrate the problem.

julia
Nathan Chancellor May 13, 2024, 6:44 a.m. UTC | #4
On Sun, May 12, 2024 at 03:56:22PM +0530, Kousik Sanagavarapu wrote:
> On Sat, May 11, 2024 at 06:12:39PM +0800, kernel test robot wrote:
> > Hi Kousik,
> > 
> > kernel test robot noticed the following build errors:
> > 
> 
> [...]
> 
> > All errors (new ones prefixed by >>):
> > 
> > >> drivers/soc/ti/knav_qmss_queue.c:1853:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1840:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1835:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1831:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1822:4: error: cannot jump from this goto statement to its label
> >                            goto err;
> >                            ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *queue_pools __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1818:4: error: cannot jump from this goto statement to its label
> >                            goto err;
> >                            ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *queue_pools __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1810:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *queue_pools __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1813:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *pdsps __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1806:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *queue_pools __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1813:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *pdsps __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1795:3: error: cannot jump from this goto statement to its label
> >                    goto err;
> >                    ^
> >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *regions __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1826:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *queue_pools __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1813:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *pdsps __free(device_node) =
> >                                ^
> >    drivers/soc/ti/knav_qmss_queue.c:1801:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> >            struct device_node *qmgrs __free(device_node) =
> >                                ^
> >    9 errors generated.
> 
> Seems like gcc didn't catch this when I compiled locally.

FWIW, you may notice this as you do more conversions. The fact that GCC
does not warn at all is a GCC bug as far as I am aware (i.e., clang's
error is correct):

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91951

which has come up in other places:

https://lore.kernel.org/20240425174732.GA270911@dev-arch.thelio-3990X/

Cheers,
Nathan
Kousik Sanagavarapu May 13, 2024, 7:23 a.m. UTC | #5
On Sun, May 12, 2024 at 11:44:51PM -0700, Nathan Chancellor wrote:
> On Sun, May 12, 2024 at 03:56:22PM +0530, Kousik Sanagavarapu wrote:
> > On Sat, May 11, 2024 at 06:12:39PM +0800, kernel test robot wrote:
> > > Hi Kousik,
> > > 
> > > kernel test robot noticed the following build errors:
> > > 
> > 
> > [...]
> > 
> > > All errors (new ones prefixed by >>):
> > > 
> > > >> drivers/soc/ti/knav_qmss_queue.c:1853:3: error: cannot jump from this goto statement to its label
> > >                    goto err;
> > >                    ^
> > >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> > >            struct device_node *regions __free(device_node) =
> > >                                ^

[...]

> > Seems like gcc didn't catch this when I compiled locally.
> 
> FWIW, you may notice this as you do more conversions. The fact that GCC
> does not warn at all is a GCC bug as far as I am aware (i.e., clang's
> error is correct):
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91951
> 
> which has come up in other places:
> 
> https://lore.kernel.org/20240425174732.GA270911@dev-arch.thelio-3990X/

Thank you so much for these links :)

All my internet searches ended up at stackoverflow posts which didn't
even describe the problem correctly, which also lead me to write an
email explaining a partly erroneous solution, which is sitting in my
mailbox ;)

Thanks again, these will help a lot.
Jonathan Cameron May 16, 2024, 2:48 p.m. UTC | #6
On Mon, 13 May 2024 12:53:27 +0530
Kousik Sanagavarapu <five231003@gmail.com> wrote:

> On Sun, May 12, 2024 at 11:44:51PM -0700, Nathan Chancellor wrote:
> > On Sun, May 12, 2024 at 03:56:22PM +0530, Kousik Sanagavarapu wrote:  
> > > On Sat, May 11, 2024 at 06:12:39PM +0800, kernel test robot wrote:  
> > > > Hi Kousik,
> > > > 
> > > > kernel test robot noticed the following build errors:
> > > >   
> > > 
> > > [...]
> > >   
> > > > All errors (new ones prefixed by >>):
> > > >   
> > > > >> drivers/soc/ti/knav_qmss_queue.c:1853:3: error: cannot jump from this goto statement to its label  
> > > >                    goto err;
> > > >                    ^
> > > >    drivers/soc/ti/knav_qmss_queue.c:1855:22: note: jump bypasses initialization of variable with __attribute__((cleanup))
> > > >            struct device_node *regions __free(device_node) =
> > > >                                ^  
> 
> [...]
> 
> > > Seems like gcc didn't catch this when I compiled locally.  
> > 
> > FWIW, you may notice this as you do more conversions. The fact that GCC
> > does not warn at all is a GCC bug as far as I am aware (i.e., clang's
> > error is correct):
> > 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91951
> > 
> > which has come up in other places:
> > 
> > https://lore.kernel.org/20240425174732.GA270911@dev-arch.thelio-3990X/  
> 
> Thank you so much for these links :)
> 
> All my internet searches ended up at stackoverflow posts which didn't
> even describe the problem correctly, which also lead me to write an
> email explaining a partly erroneous solution, which is sitting in my
> mailbox ;)
> 
> Thanks again, these will help a lot.

Independent of all this, it's not a good idea form a readability point
of view to mix automated and manual cleanup.  So in cases like this
where you want to do scope based cleanup, use separate functions
that have appropriately defined scope (or brackets for the really minor
cases).

Here, you may just be able to push the device_node get into
knav_queue_setup_regions() for example.

Jonathan

> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
diff mbox series

Patch

diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c
index 06fb5505c22c..237946312080 100644
--- a/drivers/soc/ti/knav_qmss_queue.c
+++ b/drivers/soc/ti/knav_qmss_queue.c
@@ -1755,7 +1755,6 @@  MODULE_DEVICE_TABLE(of, keystone_qmss_of_match);
 static int knav_queue_probe(struct platform_device *pdev)
 {
 	struct device_node *node = pdev->dev.of_node;
-	struct device_node *qmgrs, *queue_pools, *regions, *pdsps;
 	struct device *dev = &pdev->dev;
 	u32 temp[2];
 	int ret;
@@ -1799,19 +1798,20 @@  static int knav_queue_probe(struct platform_device *pdev)
 	kdev->num_queues = temp[1];
 
 	/* Initialize queue managers using device tree configuration */
-	qmgrs =  of_get_child_by_name(node, "qmgrs");
+	struct device_node *qmgrs __free(device_node) =
+			of_get_child_by_name(node, "qmgrs");
 	if (!qmgrs) {
 		dev_err(dev, "queue manager info not specified\n");
 		ret = -ENODEV;
 		goto err;
 	}
 	ret = knav_queue_init_qmgrs(kdev, qmgrs);
-	of_node_put(qmgrs);
 	if (ret)
 		goto err;
 
 	/* get pdsp configuration values from device tree */
-	pdsps =  of_get_child_by_name(node, "pdsps");
+	struct device_node *pdsps __free(device_node) =
+			of_get_child_by_name(node, "pdsps");
 	if (pdsps) {
 		ret = knav_queue_init_pdsps(kdev, pdsps);
 		if (ret)
@@ -1821,17 +1821,16 @@  static int knav_queue_probe(struct platform_device *pdev)
 		if (ret)
 			goto err;
 	}
-	of_node_put(pdsps);
 
 	/* get usable queue range values from device tree */
-	queue_pools = of_get_child_by_name(node, "queue-pools");
+	struct device_node *queue_pools __free(device_node) =
+			of_get_child_by_name(node, "queue-pools");
 	if (!queue_pools) {
 		dev_err(dev, "queue-pools not specified\n");
 		ret = -ENODEV;
 		goto err;
 	}
 	ret = knav_setup_queue_pools(kdev, queue_pools);
-	of_node_put(queue_pools);
 	if (ret)
 		goto err;
 
@@ -1853,14 +1852,14 @@  static int knav_queue_probe(struct platform_device *pdev)
 	if (ret)
 		goto err;
 
-	regions = of_get_child_by_name(node, "descriptor-regions");
+	struct device_node *regions __free(device_node) =
+			of_get_child_by_name(node, "descriptor-regions");
 	if (!regions) {
 		dev_err(dev, "descriptor-regions not specified\n");
 		ret = -ENODEV;
 		goto err;
 	}
 	ret = knav_queue_setup_regions(kdev, regions);
-	of_node_put(regions);
 	if (ret)
 		goto err;