Messages in this thread | | | From | Bartosz Golaszewski <> | Date | Wed, 30 Aug 2023 13:48:39 +0200 | Subject | Re: [GIT PULL] gpio: updates for v6.6 |
| |
On Tue, Aug 29, 2023 at 10:29 PM Linus Torvalds <torvalds@linux-foundation.org> wrote: > > On Tue, 29 Aug 2023 at 04:43, Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > > > Driver improvements: > > - use autopointers and guards from cleanup.h in gpio-sim > > So I've pulled this, but I'm not entirely convinced some of this was a cleanup. > > That gpio_sim_config_make_device_group() change is "interesting". Doing > > return &no_free_ptr(dev)->group; > > looks a bit crazy. My first reaction to it was 'that can't be right". > It _is_ right, but I'm not convinced that getting rid of one kfree() > call in the error path above it is worth that kind of semantic > complexity. > > I guess we'll get more used to this - and it will look a bit less > crazy in the process - but I did want to just note that I'm not > entirely convinced we should encourage things like this. > > Linus
I on the other hand absolutely love SBRM in C. I have been using autopointers a lot in user-space when coding in GLib/GObject and it quickly becomes second nature with no_free_ptr() not being much different from g_steal_pointer(). It's an even better pattern when used with reference counted objects where the cleanup function just drops the reference so you can do a less "crazy" return object_ref(obj);
Maybe this particular example doesn't save a lot of code but I think it's worth using SBRM consistently across a given file, otherwise mixing both styles will lead to an unreadable mess.
Bartosz
| |