From: Jason Gunthorpe <jgg@nvidia.com>
To: "Jason J. Herne" <jjherne@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
pasic@linux.ibm.com, akrowiak@linux.ibm.com
Subject: Re: [PATCH] s390/vfio-ap: Fix module unload memory leak of matrix_dev
Date: Fri, 18 Jun 2021 11:59:59 -0300 [thread overview]
Message-ID: <20210618145959.GF1002214@nvidia.com> (raw)
In-Reply-To: <4ea3de71-9d68-59c6-bfb8-d8258019e585@linux.ibm.com>
On Fri, Jun 18, 2021 at 10:35:21AM -0400, Jason J. Herne wrote:
> On 6/18/21 10:10 AM, Jason Gunthorpe wrote:
> > On Fri, Jun 18, 2021 at 09:35:24AM -0400, Jason J. Herne wrote:
> > > vfio_ap_matrix_dev_release is shadowing the global matrix_dev with driver
> > > data that never gets set. So when release is called we end up not freeing
> > > matrix_dev. The fix is to remove the shadow variable and just free the
> > > global.
> >
> > I would clarify this commit message to say that the drv_data of the
> > matrix_dev is never set and so dev_get_drvdata() always returns NULL
> >
> > And I would suggest to use
> >
> > container_of(dev, struct ap_matrix_dev, dev)
> >
> > instead of the global variable, and probably NULL the global
> > too..
> >
>
> The use of driver_data seems to have been completely erroneous here. In this
> case the global matrix_dev is the top level struct. It is not contained in
> anything. matrix_dev is created upon module load, and it is freed when the
> module exits.
>
> So I don't think using container_of makes sense. Unless I've
> misunderstood your suggestion?
matrix_dev = kzalloc(sizeof(*matrix_dev), GFP_KERNEL);
matrix_dev->device.release = vfio_ap_matrix_dev_release;
ret = device_register(&matrix_dev->device);
"dev" is contained inside matrix_dev which is why we should use
container of to go from a struct device pointer back to the containing
matrix_dev pointer
Jason
next prev parent reply other threads:[~2021-06-18 15:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-18 13:35 [PATCH] s390/vfio-ap: Fix module unload memory leak of matrix_dev Jason J. Herne
2021-06-18 14:10 ` Jason Gunthorpe
2021-06-18 14:35 ` Jason J. Herne
2021-06-18 14:59 ` Jason Gunthorpe [this message]
2021-06-18 15:31 ` Tony Krowiak
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=20210618145959.GF1002214@nvidia.com \
--to=jgg@nvidia.com \
--cc=akrowiak@linux.ibm.com \
--cc=jjherne@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=pasic@linux.ibm.com \
/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.