All of lore.kernel.org
 help / color / mirror / Atom feed
From: Halil Pasic <pasic@linux.ibm.com>
To: "Jason J. Herne" <jjherne@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	akrowiak@linux.ibm.com, jgg@nvidia.com
Subject: Re: [PATCH v2] s390/vfio-ap: Fix module unload memory leak of matrix_dev
Date: Mon, 21 Jun 2021 12:04:32 +0200	[thread overview]
Message-ID: <20210621120432.0e6d2839.pasic@linux.ibm.com> (raw)
In-Reply-To: <20210618171255.2025-1-jjherne@linux.ibm.com>

On Fri, 18 Jun 2021 13:12:55 -0400
"Jason J. Herne" <jjherne@linux.ibm.com> wrote:

> vfio_ap_matrix_dev_release is shadowing the global matrix_dev with a NULL
> pointer. Driver data for the matrix device is never set and so
> dev_get_drvdata() always returns NULL. When release is called we end up
> not freeing matrix_dev. The fix is to remove the shadow variable and get
> the correct pointer from the device using container_of. We'll also NULL
> the global to prevent any future use.
> 
> Signed-off-by: Jason J. Herne <jjherne@linux.ibm.com>
> ---
>  drivers/s390/crypto/vfio_ap_drv.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c
> index 7dc72cb718b0..40e66cb363d1 100644
> --- a/drivers/s390/crypto/vfio_ap_drv.c
> +++ b/drivers/s390/crypto/vfio_ap_drv.c
> @@ -82,9 +82,8 @@ static void vfio_ap_queue_dev_remove(struct ap_device *apdev)
>  
>  static void vfio_ap_matrix_dev_release(struct device *dev)
>  {
> -	struct ap_matrix_dev *matrix_dev = dev_get_drvdata(dev);
> -
> -	kfree(matrix_dev);
> +	kfree(container_of(dev, struct ap_matrix_dev, device));
> +	matrix_dev = NULL;

Reviewed-by: Halil Pasic <pasic@linux.ibm.com>

I'm not sure nulling the global here buys us anything (especially after
the kfree()). But it does not hurt either, so I'm fine with it. Style
wise I think vfio_ap_matrix_dev_destroy() is a better place for the
nulling IMHO, as it is dealing with module global state.

Regards,
Halil


>  }
>  
>  static int matrix_bus_match(struct device *dev, struct device_driver *drv)


      parent reply	other threads:[~2021-06-21 10:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18 17:12 [PATCH v2] s390/vfio-ap: Fix module unload memory leak of matrix_dev Jason J. Herne
2021-06-18 18:11 ` Tony Krowiak
2021-06-18 18:23   ` Jason Gunthorpe
2021-06-18 20:05     ` Tony Krowiak
2021-06-21 10:04 ` Halil Pasic [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210621120432.0e6d2839.pasic@linux.ibm.com \
    --to=pasic@linux.ibm.com \
    --cc=akrowiak@linux.ibm.com \
    --cc=jgg@nvidia.com \
    --cc=jjherne@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.