Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

dmaengine: idxd: fix device leaks on compat bind and unbind

Make sure to drop the reference taken when looking up the idxd device as
part of the compat bind and unbind sysfs interface.

Fixes: 6e7f3ee97bbe ("dmaengine: idxd: move dsa_drv support to compatible mode")
Cc: stable@vger.kernel.org # 5.15
Cc: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20251117161258.10679-7-johan@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Johan Hovold and committed by
Vinod Koul
799900f0 ec25e60f

+19 -4
+19 -4
drivers/dma/idxd/compat.c
··· 20 20 int rc = -ENODEV; 21 21 22 22 dev = bus_find_device_by_name(bus, NULL, buf); 23 - if (dev && dev->driver) { 23 + if (!dev) 24 + return -ENODEV; 25 + 26 + if (dev->driver) { 24 27 device_driver_detach(dev); 25 28 rc = count; 26 29 } 30 + 31 + put_device(dev); 27 32 28 33 return rc; 29 34 } ··· 43 38 struct idxd_dev *idxd_dev; 44 39 45 40 dev = bus_find_device_by_name(bus, NULL, buf); 46 - if (!dev || dev->driver || drv != &dsa_drv.drv) 41 + if (!dev) 47 42 return -ENODEV; 43 + 44 + if (dev->driver || drv != &dsa_drv.drv) 45 + goto err_put_dev; 48 46 49 47 idxd_dev = confdev_to_idxd_dev(dev); 50 48 if (is_idxd_dev(idxd_dev)) { ··· 61 53 alt_drv = driver_find("user", bus); 62 54 } 63 55 if (!alt_drv) 64 - return -ENODEV; 56 + goto err_put_dev; 65 57 66 58 rc = device_driver_attach(alt_drv, dev); 67 59 if (rc < 0) 68 - return rc; 60 + goto err_put_dev; 61 + 62 + put_device(dev); 69 63 70 64 return count; 65 + 66 + err_put_dev: 67 + put_device(dev); 68 + 69 + return rc; 71 70 } 72 71 static DRIVER_ATTR_IGNORE_LOCKDEP(bind, 0200, NULL, bind_store); 73 72