Re: [RFC][PATCH 2/5 v2] dma-buf: heaps: Add heap helpers
From: Andrew F. Davis
Date: Thu Mar 21 2019 - 16:35:24 EST
On 3/19/19 9:26 AM, Brian Starkey wrote:
> Hi John,
>
> On Tue, Mar 05, 2019 at 12:54:30PM -0800, John Stultz wrote:
>
> ...
>
>> +
>> +void dma_heap_buffer_destroy(struct dma_heap_buffer *heap_buffer)
>> +{
>> + struct heap_helper_buffer *buffer = to_helper_buffer(heap_buffer);
>> +
>> + if (buffer->kmap_cnt > 0) {
>> + pr_warn_once("%s: buffer still mapped in the kernel\n",
>> + __func__);
>
> Could be worth something louder like a full WARN.
>
>> + vunmap(buffer->vaddr);
>> + }
>> +
>> + buffer->free(buffer);
>> +}
>> +
>
> ...
>
>> +
>> +static void *dma_heap_dma_buf_kmap(struct dma_buf *dmabuf,
>> + unsigned long offset)
>> +{
>> + struct dma_heap_buffer *heap_buffer = dmabuf->priv;
>> + struct heap_helper_buffer *buffer = to_helper_buffer(heap_buffer);
>> +
>> + return buffer->vaddr + offset * PAGE_SIZE;
>
> I think it'd be good to check for NULL vaddr and return NULL in that
> case. Less chance of an invalid pointer being accidentally used then.
>
Why do we assume vaddr is set at all here? I'm guessing we expected
dma_heap_map_kernel to have been called, that is not going to always be
the case. kmap should perform it's own single page kmap here and not
rely on the clunky full buffer vmap (which is probably broken on 32bit
systems here when the buffers are large).
Andrew
> Thanks,
> -Brian
>