Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751918AbcCIAPt (ORCPT ); Tue, 8 Mar 2016 19:15:49 -0500 Received: from LGEAMRELO11.lge.com ([156.147.23.51]:44161 "EHLO lgeamrelo11.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750888AbcCIAPk (ORCPT ); Tue, 8 Mar 2016 19:15:40 -0500 X-Original-SENDERIP: 156.147.1.126 X-Original-MAILFROM: chanho.min@lge.com X-Original-SENDERIP: 165.244.98.204 X-Original-MAILFROM: chanho.min@lge.com X-Original-SENDERIP: 10.178.32.160 X-Original-MAILFROM: chanho.min@lge.com From: Chanho Min To: "'Russell King - ARM Linux'" CC: "'Greg Kroah-Hartman'" , "'Jiri Slaby'" , , , "'Jongsung Kim'" , "'Gunho Lee'" References: <1457405016-23562-1-git-send-email-chanho.min@lge.com> <20160308095907.GM19428@n2100.arm.linux.org.uk> In-Reply-To: <20160308095907.GM19428@n2100.arm.linux.org.uk> Subject: RE: [PATCH] tty: amba-pl011: use sg_table instead of scatterlist Date: Wed, 9 Mar 2016 09:15:36 +0900 Message-ID: <05b701d17998$cdd9adc0$698d0940$@lge.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQGveVBnL+ICRdh1k3ovb2Y1fga2tgI31ML4n4J8aFA= X-MIMETrack: Itemize by SMTP Server on LGEKRMHUB08/LGE/LG Group(Release 8.5.3FP6|November 21, 2013) at 2016/03/09 09:15:36, Serialize by Router on LGEKRMHUB08/LGE/LG Group(Release 8.5.3FP6|November 21, 2013) at 2016/03/09 09:15:36, Serialize complete at 2016/03/09 09:15:36 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii" Content-Language: ko Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1509 Lines: 46 > > @@ -344,17 +344,23 @@ static int pl011_sgbuf_init(struct dma_chan *chan, > struct pl011_sgbuf *sg, > > enum dma_data_direction dir) > > { > > dma_addr_t dma_addr; > > + int ret; > > > > sg->buf = dma_alloc_coherent(chan->device->dev, > > PL011_DMA_BUFFER_SIZE, &dma_addr, GFP_KERNEL); > > if (!sg->buf) > > return -ENOMEM; > > sg->buf can be a mapped address, which virt_to_page() will return > sg->invalid > results: > > int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, > void *cpu_addr, dma_addr_t handle, size_t size) { > struct page *page = virt_to_page(cpu_addr); > int ret; > > ret = sg_alloc_table(sgt, 1, GFP_KERNEL); > if (unlikely(ret)) > return ret; > > sg_set_page(sgt->sgl, page, PAGE_ALIGN(size), 0); > return 0; > } > EXPORT_SYMBOL(dma_common_get_sgtable); > > I've no idea who is shoveling crap like this into the kernel, but it's > _really_ far from good that such broken abstractions are being merged as > generic code. dma_get_sgtable goes to ops->get_sgtable first, which dma_to_pfn will return valid address. IMHO, Only If ops->alloc returns direct mapping address, dma_common_get_sgtable can be used. int arm_dma_get_sgtable(struct device *dev, struct sg_table *sgt, void *cpu_addr, dma_addr_t handle, size_t size, struct dma_attrs *attrs) { struct page *page = pfn_to_page(dma_to_pfn(dev, handle)); int ret;