RDMA/mad: Convert BUG_ONs to error flows
authorLeon Romanovsky <leonro@mellanox.com>
Tue, 29 May 2018 11:56:19 +0000 (14:56 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 3 Aug 2018 05:55:14 +0000 (07:55 +0200)
[ Upstream commit 2468b82d69e3a53d024f28d79ba0fdb8bf43dfbf ]

Let's perform checks in-place instead of BUG_ONs.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/infiniband/core/mad.c

index 2395fe2021c96102fd190f57344729fc8ee7c70e..3e2ab04201e2c611bb5d3b3a9fdfb832f40e5b01 100644 (file)
@@ -1549,7 +1549,8 @@ static int add_oui_reg_req(struct ib_mad_reg_req *mad_reg_req,
                            mad_reg_req->oui, 3)) {
                        method = &(*vendor_table)->vendor_class[
                                                vclass]->method_table[i];
-                       BUG_ON(!*method);
+                       if (!*method)
+                               goto error3;
                        goto check_in_use;
                }
        }
@@ -1559,10 +1560,12 @@ static int add_oui_reg_req(struct ib_mad_reg_req *mad_reg_req,
                                vclass]->oui[i])) {
                        method = &(*vendor_table)->vendor_class[
                                vclass]->method_table[i];
-                       BUG_ON(*method);
                        /* Allocate method table for this OUI */
-                       if ((ret = allocate_method_table(method)))
-                               goto error3;
+                       if (!*method) {
+                               ret = allocate_method_table(method);
+                               if (ret)
+                                       goto error3;
+                       }
                        memcpy((*vendor_table)->vendor_class[vclass]->oui[i],
                               mad_reg_req->oui, 3);
                        goto check_in_use;