Skip to contentSkip to conversation

char:ipmi: Free ipmi_recv_msg messages from the linked list,recv_msgs for the function,ipmi_release in the file,ipmi_devintf.c

PATCH Corey Minyard 2 participants 2 messages Jan 23, 2015 – Jan 24, 2015 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 3 lines · nick

Corney,
Hope this patch fixes the issue. Sorry about missing that kfree being required. :(

Well, the kfree needs to be after the free of the messages. You can't
use an item after you free it.

-corey

Quoted 42 lines

Nick

Quoted 38 lines · Nicholas Krause

This adds a loop through the elements in the linked list, recv_msgs using list_for_entry_safe in order to free messages in this list. In addition we are using the safe version of this marco in order to prevent use after bugs related to deleting the element we are on currently by holding a pointer to the next element after the current one we are on and freeing with the function, ipmi_free_recv_msg internally in this loop.

---
 drivers/char/ipmi/ipmi_devintf.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/char/ipmi/ipmi_devintf.c +6 -1
index ec318bf..a625510 100644
@@ -157,14 +157,19 @@ static int ipmi_release(struct inode *inode, struct file *file)
 {
 	struct ipmi_file_private *priv = file->private_data;
 	int                      rv;
+	struct  ipmi_recv_msg *msg, *next;
 
 	rv = ipmi_destroy_user(priv->user);
 	if (rv)
 		return rv;
 
-	/* FIXME - free the messages in the list. */
 	kfree(priv);
 
+	list_for_each_entry_safe(msg, next, &priv->recv_msgs, link) {
+		ipmi_free_recv_msg(msg);
+	}
+
+
 	return 0;
 }
 
#3 lore raw
Quoted 6 lines · Corey Minyard
Quoted 3 lines · nick
Quoted 3 lines

Corney,
Hope this patch fixes the issue. Sorry about missing that kfree being required. :(

Well, the kfree needs to be after the free of the messages. You can't
use an item after you free it.

As you can see, his patches aren't event tested. See https://lkml.org/lkml/2014/8/4/206 .

Thanks,
Sasha