From: gavinli@thegavinli.com
To: jic23@kernel.org, lars@metafoo.de
Cc: linux-iio@vger.kernel.org, Gavin Li <gavin@matician.com>
Subject: [PATCH] iio: trigger: fix iio_trigger reference leak
Date: Fri, 8 Oct 2021 01:32:20 -0700 [thread overview]
Message-ID: <20211008083220.3713926-1-gavinli@thegavinli.com> (raw)
From: Gavin Li <gavin@matician.com>
viio_trigger_alloc() includes a get_device() call added in commit
5f9c035cae back in 2011. While I wasn't able to ascertain why it was
added, I've noticed that it does cause a memory leak, especially when
rmmod'ing iio modules. Here is a simple module that replicates this
issue:
#include <linux/module.h>
#include <linux/iio/iio.h>
#include <linux/iio/trigger.h>
int my_init(void) {
struct iio_trigger *trig = iio_trigger_alloc("leak-trig");
if (!trig)
return -ENOMEM;
printk("iio-leak: %u uses at A\n", kref_read(&trig->dev.kobj.kref));
iio_trigger_free(trig);
printk("iio-leak: %u uses at B\n", kref_read(&trig->dev.kobj.kref));
return 0;
}
void my_exit(void) {}
module_init(my_init);
module_exit(my_exit);
MODULE_LICENSE("GPL v2");
It prints the following in the kernel log:
iio-leak: 2 uses at A
iio-leak: 1 uses at B
This patch removes the get_device() call. This shouldn't break
subirqs with iio_trigger_attach_poll_func() because a reference should
already exist via indio_dev->trig.
---
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 b23caa2f2aa1f..93990ff1dfe39 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;
--
2.33.0
next reply other threads:[~2021-10-08 8:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-08 8:32 gavinli [this message]
2021-10-17 16:09 ` [PATCH] iio: trigger: fix iio_trigger reference leak 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=20211008083220.3713926-1-gavinli@thegavinli.com \
--to=gavinli@thegavinli.com \
--cc=gavin@matician.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox