Skip to content

Commit 799900f

Browse files
jhovoldvinodkoul
authored andcommitted
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: 6e7f3ee ("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>
1 parent ec25e60 commit 799900f

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

drivers/dma/idxd/compat.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf, size_t c
2020
int rc = -ENODEV;
2121

2222
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) {
2427
device_driver_detach(dev);
2528
rc = count;
2629
}
2730

31+
put_device(dev);
32+
2833
return rc;
2934
}
3035
static DRIVER_ATTR_IGNORE_LOCKDEP(unbind, 0200, NULL, unbind_store);
@@ -38,9 +43,12 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf, size_t cou
3843
struct idxd_dev *idxd_dev;
3944

4045
dev = bus_find_device_by_name(bus, NULL, buf);
41-
if (!dev || dev->driver || drv != &dsa_drv.drv)
46+
if (!dev)
4247
return -ENODEV;
4348

49+
if (dev->driver || drv != &dsa_drv.drv)
50+
goto err_put_dev;
51+
4452
idxd_dev = confdev_to_idxd_dev(dev);
4553
if (is_idxd_dev(idxd_dev)) {
4654
alt_drv = driver_find("idxd", bus);
@@ -53,13 +61,20 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf, size_t cou
5361
alt_drv = driver_find("user", bus);
5462
}
5563
if (!alt_drv)
56-
return -ENODEV;
64+
goto err_put_dev;
5765

5866
rc = device_driver_attach(alt_drv, dev);
5967
if (rc < 0)
60-
return rc;
68+
goto err_put_dev;
69+
70+
put_device(dev);
6171

6272
return count;
73+
74+
err_put_dev:
75+
put_device(dev);
76+
77+
return rc;
6378
}
6479
static DRIVER_ATTR_IGNORE_LOCKDEP(bind, 0200, NULL, bind_store);
6580

0 commit comments

Comments
 (0)