Skip to content

Commit afc545d

Browse files
TomRita999jgross1
authored andcommitted
xen: Fix the issue of resource not being properly released in xenbus_dev_probe()
This patch fixes an issue in the function xenbus_dev_probe(). In the xenbus_dev_probe() function, within the if (err) branch at line 313, the program incorrectly returns err directly without releasing the resources allocated by err = drv->probe(dev, id). As the return value is non-zero, the upper layers assume the processing logic has failed. However, the probe operation was performed earlier without a corresponding remove operation. Since the probe actually allocates resources, failing to perform the remove operation could lead to problems. To fix this issue, we followed the resource release logic of the xenbus_dev_remove() function by adding a new block fail_remove before the fail_put block. After entering the branch if (err) at line 313, the function will use a goto statement to jump to the fail_remove block, ensuring that the previously acquired resources are correctly released, thus preventing the reference count leak. This bug was identified by an experimental static analysis tool developed by our team. The tool specializes in analyzing reference count operations and detecting potential issues where resources are not properly managed. In this case, the tool flagged the missing release operation as a potential problem, which led to the development of this patch. Fixes: 4bac07c ("xen: add the Xenbus sysfs and virtual device hotplug driver") Cc: stable@vger.kernel.org Signed-off-by: Qiu-ji Chen <chenqiuji666@gmail.com> Reviewed-by: Juergen Gross <jgross@suse.com> Message-ID: <20241105130919.4621-1-chenqiuji666@gmail.com> Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent 5c6808d commit afc545d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/xen/xenbus/xenbus_probe.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ int xenbus_dev_probe(struct device *_dev)
313313
if (err) {
314314
dev_warn(&dev->dev, "watch_otherend on %s failed.\n",
315315
dev->nodename);
316-
return err;
316+
goto fail_remove;
317317
}
318318

319319
dev->spurious_threshold = 1;
@@ -322,6 +322,12 @@ int xenbus_dev_probe(struct device *_dev)
322322
dev->nodename);
323323

324324
return 0;
325+
fail_remove:
326+
if (drv->remove) {
327+
down(&dev->reclaim_sem);
328+
drv->remove(dev);
329+
up(&dev->reclaim_sem);
330+
}
325331
fail_put:
326332
module_put(drv->driver.owner);
327333
fail:

0 commit comments

Comments
 (0)