mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Sverdlin <alexander.sverdlin@nokia.com>
To: Ioan Nicu <ioan.nicu.ext@nokia.com>,
	Alexandre Bounine <alex.bou9@gmail.com>,
	Barry Wood <barry.wood@idt.com>,
	Matt Porter <mporter@kernel.crashing.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Logan Gunthorpe <logang@deltatee.com>,
	Chris Wilson <chris@chris-wilson.co.uk>,
	Tvrtko Ursulin <tvrtko.ursulin@intel.com>,
	Frank Kunz <frank.kunz@nokia.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] rapidio: fix rio_dma_transfer error handling
Date: Thu, 12 Apr 2018 17:08:40 +0200	[thread overview]
Message-ID: <307953c3-6f41-2e2c-eba5-5dcd2fb5e1b4@nokia.com> (raw)
In-Reply-To: <20180412150605.GA31409@nokia.com>

On 12/04/18 17:06, Ioan Nicu wrote:
> Some of the mport_dma_req structure members were initialized late
> inside the do_dma_request() function, just before submitting the
> request to the dma engine. But we have some error branches before
> that. In case of such an error, the code would return on the error
> path and trigger the calling of dma_req_free() with a req structure
> which is not completely initialized. This causes a NULL pointer
> dereference in dma_req_free().
> 
> This patch fixes these error branches by making sure that all
> necessary mport_dma_req structure members are initialized in
> rio_dma_transfer() immediately after the request structure gets
> allocated.
> 
> Signed-off-by: Ioan Nicu <ioan.nicu.ext@nokia.com>

Tested-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>

> ---
>  drivers/rapidio/devices/rio_mport_cdev.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
> index 9d27016c899e..0434ab7b6497 100644
> --- a/drivers/rapidio/devices/rio_mport_cdev.c
> +++ b/drivers/rapidio/devices/rio_mport_cdev.c
> @@ -740,10 +740,7 @@ static int do_dma_request(struct mport_dma_req *req,
>  	tx->callback = dma_xfer_callback;
>  	tx->callback_param = req;
>  
> -	req->dmach = chan;
> -	req->sync = sync;
>  	req->status = DMA_IN_PROGRESS;
> -	init_completion(&req->req_comp);
>  	kref_get(&req->refcount);
>  
>  	cookie = dmaengine_submit(tx);
> @@ -831,13 +828,20 @@ rio_dma_transfer(struct file *filp, u32 transfer_mode,
>  	if (!req)
>  		return -ENOMEM;
>  
> -	kref_init(&req->refcount);
> -
>  	ret = get_dma_channel(priv);
>  	if (ret) {
>  		kfree(req);
>  		return ret;
>  	}
> +	chan = priv->dmach;
> +
> +	kref_init(&req->refcount);
> +	init_completion(&req->req_comp);
> +	req->dir = dir;
> +	req->filp = filp;
> +	req->priv = priv;
> +	req->dmach = chan;
> +	req->sync = sync;
>  
>  	/*
>  	 * If parameter loc_addr != NULL, we are transferring data from/to
> @@ -925,11 +929,6 @@ rio_dma_transfer(struct file *filp, u32 transfer_mode,
>  				xfer->offset, xfer->length);
>  	}
>  
> -	req->dir = dir;
> -	req->filp = filp;
> -	req->priv = priv;
> -	chan = priv->dmach;
> -
>  	nents = dma_map_sg(chan->device->dev,
>  			   req->sgt.sgl, req->sgt.nents, dir);
>  	if (nents == 0) {

-- 
Best regards,
Alexander Sverdlin.

  reply	other threads:[~2018-04-12 15:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-12 15:06 Ioan Nicu
2018-04-12 15:08 ` Alexander Sverdlin [this message]
2018-04-12 18:47 ` Alexandre Bounine
2018-04-12 21:28 ` Andrew Morton
2018-04-12 23:44   ` Alexandre Bounine
2018-04-13  7:09     ` Ioan Nicu
2018-04-13 21:16       ` Andrew Morton

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=307953c3-6f41-2e2c-eba5-5dcd2fb5e1b4@nokia.com \
    --to=alexander.sverdlin@nokia.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.bou9@gmail.com \
    --cc=barry.wood@idt.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=frank.kunz@nokia.com \
    --cc=ioan.nicu.ext@nokia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=logang@deltatee.com \
    --cc=mporter@kernel.crashing.org \
    --cc=tvrtko.ursulin@intel.com \
    --cc=viro@zeniv.linux.org.uk \
    /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

Powered by JetHome