Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751992AbdIUOgy (ORCPT ); Thu, 21 Sep 2017 10:36:54 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:6537 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751929AbdIUOgu (ORCPT ); Thu, 21 Sep 2017 10:36:50 -0400 Date: Thu, 21 Sep 2017 15:36:29 +0100 From: Jonathan Cameron To: Wolfram Sang CC: Wolfram Sang , , , , , , , Subject: Re: [RFC PATCH v5 2/6] i2c: add helpers to ease DMA handling Message-ID: <20170921153629.00001aae@huawei.com> In-Reply-To: <20170921141528.xre53zpxwk355uih@ninjato> References: <20170920185956.13874-1-wsa+renesas@sang-engineering.com> <20170920185956.13874-3-wsa+renesas@sang-engineering.com> <20170921145922.000017b5@huawei.com> <20170921150554.0000273b@huawei.com> <20170921141528.xre53zpxwk355uih@ninjato> Organization: Huawei X-Mailer: Claws Mail 3.15.0 (GTK+ 2.24.31; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.206.48.115] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090203.59C3CE7A.00F0,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 0d889656e168e946c9b26c0fee6159d8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1338 Lines: 40 On Thu, 21 Sep 2017 16:15:28 +0200 Wolfram Sang wrote: > > > > +/** > > > > + * i2c_release_dma_safe_msg_buf - release DMA safe buffer and sync with i2c_msg > > > > + * @msg: the message to be synced with > > > > + * @buf: the buffer obtained from i2c_get_dma_safe_msg_buf(). May be NULL. > > > > + */ > > > > +void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf) > > > > +{ > > > > + if (!buf || buf == msg->buf) > > > > + return; > > > > + > > > > + if (msg->flags & I2C_M_RD) > > > > + memcpy(msg->buf, buf, msg->len); > > > > + > > > > + kfree(buf); > > > > Only free when you actually allocated it. Seems to me like you need > > to check if (!(msg->flags & I2C_M_DMA_SAFE)) before kfree. > > > > Otherwise the logic to do this will be needed in every driver > > which will get irritating fast. > > Well, I return early if (buf == msg->buf) which is only true for > I2C_M_DMA_SAFE. If not, I allocated the buffer. Am I missing something? > It would be very strange to call this function if the caller allocated > the buffer manually. > > Thanks for the review! Doh missed that check and my comment was bonkers even if it hadn't been there. I come back to the claim of insufficient caffeine. You are quite correct. Please ignore previous comment - the code is fine as is. Jonathan > >