s390/vfio_ap: fix memory leak in vfio_ap device driver
Subsystems (3)
Tony Krowiak
maintainerPATCH v2 1/1 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.
--- drivers/s390/crypto/vfio_ap_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/s390/crypto/vfio_ap_drv.c +2 -1
@@ -54,8 +54,9 @@ static struct ap_driver vfio_ap_drv = {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); }
Signature · 1 line
2.31.1
Anthony Krowiak
maintainerPING!
Quoted 32 lines · Tony Krowiak
The device release callback function invoked to release the matrix device uses the
dev_get_drvdata(device *dev)function to retrieve the pointer to thevfio_matrix_devobject 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 thevfio_matrix_devobject is never freed.Since the device being released is contained within the
vfio_matrix_devobject, thecontainer_ofmacro will be used to retrieve its pointer.Fixes 1fde573413b5 ("s390: vfio-ap: base implementation of VFIO AP device driver")Signed-off-by Tony Krowiak <[email protected]>Reviewed-by Harald Freudenberger <[email protected]>--- drivers/s390/crypto/vfio_ap_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/s390/crypto/vfio_ap_drv.c +2
-1@@ -54,8 +54,9 @@ static struct ap_driver vfio_ap_drv = {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); }
Quoted 10 lines · Tony Krowiak
The device release callback function invoked to release the matrix device uses the
dev_get_drvdata(device *dev)function to retrieve the pointer to thevfio_matrix_devobject 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 thevfio_matrix_devobject is never freed.Since the device being released is contained within the
vfio_matrix_devobject, thecontainer_ofmacro will be used to retrieve its pointer.
Quoted 6 lines
Fixes 1fde573413b5 ("s390: vfio-ap: base implementation of VFIO AP device driver")Signed-off-by Tony Krowiak <[email protected]>Reviewed-by Harald Freudenberger <[email protected]>--- drivers/s390/crypto/vfio_ap_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Applied.