Re: [PATCH] thunderbolt: Use common error handling code in update_property_block()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>> 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





[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux