From: Riccardo Oliva <oliva.scorza@gmail.com>
To: lee@kernel.org
Cc: linux-kernel@vger.kernel.org, mfd@lists.linux.dev,
oliva.scorza@gmail.com
Subject: [PATCH] mfd: dln2: Fix use-after-free risk in list iterator
Date: Mon, 12 Oct 2026 18:42:30 -0500 [thread overview]
Message-ID: <20261012234230.17966-1-oliva.scorza@gmail.com> (raw)
In dln2_unregister_event_cb(), the iterator variable 'i' is used after
the list_for_each_entry() loop terminates to free memory.
Fix this by introducing a dedicated 'target' pointer to hold the entry,
isolating the iterator to the loop scope and removing the 'found' bool.
Assisted-by: coccinelle sparse
Signed-off-by: Riccardo Oliva <oliva.scorza@gmail.com>
---
drivers/mfd/dln2.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/mfd/dln2.c b/drivers/mfd/dln2.c
index 0b1e7fd7f..7cd64aad1 100644
--- a/drivers/mfd/dln2.c
+++ b/drivers/mfd/dln2.c
@@ -157,25 +157,24 @@ EXPORT_SYMBOL(dln2_register_event_cb);
void dln2_unregister_event_cb(struct platform_device *pdev, u16 id)
{
struct dln2_dev *dln2 = dev_get_drvdata(pdev->dev.parent);
- struct dln2_event_cb_entry *i;
+ struct dln2_event_cb_entry *i, *target = NULL;
unsigned long flags;
- bool found = false;
spin_lock_irqsave(&dln2->event_cb_lock, flags);
list_for_each_entry(i, &dln2->event_cb_list, list) {
if (i->id == id) {
list_del_rcu(&i->list);
- found = true;
+ target = i;
break;
}
}
spin_unlock_irqrestore(&dln2->event_cb_lock, flags);
- if (found) {
+ if (target) {
synchronize_rcu();
- kfree(i);
+ kfree(target);
}
}
EXPORT_SYMBOL(dln2_unregister_event_cb);
--
2.43.0
next reply other threads:[~2026-10-12 23:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 23:42 Riccardo Oliva [this message]
2026-10-20 9:59 ` Lee Jones
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=20261012234230.17966-1-oliva.scorza@gmail.com \
--to=oliva.scorza@gmail.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mfd@lists.linux.dev \
/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
all inboxes | Powered by JetHome®