aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/core/sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/infiniband/core/sysfs.c')
-rw-r--r--drivers/infiniband/core/sysfs.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 5e573bb18660..a5793c8f1590 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -889,9 +889,9 @@ static struct attribute *alloc_hsa_lifespan(char *name, u8 port_num)
889static void setup_hw_stats(struct ib_device *device, struct ib_port *port, 889static void setup_hw_stats(struct ib_device *device, struct ib_port *port,
890 u8 port_num) 890 u8 port_num)
891{ 891{
892 struct attribute_group *hsag = NULL; 892 struct attribute_group *hsag;
893 struct rdma_hw_stats *stats; 893 struct rdma_hw_stats *stats;
894 int i = 0, ret; 894 int i, ret;
895 895
896 stats = device->alloc_hw_stats(device, port_num); 896 stats = device->alloc_hw_stats(device, port_num);
897 897
@@ -899,19 +899,22 @@ static void setup_hw_stats(struct ib_device *device, struct ib_port *port,
899 return; 899 return;
900 900
901 if (!stats->names || stats->num_counters <= 0) 901 if (!stats->names || stats->num_counters <= 0)
902 goto err; 902 goto err_free_stats;
903 903
904 /*
905 * Two extra attribue elements here, one for the lifespan entry and
906 * one to NULL terminate the list for the sysfs core code
907 */
904 hsag = kzalloc(sizeof(*hsag) + 908 hsag = kzalloc(sizeof(*hsag) +
905 // 1 extra for the lifespan config entry 909 sizeof(void *) * (stats->num_counters + 2),
906 sizeof(void *) * (stats->num_counters + 1),
907 GFP_KERNEL); 910 GFP_KERNEL);
908 if (!hsag) 911 if (!hsag)
909 return; 912 goto err_free_stats;
910 913
911 ret = device->get_hw_stats(device, stats, port_num, 914 ret = device->get_hw_stats(device, stats, port_num,
912 stats->num_counters); 915 stats->num_counters);
913 if (ret != stats->num_counters) 916 if (ret != stats->num_counters)
914 goto err; 917 goto err_free_hsag;
915 918
916 stats->timestamp = jiffies; 919 stats->timestamp = jiffies;
917 920
@@ -922,10 +925,13 @@ static void setup_hw_stats(struct ib_device *device, struct ib_port *port,
922 hsag->attrs[i] = alloc_hsa(i, port_num, stats->names[i]); 925 hsag->attrs[i] = alloc_hsa(i, port_num, stats->names[i]);
923 if (!hsag->attrs[i]) 926 if (!hsag->attrs[i])
924 goto err; 927 goto err;
928 sysfs_attr_init(hsag->attrs[i]);
925 } 929 }
926 930
927 /* treat an error here as non-fatal */ 931 /* treat an error here as non-fatal */
928 hsag->attrs[i] = alloc_hsa_lifespan("lifespan", port_num); 932 hsag->attrs[i] = alloc_hsa_lifespan("lifespan", port_num);
933 if (hsag->attrs[i])
934 sysfs_attr_init(hsag->attrs[i]);
929 935
930 if (port) { 936 if (port) {
931 struct kobject *kobj = &port->kobj; 937 struct kobject *kobj = &port->kobj;
@@ -946,10 +952,12 @@ static void setup_hw_stats(struct ib_device *device, struct ib_port *port,
946 return; 952 return;
947 953
948err: 954err:
949 kfree(stats);
950 for (; i >= 0; i--) 955 for (; i >= 0; i--)
951 kfree(hsag->attrs[i]); 956 kfree(hsag->attrs[i]);
957err_free_hsag:
952 kfree(hsag); 958 kfree(hsag);
959err_free_stats:
960 kfree(stats);
953 return; 961 return;
954} 962}
955 963