linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: idxd: Fix a possible NULL pointer dereference
@ 2021-07-29 12:04 Christophe JAILLET
  2021-07-29 16:12 ` Dave Jiang
  2021-08-02  7:05 ` Vinod Koul
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2021-07-29 12:04 UTC (permalink / raw)
  To: dave.jiang, vkoul, dan.j.williams
  Cc: dmaengine, linux-kernel, kernel-janitors, Christophe JAILLET

'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(-)

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


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

end of thread, other threads:[~2021-08-02  7:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29 12:04 [PATCH] dmaengine: idxd: Fix a possible NULL pointer dereference Christophe JAILLET
2021-07-29 16:12 ` Dave Jiang
2021-08-02  7:05 ` 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).