linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: butt3rflyh4ck <butterflyhuangxx@gmail.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	mchehab@kernel.org, tglx@linutronix.de, mpe@ellerman.id.au,
	allison@lohutok.net
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: media/pci: prevent memory leak in bttv_probe
Date: Fri, 17 Apr 2020 17:45:26 +0800	[thread overview]
Message-ID: <CAFcO6XN-adr9SYt2KX2UyNChV+XSprnWmOWkGuPMcaS6FT+gGg@mail.gmail.com> (raw)
In-Reply-To: <4149a5b4-c3f3-2902-84e2-eedc9ecc54f8@xs4all.nl>

On Fri, Apr 17, 2020 at 3:26 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>
> On 25/03/2020 10:01, Xiaolong Huang wrote:
> > In bttv_probe if some functions such as pci_enable_device,
> > pci_set_dma_mask and request_mem_region fails the allocated
> >  memory for btv should be released.
> >
> > Signed-off-by: Xiaolong Huang <butterflyhuangxx@gmail.com>
> > ---
> >  drivers/media/pci/bt8xx/bttv-driver.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
> > index a359da7773a9..37ac59110383 100644
> > --- a/drivers/media/pci/bt8xx/bttv-driver.c
> > +++ b/drivers/media/pci/bt8xx/bttv-driver.c
> > @@ -4013,10 +4013,14 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
> >       btv->id  = dev->device;
> >       if (pci_enable_device(dev)) {
> >               pr_warn("%d: Can't enable device\n", btv->c.nr);
> > +             bttvs[btv->c.nr] = NULL;
> > +             kfree(btv);
> >               return -EIO;
>
> Let's change this...
>
> >       }
> >       if (pci_set_dma_mask(dev, DMA_BIT_MASK(32))) {
> >               pr_warn("%d: No suitable DMA available\n", btv->c.nr);
> > +             bttvs[btv->c.nr] = NULL;
> > +             kfree(btv);
> >               return -EIO;
>
> this...
>
> >       }
> >       if (!request_mem_region(pci_resource_start(dev,0),
> > @@ -4025,6 +4029,8 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
> >               pr_warn("%d: can't request iomem (0x%llx)\n",
> >                       btv->c.nr,
> >                       (unsigned long long)pci_resource_start(dev, 0));
> > +             bttvs[btv->c.nr] = NULL;
> > +             kfree(btv);
> >               return -EBUSY;
>
> and this to a goto free_mem.
>
> >       }
> >       pci_set_master(dev);
> > @@ -4211,6 +4217,8 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
> >       release_mem_region(pci_resource_start(btv->c.pci,0),
> >                          pci_resource_len(btv->c.pci,0));
> >       pci_disable_device(btv->c.pci);
>
> And add the free_mem: label here.
>
> > +     bttvs[btv->c.nr] = NULL;
> > +     kfree(btv);
> >       return result;
> >  }
> >
> >
>
> Regards,
>
>         Hans

Good, I will modify the patch and resend a new one.

Thanks,

      Butt3flyh4ck

  reply	other threads:[~2020-04-17  9:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25  9:01 [PATCH] media: media/pci: prevent memory leak in bttv_probe Xiaolong Huang
2020-04-17  7:26 ` Hans Verkuil
2020-04-17  9:45   ` butt3rflyh4ck [this message]
2020-04-17  9:52 Xiaolong Huang

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=CAFcO6XN-adr9SYt2KX2UyNChV+XSprnWmOWkGuPMcaS6FT+gGg@mail.gmail.com \
    --to=butterflyhuangxx@gmail.com \
    --cc=allison@lohutok.net \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).