Skip to content

Commit 0dda569

Browse files
author
Alex Williamson
committed
s390/vfio-ap: fix memory leak in vfio_ap device driver
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2188088 commit 8f8cf76 Author: Tony Krowiak <akrowiak@linux.ibm.com> Date: Mon Mar 20 11:04:47 2023 -0400 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: 1fde573 ("s390: vfio-ap: base implementation of VFIO AP device driver") Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com> Reviewed-by: Harald Freudenberger <freude@linux.ibm.com> Link: https://lore.kernel.org/r/20230320150447.34557-1-akrowiak@linux.ibm.com Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent a4521a5 commit 0dda569

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/s390/crypto/vfio_ap_drv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ static struct ap_driver vfio_ap_drv = {
5454

5555
static void vfio_ap_matrix_dev_release(struct device *dev)
5656
{
57-
struct ap_matrix_dev *matrix_dev = dev_get_drvdata(dev);
57+
struct ap_matrix_dev *matrix_dev;
5858

59+
matrix_dev = container_of(dev, struct ap_matrix_dev, device);
5960
kfree(matrix_dev);
6061
}
6162

0 commit comments

Comments
 (0)