Re: dm: Use common error handling code in three functions
Mikulas Patocka <[email protected]> Thu, 11 Jun 2026 15:25:17 +0200 (CEST)
| Newsgroups | org.kernel.vger.kernel-janitors,dev.linux.lists.dm-devel,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 11 Jun 2026, Markus Elfring wrote: > >> Use additional labels so that a bit of exception handling can be better > >> reused at the end of three if branches. > >> > >> This issue was detected by using the Coccinelle software. > > > > Hi > > > > I think that jumping into a nested block isn't good practice and it makes > > the code harder to read and maintain. I would redo the patches so that > > they jump to the end of the topmost function block, for example: > Thanks for your constructive feedback. > > Can any further adjustments become feasible for the design goal “Centralized exiting of functions”? > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v7.1-rc7#n526 I think that this document is OK. > Would you find goto chains applicable for another while? > https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/recommendations/memory-management-mem/mem12-c/ I think goto chains are ok if there are few variables to free. > How do you think about to increase the application of scope-based resource management? > https://elixir.bootlin.com/linux/v7.1-rc7/source/include/linux/cleanup.h I am not a fan of these. I think that goto is OK if there are few variables to clean-up. If there is a large number of variables to clean up, it's better to zero-fill the whole structure and free the entries unconditionally (kfree does noting if it gets NULL) - see for example dm_integrity_ctr - it allocates the structure with kzalloc_obj and on any error it jumps to the label "bad" that calls dm_integrity_dtr - and dm_integrity_dtr frees all non-NULL entries. Mikulas > Regards, > Markus