lkml.org 
[lkml]   [2019]   [Mar]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [RFC][PATCH 2/5 v2] dma-buf: heaps: Add heap helpers
On Fri, Mar 15, 2019 at 2:06 AM Christoph Hellwig <hch@infradead.org> wrote:
> > + if (buffer->kmap_cnt) {
> > + buffer->kmap_cnt++;
> > + return buffer->vaddr;
> > + }
> > + vaddr = dma_heap_map_kernel(buffer);
> > + if (WARN_ONCE(!vaddr,
> > + "heap->ops->map_kernel should return ERR_PTR on error"))
> > + return ERR_PTR(-EINVAL);
> > + if (IS_ERR(vaddr))
> > + return vaddr;
> > + buffer->vaddr = vaddr;
> > + buffer->kmap_cnt++;
>
> The cnt manioulation is odd. The normal way to make this readable
> is to use a postfix op on the check, as that makes it clear to everyone,
> e.g.:
>
> if (buffer->kmap_cnt++)
> return buffer->vaddr;
> ..

Thanks again on the feedback, I have had some other distractions
recently, so just getting around to these details again now.

The trouble w/ the suggestion here, if we increment in the check, then
if we trip on any of the other error paths, the cnt value will be
wrong when we return (and doing the extra decrementing in the error
paths feels as ugly as just doing the increment at the end of the
success paths)

> > + buffer->kmap_cnt--;
> > + if (!buffer->kmap_cnt) {
> > + vunmap(buffer->vaddr);
> > + buffer->vaddr = NULL;
> > + }
>
> Same here, just with an infix.
>
> > +static inline void INIT_HEAP_HELPER_BUFFER(struct heap_helper_buffer *buffer,
> > + void (*free)(struct heap_helper_buffer *))
> > +{
> > + buffer->private_flags = 0;
> > + buffer->priv_virt = NULL;
> > + mutex_init(&buffer->lock);
> > + buffer->kmap_cnt = 0;
> > + buffer->vaddr = NULL;
> > + buffer->sg_table = NULL;
> > + INIT_LIST_HEAD(&buffer->attachments);
> > + buffer->free = free;
> > +}
>
> There is absolutely no reason to inlines this as far as I can tell.

Yea, I think I was mimicing some of the helpers like INIT_LIST_HEAD()
But sounds good. I can uninline it.

> Also it would seem much simpler to simply let the caller assign the
> free callback.

Yea, its a bit ugly but I worry the caller might forget?

Thanks again for the feedback!
-john

\
 
 \ /
  Last update: 2019-03-21 21:02    [W:0.125 / U:32.228 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site