Re: [PATCH v2 11/28] binder: do unlocked work in binder_alloc_new_buf()

From: Carlos Llamas
Date: Mon Dec 04 2023 - 09:23:34 EST


On Mon, Dec 04, 2023 at 11:57:04AM +0000, 'Alice Ryhl' via kernel-team wrote:
> > Extract non-critical sections from binder_alloc_new_buf_locked() that
> > don't require holding the alloc->mutex. While we are here, consolidate
> > the checks for size overflow and zero-sized padding into a separate
> > sanitized_size() helper function.
> >
> > Also add a few touchups to follow the coding guidelines.
> >
> > Signed-off-by: Carlos Llamas <cmllamas@xxxxxxxxxx>
>
> Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
>
> > + if (IS_ERR(buffer)) {
> > + mutex_unlock(&alloc->mutex);
> > + goto out;
> > + }
> > +
> > + buffer->data_size = data_size;
> > + buffer->offsets_size = offsets_size;
> > + buffer->extra_buffers_size = extra_buffers_size;
> > mutex_unlock(&alloc->mutex);
> > +
> > +out:
> > return buffer;
> > }
>
> You could also write this as:
>
> if (!IS_ERR(buffer)) {
> buffer->data_size = data_size;
> buffer->offsets_size = offsets_size;
> buffer->extra_buffers_size = extra_buffers_size;
> }
>
> mutex_unlock(&alloc->mutex);
> return buffer;

There is a subsequent patch that adds more work after this and makes the
goto statement a better fit (patch 19/28)... at least IMO.

--
Carlos Llamas