public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Mika Westerberg <mika.westerberg@linux.intel.com>,
	linux-usb@vger.kernel.org,
	Andreas Noever <andreas.noever@gmail.com>,
	Michael Jamet <michael.jamet@intel.com>,
	Yehezkel Bernat <YehezkelShB@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] thunderbolt: Use common error handling code in update_property_block()
Date: Wed, 25 Sep 2024 11:20:45 +0200	[thread overview]
Message-ID: <a0c37886-cf9e-4c4c-8ff2-db8735f97cb6@web.de> (raw)
In-Reply-To: <20240925084501.GY275077@black.fi.intel.com>

>> Add a jump target so that a bit of exception handling can be better reused
>> at the end of this function implementation.
>> +++ 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;
>
> No way, this kind of spaghetti is really hard to follow.

Under which circumstances would you follow advice more from the section
“7) Centralized exiting of functions” (according to a well-known information source)?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.11#n526

How do you think about to increase the application of scope-based resource management?

Regards,
Markus

  reply	other threads:[~2024-09-25  9:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-25  8:10 [PATCH] thunderbolt: Use common error handling code in update_property_block() Markus Elfring
2024-09-25  8:45 ` Mika Westerberg
2024-09-25  9:20   ` Markus Elfring [this message]
2024-09-25  9:35     ` Mika Westerberg
2024-09-25  9:40       ` Markus Elfring
2024-09-25  9:42         ` Greg KH
2024-09-25 23:58 ` [PATCH] " kernel test robot
2024-09-26  1:52 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a0c37886-cf9e-4c4c-8ff2-db8735f97cb6@web.de \
    --to=markus.elfring@web.de \
    --cc=YehezkelShB@gmail.com \
    --cc=andreas.noever@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=michael.jamet@intel.com \
    --cc=mika.westerberg@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox