From patchwork Wed Apr 29 12:00:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 6295601 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AB826BEEE1 for ; Wed, 29 Apr 2015 12:02:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9A0AE201BB for ; Wed, 29 Apr 2015 12:02:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 793EE2010E for ; Wed, 29 Apr 2015 12:02:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422835AbbD2MBo (ORCPT ); Wed, 29 Apr 2015 08:01:44 -0400 Received: from mail-lb0-f179.google.com ([209.85.217.179]:36023 "EHLO mail-lb0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422900AbbD2MAy (ORCPT ); Wed, 29 Apr 2015 08:00:54 -0400 Received: by lbbqq2 with SMTP id qq2so18191142lbb.3; Wed, 29 Apr 2015 05:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rYwr16xKbfY9JaRvcAMaSlHnJzKJC2VS3jhgwImi5ow=; b=zCXlg+iUZH+mBzb22IOh4w+t+ywjqnhOW3qj6tqAirZmfwcRwYln110HmkNCYgmGaM Qrd5jfOeEq+ou3ezmQWD6xaTgAe5dWRpU6MewPq8TSASUVQu/Gm4x1a8VIOZs0kVbZDY Bh4z1iFygVEk4VKh3qnNW5+AUBdVdnYqDuFb1iy4N3+h8zfAF1wnoAcR+mxT/2Mmq4MX 3to/Dz503ipn5bQw+XgKltxn5Fq+f3O+0791PUB94UMAvasrHATAAivPjzsYWAmaLdQH O1mb4NPjG/8d2DLdy5yGzn4kVRoWlUNvW439pkuYhFvhbx/0/lduF/LDOifWhWTY2Qve jB2w== X-Received: by 10.152.43.110 with SMTP id v14mr17743638lal.4.1430308852760; Wed, 29 Apr 2015 05:00:52 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by mx.google.com with ESMTPSA id lf12sm6290686lac.38.2015.04.29.05.00.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Apr 2015 05:00:51 -0700 (PDT) From: Ricardo Ribalda Delgado To: Hans Verkuil , Pawel Osciak , Marek Szyprowski , Kyungmin Park , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [RESEND PATCH v2 1/3] media/videobuf2-dma-sg: Fix handling of sg_table structure Date: Wed, 29 Apr 2015 14:00:45 +0200 Message-Id: <1430308847-32140-2-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1430308847-32140-1-git-send-email-ricardo.ribalda@gmail.com> References: <1430308847-32140-1-git-send-email-ricardo.ribalda@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ricardo Ribalda When sg_alloc_table_from_pages() does not fail it returns a sg_table structure with nents and nents_orig initialized to the same value. dma_map_sg returns the number of areas mapped by the hardware, which could be different than the areas given as an input. The output must be saved to nent. The output of dma_map, should be used to transverse the scatter list. dma_unmap_sg needs the value passed to dma_map_sg (nents_orig). sg_free_tables uses also orig_nent. This patch fix the file to follow this paradigm. Signed-off-by: Ricardo Ribalda Delgado Reviewed-by: Marek Szyprowski --- drivers/media/v4l2-core/videobuf2-dma-sg.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c b/drivers/media/v4l2-core/videobuf2-dma-sg.c index 45c708e463b9..7289b81bd7b7 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-sg.c +++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c @@ -147,8 +147,9 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, * No need to sync to the device, this will happen later when the * prepare() memop is called. */ - if (dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->nents, - buf->dma_dir, &attrs) == 0) + sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, + buf->dma_dir, &attrs); + if (!sgt->nents) goto fail_map; buf->handler.refcount = &buf->refcount; @@ -187,7 +188,7 @@ static void vb2_dma_sg_put(void *buf_priv) dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, &attrs); dprintk(1, "%s: Freeing buffer of %d pages\n", __func__, buf->num_pages); - dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->nents, + dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir, &attrs); if (buf->vaddr) vm_unmap_ram(buf->vaddr, buf->num_pages); @@ -314,9 +315,11 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr, * No need to sync to the device, this will happen later when the * prepare() memop is called. */ - if (dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->nents, - buf->dma_dir, &attrs) == 0) + sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, + buf->dma_dir, &attrs); + if (!sgt->nents) goto userptr_fail_map; + return buf; userptr_fail_map: @@ -351,7 +354,8 @@ static void vb2_dma_sg_put_userptr(void *buf_priv) dprintk(1, "%s: Releasing userspace buffer of %d pages\n", __func__, buf->num_pages); - dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir, &attrs); + dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir, + &attrs); if (buf->vaddr) vm_unmap_ram(buf->vaddr, buf->num_pages); sg_free_table(buf->dma_sgt); @@ -502,7 +506,6 @@ static struct sg_table *vb2_dma_sg_dmabuf_ops_map( /* stealing dmabuf mutex to serialize map/unmap operations */ struct mutex *lock = &db_attach->dmabuf->lock; struct sg_table *sgt; - int ret; mutex_lock(lock); @@ -521,8 +524,9 @@ static struct sg_table *vb2_dma_sg_dmabuf_ops_map( } /* mapping to the client with new direction */ - ret = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents, dma_dir); - if (ret <= 0) { + sgt->nents = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents, + dma_dir); + if (!sgt->nents) { pr_err("failed to map scatterlist\n"); mutex_unlock(lock); return ERR_PTR(-EIO);