All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sowjanya Komatineni <skomatineni@nvidia.com>
To: Dmitry Osipenko <digetx@gmail.com>,
	"thierry.reding@gmail.com" <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Mantravadi Karthik <mkarthik@nvidia.com>,
	Shardar Mohammed <smohammed@nvidia.com>,
	Timo Alho <talho@nvidia.com>
Cc: "linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>
Subject: RE: [PATCH V9 3/5] i2c: tegra: Add DMA support
Date: Fri, 1 Feb 2019 21:36:41 +0000	[thread overview]
Message-ID: <BYAPR12MB339835E59C2D4DCDFC93BEF4C2920@BYAPR12MB3398.namprd12.prod.outlook.com> (raw)
In-Reply-To: <f0c4cc1b-4e3d-3956-7ac4-de35073fbf94@gmail.com>


> > 
> >> 	rx_chan = dma_request_slave_channel_reason(i2c_dev->dev, "rx");
> >> 	if (IS_ERR(rx_chan))
> >> 		return PTR_ERR(rx_chan); 
> >>
> >>
> >>> +
> >>> +	dma_chan = dma_request_slave_channel_reason(i2c_dev->dev, "tx");
> >>> +	if (IS_ERR(dma_chan)) {
> >>> +		err = PTR_ERR(dma_chan);
> >>> +		goto error;
> >>
> >> It's a good practice to release resources in opposite order to the allocation. Hence better to write this as:
> >>
> >> 		goto err_release_rx;
> >>
> >>> +	}
> >>> +
> >>> +	i2c_dev->tx_dma_chan = dma_chan;
> >>> +
> >>> +	dma_buf = dma_alloc_coherent(i2c_dev->dev,
> >>> +				     i2c_dev->dma_buf_size, &dma_phys,
> >>> +				     GFP_KERNEL | __GFP_NOWARN);
> >>> +
> >>> +	if (!dma_buf) {
> >>> +		dev_err(i2c_dev->dev, "failed to allocate the DMA buffer\n");
> >>> +		err = -ENOMEM;
> >>> +		goto error;
> >>
> >> 		goto err_release_tx;
> >>
> >>> +	}
> >>> +
> >>> +	i2c_dev->dma_buf = dma_buf;
> >>> +	i2c_dev->dma_phys = dma_phys;	
>
>	i2c_dev->rx_dma_chan = rx_chan;
> >> 	i2c_dev->tx_dma_chan = tx_chan;
> >>
> >>> +	return 0;
> >>> +
> >>> +error:
> >>> +	if (i2c_dev->tx_dma_chan)
> >>> +		dma_release_channel(i2c_dev->tx_dma_chan);
> >>> +
> >>> +	if (i2c_dev->rx_dma_chan)
> >>> +		dma_release_channel(i2c_dev->rx_dma_chan); 
> >>
> >> error_release_tx:
> >> 	dma_release_channel(tx_chan);
> >> error_release_rx:
> >> 	dma_release_channel(rx_chan);
> >>
> >>> +
> >>> +	return err;
> > 
> > I am releasing resources in reverse order to allocation.
> > Trying for rx allocation followed by tx allocation During release 
> > releasing tx and then rx.
> > In case if tx allocation fails, doesn’t go thru release. If rx or buf 
> > allocation fails, releases tx first and then rx
> > 
>
>
> Okay. Anyway it's a good-n-common practice to write it in the way I'm suggesting.
>
> And please set rx_chan and tx_chan after dma_buf allocation as I'm suggesting because you current variant will crash kernel since if dma_buf allocation fails, both rx and tx channels will be released and you're not setting them to NULL in that case.

OK, my wrong assumption. Thought dma_release_channel will NULL chan after its freed
Will update and send V10

  reply	other threads:[~2019-02-01 21:36 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-01 17:07 [PATCH V9 1/5] i2c: tegra: sort all the include headers alphabetically Sowjanya Komatineni
2019-02-01 17:07 ` Sowjanya Komatineni
2019-02-01 17:07 ` [PATCH V9 2/5] i2c: tegra: add bus clear master support Sowjanya Komatineni
2019-02-01 17:07   ` Sowjanya Komatineni
2019-02-01 19:06   ` Dmitry Osipenko
2019-02-01 17:07 ` [PATCH V9 3/5] i2c: tegra: Add DMA support Sowjanya Komatineni
2019-02-01 17:07   ` Sowjanya Komatineni
2019-02-01 18:57   ` Dmitry Osipenko
2019-02-01 19:20     ` Sowjanya Komatineni
2019-02-01 19:22       ` Dmitry Osipenko
2019-02-02 14:13         ` Dmitry Osipenko
2019-02-02 18:43           ` Sowjanya Komatineni
2019-02-03 16:42             ` Dmitry Osipenko
2019-02-01 20:21     ` Sowjanya Komatineni
2019-02-01 20:30       ` Dmitry Osipenko
2019-02-01 21:36         ` Sowjanya Komatineni [this message]
2019-02-01 21:45           ` Dmitry Osipenko
2019-02-02 14:01   ` Dmitry Osipenko
2019-02-02 18:32     ` Sowjanya Komatineni
2019-02-03 16:48       ` Dmitry Osipenko
2019-02-04  8:18         ` Thierry Reding
2019-02-03 14:19   ` Dmitry Osipenko
2019-02-03 14:47   ` Dmitry Osipenko
2019-02-03 15:27     ` Dmitry Osipenko
2019-02-04 12:57     ` Dmitry Osipenko
2019-02-05  1:37       ` Sowjanya Komatineni
2019-02-05  6:20         ` Dmitry Osipenko
2019-02-04  8:04   ` Thierry Reding
2019-02-01 17:07 ` [PATCH V9 4/5] i2c: tegra: update transfer timeout Sowjanya Komatineni
2019-02-01 17:07   ` Sowjanya Komatineni
2019-02-01 19:16   ` Dmitry Osipenko
2019-02-01 19:37     ` Sowjanya Komatineni
2019-02-01 19:41       ` Dmitry Osipenko
2019-02-04  7:54       ` Thierry Reding
2019-02-01 17:07 ` [PATCH V9 5/5] i2c: tegra: add i2c interface timing support Sowjanya Komatineni
2019-02-01 17:07   ` Sowjanya Komatineni
2019-02-01 19:05 ` [PATCH V9 1/5] i2c: tegra: sort all the include headers alphabetically Dmitry Osipenko

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=BYAPR12MB339835E59C2D4DCDFC93BEF4C2920@BYAPR12MB3398.namprd12.prod.outlook.com \
    --to=skomatineni@nvidia.com \
    --cc=digetx@gmail.com \
    --cc=jonathanh@nvidia.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mkarthik@nvidia.com \
    --cc=smohammed@nvidia.com \
    --cc=talho@nvidia.com \
    --cc=thierry.reding@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.