diff mbox series

thunderbolt: Use common error handling code in update_property_block()

Message ID 26b7f215-4f83-413c-9dab-737d790053c0@web.de
State New
Headers show
Series thunderbolt: Use common error handling code in update_property_block() | expand

Commit Message

Markus Elfring Sept. 25, 2024, 8:10 a.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 25 Sep 2024 09:39:16 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of this function implementation.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/thunderbolt/xdomain.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

--
2.46.1

Comments

kernel test robot Sept. 25, 2024, 11:58 p.m. UTC | #1
Hi Markus,

kernel test robot noticed the following build errors:

[auto build test ERROR on westeri-thunderbolt/next]
[also build test ERROR on linus/master v6.11 next-20240925]
[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/Markus-Elfring/thunderbolt-Use-common-error-handling-code-in-update_property_block/20240925-161308
base:   https://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt.git next
patch link:    https://lore.kernel.org/r/26b7f215-4f83-413c-9dab-737d790053c0%40web.de
patch subject: [PATCH] thunderbolt: Use common error handling code in update_property_block()
config: arc-randconfig-001-20240926 (https://download.01.org/0day-ci/archive/20240926/202409260728.uNVNmTvy-lkp@intel.com/config)
compiler: arceb-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240926/202409260728.uNVNmTvy-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/202409260728.uNVNmTvy-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/thunderbolt/xdomain.c: In function 'update_property_block':
>> drivers/thunderbolt/xdomain.c:703:30: error: 'dir' undeclared (first use in this function); did you mean 'idr'?
     703 |         tb_property_free_dir(dir);
         |                              ^~~
         |                              idr
   drivers/thunderbolt/xdomain.c:703:30: note: each undeclared identifier is reported only once for each function it appears in


vim +703 drivers/thunderbolt/xdomain.c

   645	
   646	static void update_property_block(struct tb_xdomain *xd)
   647	{
   648		mutex_lock(&xdomain_lock);
   649		mutex_lock(&xd->lock);
   650		/*
   651		 * If the local property block is not up-to-date, rebuild it now
   652		 * based on the global property template.
   653		 */
   654		if (!xd->local_property_block ||
   655		    xd->local_property_block_gen < xdomain_property_block_gen) {
   656			struct tb_property_dir *dir;
   657			int ret, block_len;
   658			u32 *block;
   659	
   660			dir = tb_property_copy_dir(xdomain_property_dir);
   661			if (!dir) {
   662				dev_warn(&xd->dev, "failed to copy properties\n");
   663				goto out_unlock;
   664			}
   665	
   666			/* Fill in non-static properties now */
   667			tb_property_add_text(dir, "deviceid", utsname()->nodename);
   668			tb_property_add_immediate(dir, "maxhopid", xd->local_max_hopid);
   669	
   670			ret = tb_property_format_dir(dir, NULL, 0);
   671			if (ret < 0) {
   672				dev_warn(&xd->dev, "local property block creation failed\n");
   673				goto out_free_dir;
   674			}
   675	
   676			block_len = ret;
   677			block = kcalloc(block_len, sizeof(*block), GFP_KERNEL);
   678			if (!block)
   679				goto out_free_dir;
   680	
   681			ret = tb_property_format_dir(dir, block, block_len);
   682			if (ret) {
   683				dev_warn(&xd->dev, "property block generation failed\n");
   684				kfree(block);
   685				goto out_free_dir;
   686			}
   687	
   688			tb_property_free_dir(dir);
   689			/* Release the previous block */
   690			kfree(xd->local_property_block);
   691			/* Assign new one */
   692			xd->local_property_block = block;
   693			xd->local_property_block_len = block_len;
   694			xd->local_property_block_gen = xdomain_property_block_gen;
   695		}
   696	
   697	out_unlock:
   698		mutex_unlock(&xd->lock);
   699		mutex_unlock(&xdomain_lock);
   700		return;
   701	
   702	out_free_dir:
 > 703		tb_property_free_dir(dir);
   704		goto out_unlock;
   705	}
   706
diff mbox series

Patch

diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
index 11a50c86a1e4..8e3cf95ca99c 100644
--- a/drivers/thunderbolt/xdomain.c
+++ b/drivers/thunderbolt/xdomain.c
@@ -670,23 +670,19 @@  static void update_property_block(struct tb_xdomain *xd)
 		ret = tb_property_format_dir(dir, NULL, 0);
 		if (ret < 0) {
 			dev_warn(&xd->dev, "local property block creation failed\n");
-			tb_property_free_dir(dir);
-			goto out_unlock;
+			goto out_free_dir;
 		}

 		block_len = ret;
 		block = kcalloc(block_len, sizeof(*block), GFP_KERNEL);
-		if (!block) {
-			tb_property_free_dir(dir);
-			goto out_unlock;
-		}
+		if (!block)
+			goto out_free_dir;

 		ret = tb_property_format_dir(dir, block, block_len);
 		if (ret) {
 			dev_warn(&xd->dev, "property block generation failed\n");
-			tb_property_free_dir(dir);
 			kfree(block);
-			goto out_unlock;
+			goto out_free_dir;
 		}

 		tb_property_free_dir(dir);
@@ -701,6 +697,11 @@  static void update_property_block(struct tb_xdomain *xd)
 out_unlock:
 	mutex_unlock(&xd->lock);
 	mutex_unlock(&xdomain_lock);
+	return;
+
+out_free_dir:
+	tb_property_free_dir(dir);
+	goto out_unlock;
 }

 static void start_handshake(struct tb_xdomain *xd)