Skip to content

Commit ff2d2bc

Browse files
committed
ipmi:msghandler: Don't acquire a user refcount for queued messages
Messages already have a refcount for the user, so there's no need to account for a new one. As part of this, grab a refcount to the interface when processing received messages. The messages can be freed there, cause the user then the interface to be freed. Signed-off-by: Corey Minyard <[email protected]>
1 parent 84fe1eb commit ff2d2bc

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

drivers/char/ipmi/ipmi_msghandler.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -958,20 +958,14 @@ static int deliver_response(struct ipmi_smi *intf, struct ipmi_recv_msg *msg)
958958
ipmi_free_recv_msg(msg);
959959
atomic_dec(&msg->user->nr_msgs);
960960
} else {
961-
struct ipmi_user *user = acquire_ipmi_user(msg->user);
962-
963-
if (user) {
964-
/* Deliver it in smi_work. */
965-
mutex_lock(&intf->user_msgs_mutex);
966-
list_add_tail(&msg->link, &intf->user_msgs);
967-
mutex_unlock(&intf->user_msgs_mutex);
968-
queue_work(system_wq, &intf->smi_work);
969-
/* User release will happen in the work queue. */
970-
} else {
971-
/* User went away, give up. */
972-
ipmi_free_recv_msg(msg);
973-
rv = -EINVAL;
974-
}
961+
/*
962+
* Deliver it in smi_work. The message will hold a
963+
* refcount to the user.
964+
*/
965+
mutex_lock(&intf->user_msgs_mutex);
966+
list_add_tail(&msg->link, &intf->user_msgs);
967+
mutex_unlock(&intf->user_msgs_mutex);
968+
queue_work(system_wq, &intf->smi_work);
975969
}
976970

977971
return rv;
@@ -4827,16 +4821,24 @@ static void smi_work(struct work_struct *t)
48274821
mutex_unlock(&intf->users_mutex);
48284822
}
48294823

4824+
/*
4825+
* Freeing the message can cause a user to be released, which
4826+
* can then cause the interface to be freed. Make sure that
4827+
* doesn't happen until we are ready.
4828+
*/
4829+
kref_get(&intf->refcount);
4830+
48304831
mutex_lock(&intf->user_msgs_mutex);
48314832
list_for_each_entry_safe(msg, msg2, &intf->user_msgs, link) {
48324833
struct ipmi_user *user = msg->user;
48334834

48344835
list_del(&msg->link);
48354836
atomic_dec(&user->nr_msgs);
48364837
user->handler->ipmi_recv_hndl(msg, user->handler_data);
4837-
release_ipmi_user(user);
48384838
}
48394839
mutex_unlock(&intf->user_msgs_mutex);
4840+
4841+
kref_put(&intf->refcount, intf_free);
48404842
}
48414843

48424844
/* Handle a new message from the lower layer. */

0 commit comments

Comments
 (0)