All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Martin Fuzzey <mfuzzey@parkeon.com>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH 2/2] iio: trigger: Fix reference counting
Date: Thu, 28 Oct 2021 17:12:08 +0100	[thread overview]
Message-ID: <20211028171208.0edaa4e1@jic23-huawei> (raw)
In-Reply-To: <41bc22f4-071e-9ede-bce2-2d3c9cdf0344@metafoo.de>

On Thu, 28 Oct 2021 18:04:22 +0200
Lars-Peter Clausen <lars@metafoo.de> wrote:

> On 10/28/21 4:16 PM, Jonathan Cameron wrote:
> > On Sun, 24 Oct 2021 11:27:00 +0200
> > Lars-Peter Clausen <lars@metafoo.de> wrote:
> >  
> >> In viio_trigger_alloc() device_initialize() is used to set the initial
> >> reference count of the trigger to 1. Then another get_device() is called on
> >> trigger. This sets the reference count to 2 before the trigger is returned.
> >>
> >> iio_trigger_free(), which is the matching API to viio_trigger_alloc(),
> >> calls put_device() which decreases the reference count by 1. But the second
> >> reference count acquired in viio_trigger_alloc() is never dropped.
> >>
> >> As a result the iio_trigger_release() function is never called and the
> >> memory associated with the trigger is never freed.
> >>
> >> Since there is no reason for the trigger to start its lifetime with two
> >> reference counts just remove the extra get_device() in
> >> viio_trigger_alloc().
> >>
> >> Fixes: 5f9c035cae18 ("staging:iio:triggers. Add a reference get to the core for triggers.")
> >> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>  
> > I fully agree the current code is wrong, but we really should be using
> > device_put() in the error path after device_initialize() has been called.
> >
> > There are multiple places where we currently do this wrong in IIO but this particular
> > one looks like a local fix would be safe.
> > Worth doing that in the same patch at this one given it's all about reference
> > counting logic being wrong?  If not, we can do it as a separate follow up patch.  
> I already have that patch. Just waiting for this to be applied since it 
> has a dependency.

In that case, applied for this one to the fixes-togreg branch of iio.git.

Thanks,

Jonathan

> >
> > Jonathan
> >
> >  
> >> ---
> >> I'm a bit unsure about the fixes tag. I've looked at the IIO tree at the
> >> point when this was introduced and I believe it was incorrect even back
> >> then.
> >>
> >> But we also had a few drivers that directly assigned the indio_dev->trig
> >> without getting an extra reference. So these two bugs, one in the core, one
> >> in the drivers sort of even out. Except that iio_trigger_get() also gets a
> >> reference to the drivers module and iio_trigger_put() releases it again. So
> >> with the missing iio_trigger_get() there is still the problem that, even
> >> though the device references balance out, there is a module reference count
> >> imbalance.
> >> ---
> >>   drivers/iio/industrialio-trigger.c | 1 -
> >>   1 file changed, 1 deletion(-)
> >>
> >> diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
> >> index b23caa2f2aa1..93990ff1dfe3 100644
> >> --- a/drivers/iio/industrialio-trigger.c
> >> +++ b/drivers/iio/industrialio-trigger.c
> >> @@ -556,7 +556,6 @@ struct iio_trigger *viio_trigger_alloc(struct device *parent,
> >>   		irq_modify_status(trig->subirq_base + i,
> >>   				  IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE);
> >>   	}
> >> -	get_device(&trig->dev);
> >>   
> >>   	return trig;
> >>     
> 
> 


  reply	other threads:[~2021-10-28 16:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-24  9:26 [PATCH 1/2] iio: mma8452: Fix trigger reference couting Lars-Peter Clausen
2021-10-24  9:27 ` [PATCH 2/2] iio: trigger: Fix reference counting Lars-Peter Clausen
2021-10-25 10:55   ` Sa, Nuno
2021-10-28 14:16   ` Jonathan Cameron
2021-10-28 16:04     ` Lars-Peter Clausen
2021-10-28 16:12       ` Jonathan Cameron [this message]
2021-10-28 14:07 ` [PATCH 1/2] iio: mma8452: Fix trigger reference couting Jonathan Cameron
2021-10-28 19:52   ` Lars-Peter Clausen
2021-10-30 15:03     ` Jonathan Cameron
2021-10-30 15:12       ` Lars-Peter Clausen
2021-10-30 17:08         ` Jonathan Cameron

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=20211028171208.0edaa4e1@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=mfuzzey@parkeon.com \
    --cc=pmeerw@pmeerw.net \
    /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.