From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-renesas-soc@vger.kernel.org, linux-iio@vger.kernel.org,
linux-input@vger.kernel.org, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org
Subject: Re: [RFC PATCH v5 2/6] i2c: add helpers to ease DMA handling
Date: Thu, 21 Sep 2017 15:36:29 +0100 [thread overview]
Message-ID: <20170921153629.00001aae@huawei.com> (raw)
In-Reply-To: <20170921141528.xre53zpxwk355uih@ninjato>
On Thu, 21 Sep 2017 16:15:28 +0200
Wolfram Sang <wsa@the-dreams.de> 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
>
>
next prev parent reply other threads:[~2017-09-21 14:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-20 18:59 [RFC PATCH v5 0/6] i2c: document DMA handling and add helpers for it Wolfram Sang
2017-09-20 18:59 ` [RFC PATCH v5 1/6] i2c: add a message flag for DMA safe buffers Wolfram Sang
2017-09-20 18:59 ` [RFC PATCH v5 2/6] i2c: add helpers to ease DMA handling Wolfram Sang
2017-09-21 13:59 ` Jonathan Cameron
[not found] ` <20170921145922.000017b5-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2017-09-21 14:05 ` Jonathan Cameron
2017-09-21 14:15 ` Wolfram Sang
2017-09-21 14:36 ` Jonathan Cameron [this message]
2017-09-20 18:59 ` [RFC PATCH v5 3/6] i2c: add docs to clarify " Wolfram Sang
2017-09-20 19:56 ` Mauro Carvalho Chehab
2017-09-21 14:08 ` Jonathan Cameron
2017-09-20 18:59 ` [RFC PATCH v5 4/6] i2c: sh_mobile: use helper to decide if DMA is useful Wolfram Sang
2017-09-20 18:59 ` [RFC PATCH v5 5/6] i2c: rcar: skip DMA if buffer is not safe Wolfram Sang
2017-09-20 18:59 ` [RFC PATCH v5 6/6] i2c: dev: mark RDWR buffers as DMA_SAFE Wolfram Sang
2017-09-21 14:17 ` Jonathan Cameron
2017-09-21 14:23 ` Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170921153629.00001aae@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=wsa+renesas@sang-engineering.com \
--cc=wsa@the-dreams.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).