diff mbox series

dmaengine: idxd: Fix a possible NULL pointer dereference

Message ID 77f0dc4f3966591d1f0cffb614a94085f8895a85.1627560174.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State Accepted
Commit e9c5b0b53ccca81dd0a35c62309e243a57c7959d
Headers show
Series dmaengine: idxd: Fix a possible NULL pointer dereference | expand

Commit Message

Christophe JAILLET July 29, 2021, 12:04 p.m. UTC
'device_driver_attach()' dereferences its first argument (i.e. 'alt_drv')
so it must not be NULL.
Simplify the error handling logic about NULL 'alt_drv' in order to be
more robust and future-proof.

Fixes: 568b2126466f ("dmaengine: idxd: fix uninit var for alt_drv")
Fixes: 6e7f3ee97bbe ("dmaengine: idxd: move dsa_drv support to compatible mode")

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/dma/idxd/compat.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

Comments

Dave Jiang July 29, 2021, 4:12 p.m. UTC | #1
On 7/29/2021 5:04 AM, Christophe JAILLET wrote:
> 'device_driver_attach()' dereferences its first argument (i.e. 'alt_drv')
> so it must not be NULL.
> Simplify the error handling logic about NULL 'alt_drv' in order to be
> more robust and future-proof.
>
> Fixes: 568b2126466f ("dmaengine: idxd: fix uninit var for alt_drv")
> Fixes: 6e7f3ee97bbe ("dmaengine: idxd: move dsa_drv support to compatible mode")
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>


Thanks for the cleanup.

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

> ---
>   drivers/dma/idxd/compat.c | 15 ++++-----------
>   1 file changed, 4 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/dma/idxd/compat.c b/drivers/dma/idxd/compat.c
> index d7616c240dcd..3df21615f888 100644
> --- a/drivers/dma/idxd/compat.c
> +++ b/drivers/dma/idxd/compat.c
> @@ -45,23 +45,16 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf, size_t cou
>   	idxd_dev = confdev_to_idxd_dev(dev);
>   	if (is_idxd_dev(idxd_dev)) {
>   		alt_drv = driver_find("idxd", bus);
> -		if (!alt_drv)
> -			return -ENODEV;
>   	} else if (is_idxd_wq_dev(idxd_dev)) {
>   		struct idxd_wq *wq = confdev_to_wq(dev);
>   
> -		if (is_idxd_wq_kernel(wq)) {
> +		if (is_idxd_wq_kernel(wq))
>   			alt_drv = driver_find("dmaengine", bus);
> -			if (!alt_drv)
> -				return -ENODEV;
> -		} else if (is_idxd_wq_user(wq)) {
> +		else if (is_idxd_wq_user(wq))
>   			alt_drv = driver_find("user", bus);
> -			if (!alt_drv)
> -				return -ENODEV;
> -		} else {
> -			return -ENODEV;
> -		}
>   	}
> +	if (!alt_drv)
> +		return -ENODEV;
>   
>   	rc = device_driver_attach(alt_drv, dev);
>   	if (rc < 0)
Vinod Koul Aug. 2, 2021, 7:05 a.m. UTC | #2
On 29-07-21, 14:04, Christophe JAILLET wrote:
> 'device_driver_attach()' dereferences its first argument (i.e. 'alt_drv')
> so it must not be NULL.
> Simplify the error handling logic about NULL 'alt_drv' in order to be
> more robust and future-proof.

Applied, thanks
diff mbox series

Patch

diff --git a/drivers/dma/idxd/compat.c b/drivers/dma/idxd/compat.c
index d7616c240dcd..3df21615f888 100644
--- a/drivers/dma/idxd/compat.c
+++ b/drivers/dma/idxd/compat.c
@@ -45,23 +45,16 @@  static ssize_t bind_store(struct device_driver *drv, const char *buf, size_t cou
 	idxd_dev = confdev_to_idxd_dev(dev);
 	if (is_idxd_dev(idxd_dev)) {
 		alt_drv = driver_find("idxd", bus);
-		if (!alt_drv)
-			return -ENODEV;
 	} else if (is_idxd_wq_dev(idxd_dev)) {
 		struct idxd_wq *wq = confdev_to_wq(dev);
 
-		if (is_idxd_wq_kernel(wq)) {
+		if (is_idxd_wq_kernel(wq))
 			alt_drv = driver_find("dmaengine", bus);
-			if (!alt_drv)
-				return -ENODEV;
-		} else if (is_idxd_wq_user(wq)) {
+		else if (is_idxd_wq_user(wq))
 			alt_drv = driver_find("user", bus);
-			if (!alt_drv)
-				return -ENODEV;
-		} else {
-			return -ENODEV;
-		}
 	}
+	if (!alt_drv)
+		return -ENODEV;
 
 	rc = device_driver_attach(alt_drv, dev);
 	if (rc < 0)