From: Majd Dibbiny <[email protected]>

When ib_register_mad_agent fails, it returns a pointer with error which is not
NULL, therefore when calling ib_unregister_mad_agent we need to check that the
passed mad_agent is valid and not erroneous.

Signed-off-by: Majd Dibbiny <[email protected]>
Signed-off-by: Or Gerlitz <[email protected]>
---
 drivers/infiniband/core/mad.c |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index 74c30f4..13c5c47 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,
-                                             struct ib_mad_agent_private,
-                                             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);
+       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,
+                                                     struct 
ib_mad_snoop_private,
+                                                     agent);
+                       unregister_mad_snoop(mad_snoop_priv);
+               }
        }
+
        return 0;
 }
 EXPORT_SYMBOL(ib_unregister_mad_agent);
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to