From: Majd Dibbiny Date: Mon, 19 Aug 2013 15:19:23 +0000 (+0300) Subject: ib_core: Safely unregister mad agent when necessary. X-Git-Tag: v4.1.12-92~293^2~1^2~65 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=e6f8aedab6134bdfc736c5f3b535abe50418f3d1;p=users%2Fjedix%2Flinux-maple.git ib_core: Safely unregister mad agent when necessary. When the allocation of the receive buffer fails the driver needs to unregister the mad agent. The function ib_unregister_mad_agent doesn't check if the pointer of the mad agent is valid and doesn't contain an error and causes a Kernel Panic. Therefore, we need to check if the pointer of the mad agent is valid by calling PTR_ERR and only then unregister the agent. Signed-off-by: Majd Dibbiny (Ported from Mellanox OFED 2.4) Signed-off-by: Mukesh Kacker --- diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c index 4b759308ff3df..af878a71ee3fe 100644 --- a/drivers/infiniband/core/mad.c +++ b/drivers/infiniband/core/mad.c @@ -619,18 +619,21 @@ int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent) struct ib_mad_agent_private *mad_agent_priv; struct ib_mad_snoop_private *mad_snoop_priv; - /* If the TID is zero, the agent can only snoop. */ - if (mad_agent->hi_tid) { - mad_agent_priv = container_of(mad_agent, + if (!IS_ERR(mad_agent)) { + /* If the TID is zero, the agent can only snoop. */ + if (mad_agent->hi_tid) { + mad_agent_priv = container_of(mad_agent, struct ib_mad_agent_private, agent); - unregister_mad_agent(mad_agent_priv); - } else { - mad_snoop_priv = container_of(mad_agent, + unregister_mad_agent(mad_agent_priv); + } else { + mad_snoop_priv = container_of(mad_agent, struct ib_mad_snoop_private, agent); - unregister_mad_snoop(mad_snoop_priv); + unregister_mad_snoop(mad_snoop_priv); + } } + return 0; } EXPORT_SYMBOL(ib_unregister_mad_agent);