IB/srpt: Support HCAs with more than two ports
authorBart Van Assche <bart.vanassche@wdc.com>
Tue, 26 Jun 2018 22:24:48 +0000 (15:24 -0700)
committerJason Gunthorpe <jgg@mellanox.com>
Fri, 29 Jun 2018 20:35:45 +0000 (14:35 -0600)
Since there are adapters that have four ports, increase the size of
the srpt_device.port[] array. This patch avoids that the following
warning is hit with quad port Chelsio adapters:

    WARN_ON(sdev->device->phys_port_cnt > ARRAY_SIZE(sdev->port));

Reported-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Steve Wise <swise@opengridcomputing.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: <stable@vger.kernel.org>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/ulp/srpt/ib_srpt.c
drivers/infiniband/ulp/srpt/ib_srpt.h

index 1b0b285a0ae021794915d8950f7ab6b62e7cb74b..36d9fab7c998004971a00878802fbdf931007bb7 100644 (file)
@@ -2970,7 +2970,8 @@ static void srpt_add_one(struct ib_device *device)
 
        pr_debug("device = %p\n", device);
 
-       sdev = kzalloc(sizeof(*sdev), GFP_KERNEL);
+       sdev = kzalloc(struct_size(sdev, port, device->phys_port_cnt),
+                      GFP_KERNEL);
        if (!sdev)
                goto err;
 
@@ -3024,8 +3025,6 @@ static void srpt_add_one(struct ib_device *device)
                              srpt_event_handler);
        ib_register_event_handler(&sdev->event_handler);
 
-       WARN_ON(sdev->device->phys_port_cnt > ARRAY_SIZE(sdev->port));
-
        for (i = 1; i <= sdev->device->phys_port_cnt; i++) {
                sport = &sdev->port[i - 1];
                INIT_LIST_HEAD(&sport->nexus_list);
index 2361483476a0252663c35eef7f7b5ae7911ef424..444dfd7281b5fe774afc839cc3c9cced02642878 100644 (file)
@@ -396,9 +396,9 @@ struct srpt_port {
  * @sdev_mutex:           Serializes use_srq changes.
  * @use_srq:       Whether or not to use SRQ.
  * @ioctx_ring:    Per-HCA SRQ.
- * @port:          Information about the ports owned by this HCA.
  * @event_handler: Per-HCA asynchronous IB event handler.
  * @list:          Node in srpt_dev_list.
+ * @port:          Information about the ports owned by this HCA.
  */
 struct srpt_device {
        struct ib_device        *device;
@@ -410,9 +410,9 @@ struct srpt_device {
        struct mutex            sdev_mutex;
        bool                    use_srq;
        struct srpt_recv_ioctx  **ioctx_ring;
-       struct srpt_port        port[2];
        struct ib_event_handler event_handler;
        struct list_head        list;
+       struct srpt_port        port[];
 };
 
 #endif                         /* IB_SRPT_H */