Commit 8f8cf767 authored by Tony Krowiak's avatar Tony Krowiak Committed by Vasily Gorbik

s390/vfio-ap: fix memory leak in vfio_ap device driver

The device release callback function invoked to release the matrix device
uses the dev_get_drvdata(device *dev) function to retrieve the
pointer to the vfio_matrix_dev object in order to free its storage. The
problem is, this object is not stored as drvdata with the device; since the
kfree function will accept a NULL pointer, the memory for the
vfio_matrix_dev object is never freed.

Since the device being released is contained within the vfio_matrix_dev
object, the container_of macro will be used to retrieve its pointer.

Fixes: 1fde5734 ("s390: vfio-ap: base implementation of VFIO AP device driver")
Signed-off-by: default avatarTony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: default avatarHarald Freudenberger <freude@linux.ibm.com>
Link: https://lore.kernel.org/r/20230320150447.34557-1-akrowiak@linux.ibm.comSigned-off-by: default avatarHeiko Carstens <hca@linux.ibm.com>
Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
parent 89aba4c2
...@@ -54,8 +54,9 @@ static struct ap_driver vfio_ap_drv = { ...@@ -54,8 +54,9 @@ static struct ap_driver vfio_ap_drv = {
static void vfio_ap_matrix_dev_release(struct device *dev) static void vfio_ap_matrix_dev_release(struct device *dev)
{ {
struct ap_matrix_dev *matrix_dev = dev_get_drvdata(dev); struct ap_matrix_dev *matrix_dev;
matrix_dev = container_of(dev, struct ap_matrix_dev, device);
kfree(matrix_dev); kfree(matrix_dev);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment