Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1736701

Re: [RFC PATCH v5 2/6] i2c: add helpers to ease DMA handling

From Wolfram Sang <wsa@the-dreams.de>
Newsgroups linux.kernel
Subject Re: [RFC PATCH v5 2/6] i2c: add helpers to ease DMA handling
Date 2017-09-21 16:20 +0200
Message-ID <usauC-25s-9@gated-at.bofh.it> (permalink)
References <urSxH-79x-7@gated-at.bofh.it> <urSxH-79x-13@gated-at.bofh.it> <usakV-21y-3@gated-at.bofh.it> <usakV-21y-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

> > > +/**
> > > + * 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!

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC PATCH v5 0/6] i2c: document DMA handling and add helpers for it Wolfram Sang <wsa+renesas@sang-engineering.com> - 2017-09-20 21:10 +0200
  [RFC PATCH v5 4/6] i2c: sh_mobile: use helper to decide if DMA is useful Wolfram Sang <wsa+renesas@sang-engineering.com> - 2017-09-20 21:10 +0200
  [RFC PATCH v5 2/6] i2c: add helpers to ease DMA handling Wolfram Sang <wsa+renesas@sang-engineering.com> - 2017-09-20 21:10 +0200
    Re: [RFC PATCH v5 2/6] i2c: add helpers to ease DMA handling Jonathan Cameron <Jonathan.Cameron@huawei.com> - 2017-09-21 16:10 +0200
      Re: [RFC PATCH v5 2/6] i2c: add helpers to ease DMA handling Jonathan Cameron <Jonathan.Cameron@huawei.com> - 2017-09-21 16:10 +0200
        Re: [RFC PATCH v5 2/6] i2c: add helpers to ease DMA handling Wolfram Sang <wsa@the-dreams.de> - 2017-09-21 16:20 +0200
          Re: [RFC PATCH v5 2/6] i2c: add helpers to ease DMA handling Jonathan Cameron <Jonathan.Cameron@huawei.com> - 2017-09-21 16:40 +0200
  [RFC PATCH v5 5/6] i2c: rcar: skip DMA if buffer is not safe Wolfram Sang <wsa+renesas@sang-engineering.com> - 2017-09-20 21:10 +0200
  [RFC PATCH v5 1/6] i2c: add a message flag for DMA safe buffers Wolfram Sang <wsa+renesas@sang-engineering.com> - 2017-09-20 21:10 +0200
  [RFC PATCH v5 3/6] i2c: add docs to clarify DMA handling Wolfram Sang <wsa+renesas@sang-engineering.com> - 2017-09-20 21:10 +0200
    Re: [RFC PATCH v5 3/6] i2c: add docs to clarify DMA handling Mauro Carvalho Chehab <mchehab@s-opensource.com> - 2017-09-20 22:00 +0200
      Re: [RFC PATCH v5 3/6] i2c: add docs to clarify DMA handling Jonathan Cameron <Jonathan.Cameron@huawei.com> - 2017-09-21 16:10 +0200

csiph-web