public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
To: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Cc: igt-dev@lists.freedesktop.org, Petri Latvala <petri.latvala@intel.com>
Subject: Re: [igt-dev] [PATCH i-g-t] lib: Fix device lists not cleaned up sufficiently before rescan
Date: Thu, 2 Apr 2020 20:31:40 +0200	[thread overview]
Message-ID: <20200402183140.GA18573@zkempczy-mobl2> (raw)
In-Reply-To: <0e6d89a14d7a2b87bc888297ef83c5e43a748039.camel@linux.intel.com>

On Thu, Apr 02, 2020 at 08:12:15PM +0200, Janusz Krzysztofik wrote:
> Hi Zbyszek,
> 
> Thanks for review.
> 
> On Thu, 2020-04-02 at 19:23 +0200, Zbigniew Kempczyński wrote:
> > On Fri, Mar 20, 2020 at 04:36:23PM +0100, Janusz Krzysztofik wrote:
> > > Some effort is already taken to clean up previous content of device
> > > lists before forced device rescan is performed but it is not
> > > sufficient.  An attempt to use forced device rescan in a test results
> > > in that test crashing or spinning until being killed by OOM killer.
> > > Fix it.
> > > 
> > > Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
> > > ---
> > >  lib/igt_device_scan.c | 16 ++++++++++------
> > >  1 file changed, 10 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
> > > index b3f79c81e..db4da30d3 100644
> > > --- a/lib/igt_device_scan.c
> > > +++ b/lib/igt_device_scan.c
> > > @@ -353,14 +353,11 @@ static void set_vendor_device(struct igt_device *dev)
> > >  	dev->device = strndup(pci_id + 5, 4);
> > >  }
> > >  
> > > -/* Allocate arrays for keeping scanned devices */
> > > +/* Initialize lists for keeping scanned devices */
> > >  static bool prepare_scan(void)
> > >  {
> > > -	if (igt_devs.all.prev == NULL || igt_devs.all.next == NULL)
> > > -		IGT_INIT_LIST_HEAD(&igt_devs.all);
> > > -
> > > -	if (igt_devs.filtered.prev == NULL || igt_devs.filtered.next == NULL)
> > > -		IGT_INIT_LIST_HEAD(&igt_devs.filtered);
> > > +	IGT_INIT_LIST_HEAD(&igt_devs.all);
> > > +	IGT_INIT_LIST_HEAD(&igt_devs.filtered);
> > 
> > I think above change according to the change below is not required. 
> 
> Indeed, but I can see no use case for conditional initialisation of the
> lists.
> 
> > 
> > >  
> > >  	return true;
> > >  }
> > > @@ -595,8 +592,15 @@ void igt_devices_scan(bool force)
> > >  {
> > >  	if (force && igt_devs.devs_scanned) {
> > >  		struct igt_device *dev, *tmp;
> > > +
> > > +		igt_list_for_each_entry_safe(dev, tmp, &igt_devs.filtered,
> > > +					     link) {
> > > +			igt_list_del(&dev->link);
> > > +			free(dev);
> > > +		}
> > >  		igt_list_for_each_entry_safe(dev, tmp, &igt_devs.all, link) {
> > >  			igt_device_free(dev);
> > > +			igt_list_del(&dev->link);
> 
> Looking at it again, I think we should better move deletion of the
> device from the list up one line so we are still more safe from use
> after free.  Please confirm your R-b still applies in that case.
> 
> Thanks,
> Janusz

Yes, you're right, better is to free the device one line after :)

Yes, you still got my R-B.

--
Zbigniew

> 
> 
> > >  			free(dev);
> > >  		}
> > >  
> > > -- 
> > > 2.21.1
> > > 
> > 
> > Yes, that part is what we need to fix the leak. 
> > 
> > Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com> 
> 
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

      reply	other threads:[~2020-04-02 18:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-20 15:36 [igt-dev] [PATCH i-g-t] lib: Fix device lists not cleaned up sufficiently before rescan Janusz Krzysztofik
2020-03-20 16:07 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2020-03-20 21:52 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2020-04-02 17:23 ` [igt-dev] [PATCH i-g-t] " Zbigniew Kempczyński
2020-04-02 18:12   ` Janusz Krzysztofik
2020-04-02 18:31     ` Zbigniew Kempczyński [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=20200402183140.GA18573@zkempczy-mobl2 \
    --to=zbigniew.kempczynski@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=janusz.krzysztofik@linux.intel.com \
    --cc=petri.latvala@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox