|
|
|
|
|
by Jtsummers
1592 days ago
|
|
The use of goto out (or similar) is idiomatic in a lot of kernel code. Since C has no notion of defer (like Go) or a finally block (like languages with exceptions), you place the code you want to always execute at the end, and then goto out instead of returning earlier. The other option, in functions like this, is to have duplicated "deferred" execution scattered throughout the function at each return point. This is a maintenance nightmare as it can be hard to discern which code is actually part of the "deferred" block (and needs to be copied) and which isn't, at least at a glance. So differences in two return points are clues that something may be wrong, but requires further investigation to determine if they should or should not be the same. As a function grows in size, this becomes increasingly problematic. It's actually a good demonstration of DRY. |
|