* [PATCH] s390/vfio_ap: fix memory leak in vfio_ap device driver
@ 2023-03-15 15:39 Tony Krowiak
2023-03-15 17:25 ` Harald Freudenberger
2023-03-16 8:39 ` Heiko Carstens
0 siblings, 2 replies; 5+ messages in thread
From: Tony Krowiak @ 2023-03-15 15:39 UTC (permalink / raw)
To: linux-s390, linux-kernel, kvm
Cc: jjherne, pasic, alex.williamson, borntraeger
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: 1fde573413b5 ("s390: vfio-ap: base implementation of VFIO AP device driver")
Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
---
drivers/s390/crypto/vfio_ap_drv.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c
index 997b524bdd2b..15e9de9f4574 100644
--- a/drivers/s390/crypto/vfio_ap_drv.c
+++ b/drivers/s390/crypto/vfio_ap_drv.c
@@ -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 = container_of(dev,
+ struct ap_matrix_dev,
+ device);
kfree(matrix_dev);
}
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] s390/vfio_ap: fix memory leak in vfio_ap device driver
2023-03-15 15:39 [PATCH] s390/vfio_ap: fix memory leak in vfio_ap device driver Tony Krowiak
@ 2023-03-15 17:25 ` Harald Freudenberger
2023-03-15 17:57 ` Anthony Krowiak
2023-03-16 8:39 ` Heiko Carstens
1 sibling, 1 reply; 5+ messages in thread
From: Harald Freudenberger @ 2023-03-15 17:25 UTC (permalink / raw)
To: Tony Krowiak
Cc: linux-s390, linux-kernel, kvm, jjherne, pasic, alex.williamson,
borntraeger
On 2023-03-15 16:39, Tony Krowiak wrote:
> 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: 1fde573413b5 ("s390: vfio-ap: base implementation of VFIO AP
> device driver")
> Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
> ---
> drivers/s390/crypto/vfio_ap_drv.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/s390/crypto/vfio_ap_drv.c
> b/drivers/s390/crypto/vfio_ap_drv.c
> index 997b524bdd2b..15e9de9f4574 100644
> --- a/drivers/s390/crypto/vfio_ap_drv.c
> +++ b/drivers/s390/crypto/vfio_ap_drv.c
> @@ -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 = container_of(dev,
> + struct ap_matrix_dev,
> + device);
> kfree(matrix_dev);
> }
I needed some indirections to follow what exactly happens here and how
you
fix it, but finally I got it.
Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] s390/vfio_ap: fix memory leak in vfio_ap device driver
2023-03-15 17:25 ` Harald Freudenberger
@ 2023-03-15 17:57 ` Anthony Krowiak
0 siblings, 0 replies; 5+ messages in thread
From: Anthony Krowiak @ 2023-03-15 17:57 UTC (permalink / raw)
To: freude
Cc: linux-s390, linux-kernel, kvm, jjherne, pasic, alex.williamson,
borntraeger
snip ...
> I needed some indirections to follow what exactly happens here and how
> you
> fix it, but finally I got it.
> Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
Sorry about the indirections. Thanks for the review.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] s390/vfio_ap: fix memory leak in vfio_ap device driver
2023-03-15 15:39 [PATCH] s390/vfio_ap: fix memory leak in vfio_ap device driver Tony Krowiak
2023-03-15 17:25 ` Harald Freudenberger
@ 2023-03-16 8:39 ` Heiko Carstens
2023-03-16 13:35 ` Anthony Krowiak
1 sibling, 1 reply; 5+ messages in thread
From: Heiko Carstens @ 2023-03-16 8:39 UTC (permalink / raw)
To: Tony Krowiak
Cc: linux-s390, linux-kernel, kvm, jjherne, pasic, alex.williamson,
borntraeger
On Wed, Mar 15, 2023 at 11:39:32AM -0400, Tony Krowiak wrote:
> 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: 1fde573413b5 ("s390: vfio-ap: base implementation of VFIO AP device driver")
> Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
> ---
> drivers/s390/crypto/vfio_ap_drv.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c
> index 997b524bdd2b..15e9de9f4574 100644
> --- a/drivers/s390/crypto/vfio_ap_drv.c
> +++ b/drivers/s390/crypto/vfio_ap_drv.c
> @@ -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 = container_of(dev,
> + struct ap_matrix_dev,
> + device);
> kfree(matrix_dev);
Could you keep this code more readable, including adding the missing
blank line after the declaration, please? Something like:
static void vfio_ap_matrix_dev_release(struct device *dev)
{
struct ap_matrix_dev *matrix_dev;
matrix_dev = container_of(dev, struct ap_matrix_dev, device);
kfree(matrix_dev);
}
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] s390/vfio_ap: fix memory leak in vfio_ap device driver
2023-03-16 8:39 ` Heiko Carstens
@ 2023-03-16 13:35 ` Anthony Krowiak
0 siblings, 0 replies; 5+ messages in thread
From: Anthony Krowiak @ 2023-03-16 13:35 UTC (permalink / raw)
To: Heiko Carstens
Cc: linux-s390, linux-kernel, kvm, jjherne, pasic, alex.williamson,
borntraeger
On 3/16/23 4:39 AM, Heiko Carstens wrote:
> On Wed, Mar 15, 2023 at 11:39:32AM -0400, Tony Krowiak wrote:
>> 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: 1fde573413b5 ("s390: vfio-ap: base implementation of VFIO AP device driver")
>> Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
>> ---
>> drivers/s390/crypto/vfio_ap_drv.c | 5 +++--
>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c
>> index 997b524bdd2b..15e9de9f4574 100644
>> --- a/drivers/s390/crypto/vfio_ap_drv.c
>> +++ b/drivers/s390/crypto/vfio_ap_drv.c
>> @@ -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 = container_of(dev,
>> + struct ap_matrix_dev,
>> + device);
>> kfree(matrix_dev);
> Could you keep this code more readable, including adding the missing
> blank line after the declaration, please? Something like:
>
> static void vfio_ap_matrix_dev_release(struct device *dev)
> {
> struct ap_matrix_dev *matrix_dev;
>
> matrix_dev = container_of(dev, struct ap_matrix_dev, device);
> kfree(matrix_dev);
> }
>
> Thanks!
Will do.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-03-16 13:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-15 15:39 [PATCH] s390/vfio_ap: fix memory leak in vfio_ap device driver Tony Krowiak
2023-03-15 17:25 ` Harald Freudenberger
2023-03-15 17:57 ` Anthony Krowiak
2023-03-16 8:39 ` Heiko Carstens
2023-03-16 13:35 ` Anthony Krowiak
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.