Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752128AbbBKJAv (ORCPT ); Wed, 11 Feb 2015 04:00:51 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:10140 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751363AbbBKJAs (ORCPT ); Wed, 11 Feb 2015 04:00:48 -0500 X-AuditID: cbfec7f4-b7f126d000001e9a-9c-54db19aca08c Message-id: <54DB1A3C.3050207@samsung.com> Date: Wed, 11 Feb 2015 10:00:44 +0100 From: Marek Szyprowski User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-version: 1.0 To: Ricardo Ribalda Delgado Cc: Hans Verkuil , Pawel Osciak , Kyungmin Park , Mauro Carvalho Chehab , linux-media , LKML Subject: Re: [PATCH 1/3] media/videobuf2-dma-sg: Fix handling of sg_table structure References: <1423498466-16718-1-git-send-email-ricardo.ribalda@gmail.com> <54DB0D84.7020600@samsung.com> In-reply-to: Content-type: text/plain; charset=utf-8; format=flowed Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCLMWRmVeSWpSXmKPExsVy+t/xK7prJG+HGHTelbBY8nMXk8XZpjfs Fpd3zWGz6NmwldVi9bMKiylvf7JbdHXPY3Jg95jyeyOrx85Zd9k9Hv96yeaxpR/I6tuyitHj 8ya5ALYoLpuU1JzMstQifbsEroyti7ewFewQrdg3v4upgfGZQBcjJ4eEgInE3+dvWCBsMYkL 99azdTFycQgJLGWUODphMyOE84lR4te9V4wgVbwCWhILJ09iBbFZBFQlJvZMYQex2QQMJbre drGB2KICMRLvVvUxQ9QLSvyYfA9sg4iAucTlD51gG5gF/jBKXLvxAKxZWCBU4v3vu0wQ2zYy SvSd2M8EkuAUCJZ4enoSmM0sYCbx5eVhVghbXmLzmrfMExgFZiFZMgtJ2SwkZQsYmVcxiqaW JhcUJ6XnGuoVJ+YWl+al6yXn525ihIT8lx2Mi49ZHWIU4GBU4uENmHAzRIg1say4MvcQowQH s5IIb4TY7RAh3pTEyqrUovz4otKc1OJDjEwcnFINjDWruls+3DN/c/CIqeofjWUSJQFbp7Go 8wT+ZxS3eTRD8MUdiRQNke+1Kyoi2OUb62OD7jsZ3bBVUj6qEMq2s8Rl897DrGL8fwItneYb zDlZJX5QqF2P803MdO9DHm7Sh5aY2NUIreSprXu1T/GpaPKx16s41ed/+GgTsVd93oIdGSsc tnj5K7EUZyQaajEXFScCAM3XqzBXAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2911 Lines: 83 Hello, On 2015-02-11 09:37, Ricardo Ribalda Delgado wrote: > Hello Marek > On Wed, Feb 11, 2015 at 9:06 AM, Marek Szyprowski > wrote: >>> Unfortunately nent differs in sign to the output of dma_map_sg, so an >>> intermediate value must be used. >> >> I don't get this part. dma_map_sg() returns the number of scatter list >> entries mapped >> to the hardware or zero if anything fails. What is the problem of assigning >> it directly >> to nents? > Are you sure about that? > > The prototype of the function is (from dma-mapping-common.h) > static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg, > int nents, enum dma_data_direction dir, > struct dma_attrs *attrs) > > which calls map_sg at the struct dma_map_ops (dma-mapping.h) > > int (*map_sg)(struct device *dev, struct scatterlist *sg, > int nents, enum dma_data_direction dir, > struct dma_attrs *attrs); > > Both return int instead of unsigned int.... Well, this int return value seems to be misleading, but according to Documentation/DMA-API.txt, the only error value is zero: "As with the other mapping interfaces, dma_map_sg() can fail. When it does, 0 is returned and a driver must take appropriate action. It is critical that the driver do something, in the case of a block driver aborting the request or even oopsing is better than doing nothing and corrupting the filesystem." I've also checked various dma-mapping implementation for different architectures and they follow this convention. Maybe one should add some comments to include/linux/dma_mapping.h to clarify this and avoid further confusion. > >> dma_map_sg_attrs() return 0 in case of error, so the check can be >> simplified, >> there is no need for temporary variable. > Check last comment > >>> vm_unmap_ram(buf->vaddr, buf->num_pages); >>> sg_free_table(buf->dma_sgt); >>> @@ -463,7 +470,7 @@ static int vb2_dma_sg_dmabuf_ops_attach(struct dma_buf >>> *dbuf, struct device *dev >>> rd = buf->dma_sgt->sgl; >>> wr = sgt->sgl; >>> - for (i = 0; i < sgt->orig_nents; ++i) { >>> + for (i = 0; i < sgt->nents; ++i) { >> >> Here the code iterates over every memory page in the scatter list (to create >> a copy of it), not the device mapped chunks, so it must use orig_nents >> like it was already there. > At that point both have the same value, but you are right, it is more > clear to use orig_nents > > > > I will resend a version using orig_nents in dmabug_ops attach, but > please take a look the map_sg, I think it can return <0 > > Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/