Skip to content

Commit a438668

Browse files
ausyskingregkh
authored andcommitted
mei: bus: fix unlink on bus in error path
Unconditional call to mei_cl_unlink in mei_cl_bus_dev_release leads to call of the mei_cl_unlink without corresponding mei_cl_link. This leads to miscalculation of open_handle_count (decrease without increase). Call unlink in mei_cldev_enable fail path and remove blanket unlink from mei_cl_bus_dev_release. Fixes: 34f1166 ("mei: bus: need to unlink client before freeing") Cc: <[email protected]> Signed-off-by: Alexander Usyskin <[email protected]> Reviewed-by: Tomas Winkler <[email protected]> Signed-off-by: Tomas Winkler <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 732065d commit a438668

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

drivers/misc/mei/bus.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,13 +702,15 @@ void *mei_cldev_dma_map(struct mei_cl_device *cldev, u8 buffer_id, size_t size)
702702
if (cl->state == MEI_FILE_UNINITIALIZED) {
703703
ret = mei_cl_link(cl);
704704
if (ret)
705-
goto out;
705+
goto notlinked;
706706
/* update pointers */
707707
cl->cldev = cldev;
708708
}
709709

710710
ret = mei_cl_dma_alloc_and_map(cl, NULL, buffer_id, size);
711-
out:
711+
if (ret)
712+
mei_cl_unlink(cl);
713+
notlinked:
712714
mutex_unlock(&bus->device_lock);
713715
if (ret)
714716
return ERR_PTR(ret);
@@ -758,7 +760,7 @@ int mei_cldev_enable(struct mei_cl_device *cldev)
758760
if (cl->state == MEI_FILE_UNINITIALIZED) {
759761
ret = mei_cl_link(cl);
760762
if (ret)
761-
goto out;
763+
goto notlinked;
762764
/* update pointers */
763765
cl->cldev = cldev;
764766
}
@@ -785,6 +787,9 @@ int mei_cldev_enable(struct mei_cl_device *cldev)
785787
}
786788

787789
out:
790+
if (ret)
791+
mei_cl_unlink(cl);
792+
notlinked:
788793
mutex_unlock(&bus->device_lock);
789794

790795
return ret;
@@ -1277,7 +1282,6 @@ static void mei_cl_bus_dev_release(struct device *dev)
12771282
mei_cl_flush_queues(cldev->cl, NULL);
12781283
mei_me_cl_put(cldev->me_cl);
12791284
mei_dev_bus_put(cldev->bus);
1280-
mei_cl_unlink(cldev->cl);
12811285
kfree(cldev->cl);
12821286
kfree(cldev);
12831287
}

0 commit comments

Comments
 (0)