dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: idxd: Fix error handling in idxd_wq_cdev_dev_setup()
@ 2020-02-05 12:32 Dan Carpenter
  2020-02-05 16:32 ` Dave Jiang
  2020-02-13 15:07 ` Vinod Koul
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-02-05 12:32 UTC (permalink / raw)
  To: Dave Jiang; +Cc: Vinod Koul, Dan Williams, dmaengine, kernel-janitors

We can't call kfree(dev) after calling device_register(dev).  The "dev"
pointer has to be freed using put_device().

Fixes: 42d279f9137a ("dmaengine: idxd: add char driver to expose submission portal to userland")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/dma/idxd/cdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
index 1d7347825b95..df47be612ebb 100644
--- a/drivers/dma/idxd/cdev.c
+++ b/drivers/dma/idxd/cdev.c
@@ -204,6 +204,7 @@ static int idxd_wq_cdev_dev_setup(struct idxd_wq *wq)
 	minor = ida_simple_get(&cdev_ctx->minor_ida, 0, MINORMASK, GFP_KERNEL);
 	if (minor < 0) {
 		rc = minor;
+		kfree(dev);
 		goto ida_err;
 	}
 
@@ -212,7 +213,6 @@ static int idxd_wq_cdev_dev_setup(struct idxd_wq *wq)
 	rc = device_register(dev);
 	if (rc < 0) {
 		dev_err(&idxd->pdev->dev, "device register failed\n");
-		put_device(dev);
 		goto dev_reg_err;
 	}
 	idxd_cdev->minor = minor;
@@ -221,8 +221,8 @@ static int idxd_wq_cdev_dev_setup(struct idxd_wq *wq)
 
  dev_reg_err:
 	ida_simple_remove(&cdev_ctx->minor_ida, MINOR(dev->devt));
+	put_device(dev);
  ida_err:
-	kfree(dev);
 	idxd_cdev->dev = NULL;
 	return rc;
 }
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] dmaengine: idxd: Fix error handling in idxd_wq_cdev_dev_setup()
  2020-02-05 12:32 [PATCH] dmaengine: idxd: Fix error handling in idxd_wq_cdev_dev_setup() Dan Carpenter
@ 2020-02-05 16:32 ` Dave Jiang
  2020-02-13 15:07 ` Vinod Koul
  1 sibling, 0 replies; 3+ messages in thread
From: Dave Jiang @ 2020-02-05 16:32 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Vinod Koul, Dan Williams, dmaengine, kernel-janitors



On 2/5/20 5:32 AM, Dan Carpenter wrote:
> We can't call kfree(dev) after calling device_register(dev).  The "dev"
> pointer has to be freed using put_device().
> 
> Fixes: 42d279f9137a ("dmaengine: idxd: add char driver to expose submission portal to userland")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Acked-by: Dave Jiang <dave.jiang@intel.com>

> ---
>   drivers/dma/idxd/cdev.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
> index 1d7347825b95..df47be612ebb 100644
> --- a/drivers/dma/idxd/cdev.c
> +++ b/drivers/dma/idxd/cdev.c
> @@ -204,6 +204,7 @@ static int idxd_wq_cdev_dev_setup(struct idxd_wq *wq)
>   	minor = ida_simple_get(&cdev_ctx->minor_ida, 0, MINORMASK, GFP_KERNEL);
>   	if (minor < 0) {
>   		rc = minor;
> +		kfree(dev);
>   		goto ida_err;
>   	}
>   
> @@ -212,7 +213,6 @@ static int idxd_wq_cdev_dev_setup(struct idxd_wq *wq)
>   	rc = device_register(dev);
>   	if (rc < 0) {
>   		dev_err(&idxd->pdev->dev, "device register failed\n");
> -		put_device(dev);
>   		goto dev_reg_err;
>   	}
>   	idxd_cdev->minor = minor;
> @@ -221,8 +221,8 @@ static int idxd_wq_cdev_dev_setup(struct idxd_wq *wq)
>   
>    dev_reg_err:
>   	ida_simple_remove(&cdev_ctx->minor_ida, MINOR(dev->devt));
> +	put_device(dev);
>    ida_err:
> -	kfree(dev);
>   	idxd_cdev->dev = NULL;
>   	return rc;
>   }
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] dmaengine: idxd: Fix error handling in idxd_wq_cdev_dev_setup()
  2020-02-05 12:32 [PATCH] dmaengine: idxd: Fix error handling in idxd_wq_cdev_dev_setup() Dan Carpenter
  2020-02-05 16:32 ` Dave Jiang
@ 2020-02-13 15:07 ` Vinod Koul
  1 sibling, 0 replies; 3+ messages in thread
From: Vinod Koul @ 2020-02-13 15:07 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Dave Jiang, Dan Williams, dmaengine, kernel-janitors

On 05-02-20, 15:32, Dan Carpenter wrote:
> We can't call kfree(dev) after calling device_register(dev).  The "dev"
> pointer has to be freed using put_device().

Applied, thanks

-- 
~Vinod

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-13 15:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-05 12:32 [PATCH] dmaengine: idxd: Fix error handling in idxd_wq_cdev_dev_setup() Dan Carpenter
2020-02-05 16:32 ` Dave Jiang
2020-02-13 15:07 ` Vinod Koul

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).