Skip to content

Commit 332e0e1

Browse files
sherllygregkh
authored andcommitted
staging: comedi: Fix comedi_device refcnt leak in comedi_open
comedi_open() invokes comedi_dev_get_from_minor(), which returns a reference of the COMEDI device to "dev" with increased refcount. When comedi_open() returns, "dev" becomes invalid, so the refcount should be decreased to keep refcount balanced. The reference counting issue happens in one exception handling path of comedi_open(). When "cfp" allocation is failed, the refcnt increased by comedi_dev_get_from_minor() is not decreased, causing a refcnt leak. Fix this issue by calling comedi_dev_put() on this error path when "cfp" allocation is failed. Fixes: 20f083c ("staging: comedi: prepare support for per-file read and write subdevices") Signed-off-by: Xiyu Yang <[email protected]> Cc: stable <[email protected]> Signed-off-by: Xin Tan <[email protected]> Signed-off-by: Ian Abbott <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0b59f10 commit 332e0e1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/staging/comedi/comedi_fops.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2725,8 +2725,10 @@ static int comedi_open(struct inode *inode, struct file *file)
27252725
}
27262726

27272727
cfp = kzalloc(sizeof(*cfp), GFP_KERNEL);
2728-
if (!cfp)
2728+
if (!cfp) {
2729+
comedi_dev_put(dev);
27292730
return -ENOMEM;
2731+
}
27302732

27312733
cfp->dev = dev;
27322734

0 commit comments

Comments
 (0)