[PATCH 11/33] drm/omap: use dma_mapping_error in omap_gem_attach_pages

Tomi Valkeinen tomi.valkeinen at ti.com
Thu Feb 25 15:39:35 UTC 2016


On 24/02/16 00:10, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Friday 19 February 2016 11:47:46 Tomi Valkeinen wrote:
>> omap_gem_attach_pages() calls dma_map_page() but does not check the
>> possible error with dma_mapping_error(). If DMA-API debugging is
>> enabled, the debug layer will give a warning if dma_mapping_error() has
>> not been used.
>>
>> This patch adds proper error handling to omap_gem_attach_pages().
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen at ti.com>
>> ---
>>  drivers/gpu/drm/omapdrm/omap_gem.c | 14 ++++++++++++++
>>  1 file changed, 14 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c
>> b/drivers/gpu/drm/omapdrm/omap_gem.c index 8495a1a4b617..7098190815f1
>> 100644
>> --- a/drivers/gpu/drm/omapdrm/omap_gem.c
>> +++ b/drivers/gpu/drm/omapdrm/omap_gem.c
>> @@ -264,6 +264,18 @@ static int omap_gem_attach_pages(struct drm_gem_object
>> *obj) for (i = 0; i < npages; i++) {
>>  			addrs[i] = dma_map_page(dev->dev, pages[i],
>>  					0, PAGE_SIZE, DMA_BIDIRECTIONAL);
>> +
>> +			if (dma_mapping_error(dev->dev, addrs[i])) {
>> +				dev_warn(dev->dev, "omap_gem_attach_pages: dma_map_page 
> failed\n");
> 
> Using dev_warn(dev->dev, "%s: failed to map page\n", __func__); and proper 
> line breaks you'll have no trouble complying with the 80 characters per line 
> limit :-)

Ok.

>> +
>> +				for (i = i - 1; i >= 0; --i) {
> 
> Maybe i-- instead of i = i - 1 ?

Hmm I don't know... I do like assignment in the initializer more than
i--. And why i--? Why not --i? =)

>> +					dma_unmap_page(dev->dev, addrs[i],
>> +						PAGE_SIZE, DMA_BIDIRECTIONAL);
>> +				}
>> +
>> +				ret = -ENOMEM;
>> +				goto free_addrs;
>> +			}
>>  		}
>>  	} else {
>>  		addrs = kzalloc(npages * sizeof(*addrs), GFP_KERNEL);
>> @@ -277,6 +289,8 @@ static int omap_gem_attach_pages(struct drm_gem_object
>> *obj) omap_obj->pages = pages;
>>
>>  	return 0;
>> +free_addrs:
>> +	kfree(addrs);
>>
> 
> I'd move this blank line before free_addrs.

Yes, that makes it cleaner.

 Tomi

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20160225/b78f6fe1/attachment.sig>


More information about the dri-devel mailing list