Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751589AbdCCIa1 (ORCPT ); Fri, 3 Mar 2017 03:30:27 -0500 Received: from out4435.biz.mail.alibaba.com ([47.88.44.35]:35656 "EHLO out4435.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751340AbdCCIa0 (ORCPT ); Fri, 3 Mar 2017 03:30:26 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R701e4;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e02c03268;MF=hillf.zj@alibaba-inc.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---.7kBLC1C_1488529107; Reply-To: "Hillf Danton" From: "Hillf Danton" To: "'Laura Abbott'" , "'Sumit Semwal'" , "'Riley Andrews'" , Cc: , , , , "'Greg Kroah-Hartman'" , , , , "'Brian Starkey'" , "'Daniel Vetter'" , "'Mark Brown'" , "'Benjamin Gaignard'" , References: <1488491084-17252-1-git-send-email-labbott@redhat.com> <1488491084-17252-4-git-send-email-labbott@redhat.com> In-Reply-To: <1488491084-17252-4-git-send-email-labbott@redhat.com> Subject: Re: [RFC PATCH 03/12] staging: android: ion: Duplicate sg_table Date: Fri, 03 Mar 2017 16:18:27 +0800 Message-ID: <07df01d293f6$bcfb4f30$36f1ed90$@alibaba-inc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQL5c0GH+hXrLljoxQpg+F75EQX0QAKr4BhQnx+k1EA= Content-Language: zh-cn Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 751 Lines: 35 On March 03, 2017 5:45 AM Laura Abbott wrote: > > +static struct sg_table *dup_sg_table(struct sg_table *table) > +{ > + struct sg_table *new_table; > + int ret, i; > + struct scatterlist *sg, *new_sg; > + > + new_table = kzalloc(sizeof(*new_table), GFP_KERNEL); > + if (!new_table) > + return ERR_PTR(-ENOMEM); > + > + ret = sg_alloc_table(new_table, table->nents, GFP_KERNEL); > + if (ret) { > + kfree(table); Free new table? > + return ERR_PTR(-ENOMEM); > + } > + > + new_sg = new_table->sgl; > + for_each_sg(table->sgl, sg, table->nents, i) { > + memcpy(new_sg, sg, sizeof(*sg)); > + sg->dma_address = 0; > + new_sg = sg_next(new_sg); > + } > + Do we need a helper, sg_copy_table(dst_table, src_table)? > + return new_table; > +} > +