OSDN Git Service

RDMA: Simplify get firmware interface
authorLeon Romanovsky <leonro@mellanox.com>
Tue, 27 Jun 2017 13:49:53 +0000 (16:49 +0300)
committerLeon Romanovsky <leon@kernel.org>
Thu, 10 Aug 2017 10:28:10 +0000 (13:28 +0300)
There is a need to forward FW version to user space
application through RDMA netlink. In order to make it safe, there
is need to declare nla_policy and limit the size of FW string.

The new define IB_FW_VERSION_NAME_MAX will limit the size of
FW version string. That define was chosen to be equal to
ETHTOOL_FWVERS_LEN, because many drivers anyway are limited
by that value indirectly.

The introduction of this define allows us to remove the string size
from get_fw_str function signature.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
16 files changed:
drivers/infiniband/core/device.c
drivers/infiniband/core/sysfs.c
drivers/infiniband/hw/cxgb3/iwch_provider.c
drivers/infiniband/hw/cxgb4/provider.c
drivers/infiniband/hw/hfi1/verbs.c
drivers/infiniband/hw/i40iw/i40iw_verbs.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/mthca/mthca_provider.c
drivers/infiniband/hw/nes/nes_verbs.c
drivers/infiniband/hw/ocrdma/ocrdma_main.c
drivers/infiniband/hw/qedr/main.c
drivers/infiniband/hw/usnic/usnic_ib_main.c
drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c
drivers/infiniband/ulp/ipoib/ipoib_ethtool.c
include/rdma/ib_verbs.h

index 66b109b..fbc92c6 100644 (file)
@@ -336,10 +336,10 @@ static int read_port_immutable(struct ib_device *device)
        return 0;
 }
 
-void ib_get_device_fw_str(struct ib_device *dev, char *str, size_t str_len)
+void ib_get_device_fw_str(struct ib_device *dev, char *str)
 {
        if (dev->get_dev_fw_str)
-               dev->get_dev_fw_str(dev, str, str_len);
+               dev->get_dev_fw_str(dev, str);
        else
                str[0] = '\0';
 }
index 7ebe1ef..abc5ab5 100644 (file)
@@ -1210,8 +1210,8 @@ static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr,
 {
        struct ib_device *dev = container_of(device, struct ib_device, dev);
 
-       ib_get_device_fw_str(dev, buf, PAGE_SIZE);
-       strlcat(buf, "\n", PAGE_SIZE);
+       ib_get_device_fw_str(dev, buf);
+       strlcat(buf, "\n", IB_FW_VERSION_NAME_MAX);
        return strlen(buf);
 }
 
index 0cd0c1f..099e76f 100644 (file)
@@ -1336,8 +1336,7 @@ static int iwch_port_immutable(struct ib_device *ibdev, u8 port_num,
        return 0;
 }
 
-static void get_dev_fw_ver_str(struct ib_device *ibdev, char *str,
-                              size_t str_len)
+static void get_dev_fw_ver_str(struct ib_device *ibdev, char *str)
 {
        struct iwch_dev *iwch_dev = to_iwch_dev(ibdev);
        struct ethtool_drvinfo info;
@@ -1345,7 +1344,7 @@ static void get_dev_fw_ver_str(struct ib_device *ibdev, char *str,
 
        pr_debug("%s dev 0x%p\n", __func__, iwch_dev);
        lldev->ethtool_ops->get_drvinfo(lldev, &info);
-       snprintf(str, str_len, "%s", info.fw_version);
+       snprintf(str, IB_FW_VERSION_NAME_MAX, "%s", info.fw_version);
 }
 
 int iwch_register_device(struct iwch_dev *dev)
index 0771e9a..346e833 100644 (file)
@@ -517,14 +517,13 @@ static int c4iw_port_immutable(struct ib_device *ibdev, u8 port_num,
        return 0;
 }
 
-static void get_dev_fw_str(struct ib_device *dev, char *str,
-                          size_t str_len)
+static void get_dev_fw_str(struct ib_device *dev, char *str)
 {
        struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
                                                 ibdev);
        pr_debug("%s dev 0x%p\n", __func__, dev);
 
-       snprintf(str, str_len, "%u.%u.%u.%u",
+       snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u.%u",
                 FW_HDR_FW_VER_MAJOR_G(c4iw_dev->rdev.lldi.fw_vers),
                 FW_HDR_FW_VER_MINOR_G(c4iw_dev->rdev.lldi.fw_vers),
                 FW_HDR_FW_VER_MICRO_G(c4iw_dev->rdev.lldi.fw_vers),
index dc51bf2..c88c03c 100644 (file)
@@ -1561,14 +1561,13 @@ static void init_ibport(struct hfi1_pportdata *ppd)
        RCU_INIT_POINTER(ibp->rvp.qp[1], NULL);
 }
 
-static void hfi1_get_dev_fw_str(struct ib_device *ibdev, char *str,
-                               size_t str_len)
+static void hfi1_get_dev_fw_str(struct ib_device *ibdev, char *str)
 {
        struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
        struct hfi1_ibdev *dev = dev_from_rdi(rdi);
        u32 ver = dd_from_dev(dev)->dc8051_ver;
 
-       snprintf(str, str_len, "%u.%u.%u", dc8051_ver_maj(ver),
+       snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u", dc8051_ver_maj(ver),
                 dc8051_ver_min(ver), dc8051_ver_patch(ver));
 }
 
index 02d871d..1aa4110 100644 (file)
@@ -2584,13 +2584,12 @@ static const char * const i40iw_hw_stat_names[] = {
                "iwRdmaInv"
 };
 
-static void i40iw_get_dev_fw_str(struct ib_device *dev, char *str,
-                                size_t str_len)
+static void i40iw_get_dev_fw_str(struct ib_device *dev, char *str)
 {
        u32 firmware_version = I40IW_FW_VERSION;
 
-       snprintf(str, str_len, "%u.%u", firmware_version,
-                      (firmware_version & 0x000000ff));
+       snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u", firmware_version,
+                (firmware_version & 0x000000ff));
 }
 
 /**
index 1f25a37..c636842 100644 (file)
@@ -2587,12 +2587,11 @@ static int mlx4_port_immutable(struct ib_device *ibdev, u8 port_num,
        return 0;
 }
 
-static void get_fw_ver_str(struct ib_device *device, char *str,
-                          size_t str_len)
+static void get_fw_ver_str(struct ib_device *device, char *str)
 {
        struct mlx4_ib_dev *dev =
                container_of(device, struct mlx4_ib_dev, ib_dev);
-       snprintf(str, str_len, "%d.%d.%d",
+       snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%d",
                 (int) (dev->dev->caps.fw_ver >> 32),
                 (int) (dev->dev->caps.fw_ver >> 16) & 0xffff,
                 (int) dev->dev->caps.fw_ver & 0xffff);
index 9279631..0a5a4e3 100644 (file)
@@ -3285,13 +3285,13 @@ static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num,
        return 0;
 }
 
-static void get_dev_fw_str(struct ib_device *ibdev, char *str,
-                          size_t str_len)
+static void get_dev_fw_str(struct ib_device *ibdev, char *str)
 {
        struct mlx5_ib_dev *dev =
                container_of(ibdev, struct mlx5_ib_dev, ib_dev);
-       snprintf(str, str_len, "%d.%d.%04d", fw_rev_maj(dev->mdev),
-                      fw_rev_min(dev->mdev), fw_rev_sub(dev->mdev));
+       snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%04d",
+                fw_rev_maj(dev->mdev), fw_rev_min(dev->mdev),
+                fw_rev_sub(dev->mdev));
 }
 
 static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev)
index c197cd9..eae9bff 100644 (file)
@@ -1178,12 +1178,11 @@ static int mthca_port_immutable(struct ib_device *ibdev, u8 port_num,
        return 0;
 }
 
-static void get_dev_fw_str(struct ib_device *device, char *str,
-                          size_t str_len)
+static void get_dev_fw_str(struct ib_device *device, char *str)
 {
        struct mthca_dev *dev =
                container_of(device, struct mthca_dev, ib_dev);
-       snprintf(str, str_len, "%d.%d.%d",
+       snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%d",
                 (int) (dev->fw_ver >> 32),
                 (int) (dev->fw_ver >> 16) & 0xffff,
                 (int) dev->fw_ver & 0xffff);
index 25dcd75..c2943e3 100644 (file)
@@ -3672,15 +3672,14 @@ static int nes_port_immutable(struct ib_device *ibdev, u8 port_num,
        return 0;
 }
 
-static void get_dev_fw_str(struct ib_device *dev, char *str,
-                          size_t str_len)
+static void get_dev_fw_str(struct ib_device *dev, char *str)
 {
        struct nes_ib_device *nesibdev =
                        container_of(dev, struct nes_ib_device, ibdev);
        struct nes_vnic *nesvnic = nesibdev->nesvnic;
 
        nes_debug(NES_DBG_INIT, "\n");
-       snprintf(str, str_len, "%u.%u",
+       snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u",
                 (nesvnic->nesdev->nesadapter->firmware_version >> 16),
                 (nesvnic->nesdev->nesadapter->firmware_version & 0x000000ff));
 }
index 757c658..fbfbd9e 100644 (file)
@@ -107,12 +107,11 @@ static int ocrdma_port_immutable(struct ib_device *ibdev, u8 port_num,
        return 0;
 }
 
-static void get_dev_fw_str(struct ib_device *device, char *str,
-                          size_t str_len)
+static void get_dev_fw_str(struct ib_device *device, char *str)
 {
        struct ocrdma_dev *dev = get_ocrdma_dev(device);
 
-       snprintf(str, str_len, "%s", &dev->attr.fw_ver[0]);
+       snprintf(str, IB_FW_VERSION_NAME_MAX, "%s", &dev->attr.fw_ver[0]);
 }
 
 static int ocrdma_register_device(struct ocrdma_dev *dev)
index 199b6ed..97d033f 100644 (file)
@@ -68,13 +68,12 @@ static enum rdma_link_layer qedr_link_layer(struct ib_device *device,
        return IB_LINK_LAYER_ETHERNET;
 }
 
-static void qedr_get_dev_fw_str(struct ib_device *ibdev, char *str,
-                               size_t str_len)
+static void qedr_get_dev_fw_str(struct ib_device *ibdev, char *str)
 {
        struct qedr_dev *qedr = get_qedr_dev(ibdev);
        u32 fw_ver = (u32)qedr->attr.fw_ver;
 
-       snprintf(str, str_len, "%d. %d. %d. %d",
+       snprintf(str, IB_FW_VERSION_NAME_MAX, "%d. %d. %d. %d",
                 (fw_ver >> 24) & 0xFF, (fw_ver >> 16) & 0xFF,
                 (fw_ver >> 8) & 0xFF, fw_ver & 0xFF);
 }
index e69c8e4..e86700f 100644 (file)
@@ -333,9 +333,7 @@ static int usnic_port_immutable(struct ib_device *ibdev, u8 port_num,
        return 0;
 }
 
-static void usnic_get_dev_fw_str(struct ib_device *device,
-                                char *str,
-                                size_t str_len)
+static void usnic_get_dev_fw_str(struct ib_device *device, char *str)
 {
        struct usnic_ib_dev *us_ibdev =
                container_of(device, struct usnic_ib_dev, ib_dev);
@@ -345,7 +343,7 @@ static void usnic_get_dev_fw_str(struct ib_device *device,
        us_ibdev->netdev->ethtool_ops->get_drvinfo(us_ibdev->netdev, &info);
        mutex_unlock(&us_ibdev->usdev_lock);
 
-       snprintf(str, str_len, "%s", info.fw_version);
+       snprintf(str, IB_FW_VERSION_NAME_MAX, "%s", info.fw_version);
 }
 
 /* Start of PF discovery section */
index e765652..7f29e4d 100644 (file)
@@ -102,12 +102,11 @@ static struct device_attribute *pvrdma_class_attributes[] = {
        &dev_attr_board_id
 };
 
-static void pvrdma_get_fw_ver_str(struct ib_device *device, char *str,
-                                 size_t str_len)
+static void pvrdma_get_fw_ver_str(struct ib_device *device, char *str)
 {
        struct pvrdma_dev *dev =
                container_of(device, struct pvrdma_dev, ib_dev);
-       snprintf(str, str_len, "%d.%d.%d\n",
+       snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%d\n",
                 (int) (dev->dsr->caps.fw_ver >> 32),
                 (int) (dev->dsr->caps.fw_ver >> 16) & 0xffff,
                 (int) dev->dsr->caps.fw_ver & 0xffff);
index 7871379..98e30b4 100644 (file)
@@ -62,8 +62,7 @@ static void ipoib_get_drvinfo(struct net_device *netdev,
 {
        struct ipoib_dev_priv *priv = ipoib_priv(netdev);
 
-       ib_get_device_fw_str(priv->ca, drvinfo->fw_version,
-                            sizeof(drvinfo->fw_version));
+       ib_get_device_fw_str(priv->ca, drvinfo->fw_version);
 
        strlcpy(drvinfo->bus_info, dev_name(priv->ca->dev.parent),
                sizeof(drvinfo->bus_info));
index 3391df5..e0e87a1 100644 (file)
@@ -64,6 +64,8 @@
 #include <linux/cgroup_rdma.h>
 #include <uapi/rdma/ib_user_verbs.h>
 
+#define IB_FW_VERSION_NAME_MAX ETHTOOL_FWVERS_LEN
+
 extern struct workqueue_struct *ib_wq;
 extern struct workqueue_struct *ib_comp_wq;
 
@@ -2307,7 +2309,7 @@ struct ib_device {
         * in fast paths.
         */
        int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *);
-       void (*get_dev_fw_str)(struct ib_device *, char *str, size_t str_len);
+       void (*get_dev_fw_str)(struct ib_device *, char *str);
 };
 
 struct ib_client {
@@ -2343,7 +2345,7 @@ struct ib_client {
 struct ib_device *ib_alloc_device(size_t size);
 void ib_dealloc_device(struct ib_device *device);
 
-void ib_get_device_fw_str(struct ib_device *device, char *str, size_t str_len);
+void ib_get_device_fw_str(struct ib_device *device, char *str);
 
 int ib_register_device(struct ib_device *device,
                       int (*port_callback)(struct ib_device *,