diff options
author | Hal Rosenstock <halr@voltaire.com> | 2005-07-27 23:38:56 -0400 |
---|---|---|
committer | Roland Dreier <roland@eddore.topspincom.com> | 2005-07-27 23:38:56 -0400 |
commit | 79d81907594e1ec4d5171653dde7cb9e9cb87de2 (patch) | |
tree | d3f99de8a2a5e382ecbcbe1a1a8d411dc6071ef0 /drivers/infiniband | |
parent | 2868bd281fef21d1e73d6b7648a41efc3d75f10c (diff) |
[IB/ucm]: Clean up userspace CM
Only print debug messages when debug_level is set.
Eliminate NULL checks prior to calling kfree.
Signed-off-by: Hal Rosenstock <halr@voltaire.com>
Signed-off-by: Libor Michalek <libor@topspin.com>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r-- | drivers/infiniband/core/ucm.c | 88 |
1 files changed, 41 insertions, 47 deletions
diff --git a/drivers/infiniband/core/ucm.c b/drivers/infiniband/core/ucm.c index 546ec61c407f..61d07c732f49 100644 --- a/drivers/infiniband/core/ucm.c +++ b/drivers/infiniband/core/ucm.c | |||
@@ -49,6 +49,11 @@ MODULE_AUTHOR("Libor Michalek"); | |||
49 | MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access"); | 49 | MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access"); |
50 | MODULE_LICENSE("Dual BSD/GPL"); | 50 | MODULE_LICENSE("Dual BSD/GPL"); |
51 | 51 | ||
52 | static int ucm_debug_level; | ||
53 | |||
54 | module_param_named(debug_level, ucm_debug_level, int, 0644); | ||
55 | MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0"); | ||
56 | |||
52 | enum { | 57 | enum { |
53 | IB_UCM_MAJOR = 231, | 58 | IB_UCM_MAJOR = 231, |
54 | IB_UCM_MINOR = 255 | 59 | IB_UCM_MINOR = 255 |
@@ -56,6 +61,14 @@ enum { | |||
56 | 61 | ||
57 | #define IB_UCM_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_MINOR) | 62 | #define IB_UCM_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_MINOR) |
58 | 63 | ||
64 | #define PFX "UCM: " | ||
65 | |||
66 | #define ucm_dbg(format, arg...) \ | ||
67 | do { \ | ||
68 | if (ucm_debug_level > 0) \ | ||
69 | printk(KERN_DEBUG PFX format, ## arg); \ | ||
70 | } while (0) | ||
71 | |||
59 | static struct semaphore ctx_id_mutex; | 72 | static struct semaphore ctx_id_mutex; |
60 | static struct idr ctx_id_table; | 73 | static struct idr ctx_id_table; |
61 | static int ctx_id_rover = 0; | 74 | static int ctx_id_rover = 0; |
@@ -107,7 +120,7 @@ static void ib_ucm_ctx_put(struct ib_ucm_context *ctx) | |||
107 | 120 | ||
108 | up(&ctx->file->mutex); | 121 | up(&ctx->file->mutex); |
109 | 122 | ||
110 | printk(KERN_ERR "UCM: Destroyed CM ID <%d>\n", ctx->id); | 123 | ucm_dbg("Destroyed CM ID <%d>\n", ctx->id); |
111 | 124 | ||
112 | ib_destroy_cm_id(ctx->cm_id); | 125 | ib_destroy_cm_id(ctx->cm_id); |
113 | kfree(ctx); | 126 | kfree(ctx); |
@@ -145,7 +158,7 @@ retry: | |||
145 | if (result) | 158 | if (result) |
146 | goto error; | 159 | goto error; |
147 | 160 | ||
148 | printk(KERN_ERR "UCM: Allocated CM ID <%d>\n", ctx->id); | 161 | ucm_dbg("Allocated CM ID <%d>\n", ctx->id); |
149 | 162 | ||
150 | return ctx; | 163 | return ctx; |
151 | error: | 164 | error: |
@@ -378,10 +391,8 @@ static int ib_ucm_event_process(struct ib_cm_event *evt, | |||
378 | 391 | ||
379 | return 0; | 392 | return 0; |
380 | error: | 393 | error: |
381 | if (uvt->info) | 394 | kfree(uvt->info); |
382 | kfree(uvt->info); | 395 | kfree(uvt->data); |
383 | if (uvt->data) | ||
384 | kfree(uvt->data); | ||
385 | return result; | 396 | return result; |
386 | } | 397 | } |
387 | 398 | ||
@@ -407,8 +418,7 @@ static int ib_ucm_event_handler(struct ib_cm_id *cm_id, | |||
407 | break; | 418 | break; |
408 | } | 419 | } |
409 | 420 | ||
410 | printk(KERN_ERR "UCM: Event. CM ID <%d> event <%d>\n", | 421 | ucm_dbg("Event. CM ID <%d> event <%d>\n", id, event->event); |
411 | id, event->event); | ||
412 | 422 | ||
413 | ctx = ib_ucm_ctx_get(id); | 423 | ctx = ib_ucm_ctx_get(id); |
414 | if (!ctx) | 424 | if (!ctx) |
@@ -551,10 +561,8 @@ user: | |||
551 | list_del(&uevent->file_list); | 561 | list_del(&uevent->file_list); |
552 | list_del(&uevent->ctx_list); | 562 | list_del(&uevent->ctx_list); |
553 | 563 | ||
554 | if (uevent->data) | 564 | kfree(uevent->data); |
555 | kfree(uevent->data); | 565 | kfree(uevent->info); |
556 | if (uevent->info) | ||
557 | kfree(uevent->info); | ||
558 | kfree(uevent); | 566 | kfree(uevent); |
559 | done: | 567 | done: |
560 | up(&file->mutex); | 568 | up(&file->mutex); |
@@ -846,12 +854,9 @@ static ssize_t ib_ucm_send_req(struct ib_ucm_file *file, | |||
846 | up(&ctx->file->mutex); | 854 | up(&ctx->file->mutex); |
847 | ib_ucm_ctx_put(ctx); /* func reference */ | 855 | ib_ucm_ctx_put(ctx); /* func reference */ |
848 | done: | 856 | done: |
849 | if (param.private_data) | 857 | kfree(param.private_data); |
850 | kfree(param.private_data); | 858 | kfree(param.primary_path); |
851 | if (param.primary_path) | 859 | kfree(param.alternate_path); |
852 | kfree(param.primary_path); | ||
853 | if (param.alternate_path) | ||
854 | kfree(param.alternate_path); | ||
855 | 860 | ||
856 | return result; | 861 | return result; |
857 | } | 862 | } |
@@ -900,8 +905,7 @@ static ssize_t ib_ucm_send_rep(struct ib_ucm_file *file, | |||
900 | up(&ctx->file->mutex); | 905 | up(&ctx->file->mutex); |
901 | ib_ucm_ctx_put(ctx); /* func reference */ | 906 | ib_ucm_ctx_put(ctx); /* func reference */ |
902 | done: | 907 | done: |
903 | if (param.private_data) | 908 | kfree(param.private_data); |
904 | kfree(param.private_data); | ||
905 | 909 | ||
906 | return result; | 910 | return result; |
907 | } | 911 | } |
@@ -939,8 +943,7 @@ static ssize_t ib_ucm_send_private_data(struct ib_ucm_file *file, | |||
939 | up(&ctx->file->mutex); | 943 | up(&ctx->file->mutex); |
940 | ib_ucm_ctx_put(ctx); /* func reference */ | 944 | ib_ucm_ctx_put(ctx); /* func reference */ |
941 | done: | 945 | done: |
942 | if (private_data) | 946 | kfree(private_data); |
943 | kfree(private_data); | ||
944 | 947 | ||
945 | return result; | 948 | return result; |
946 | } | 949 | } |
@@ -1009,10 +1012,8 @@ static ssize_t ib_ucm_send_info(struct ib_ucm_file *file, | |||
1009 | up(&ctx->file->mutex); | 1012 | up(&ctx->file->mutex); |
1010 | ib_ucm_ctx_put(ctx); /* func reference */ | 1013 | ib_ucm_ctx_put(ctx); /* func reference */ |
1011 | done: | 1014 | done: |
1012 | if (data) | 1015 | kfree(data); |
1013 | kfree(data); | 1016 | kfree(info); |
1014 | if (info) | ||
1015 | kfree(info); | ||
1016 | 1017 | ||
1017 | return result; | 1018 | return result; |
1018 | } | 1019 | } |
@@ -1063,8 +1064,7 @@ static ssize_t ib_ucm_send_mra(struct ib_ucm_file *file, | |||
1063 | up(&ctx->file->mutex); | 1064 | up(&ctx->file->mutex); |
1064 | ib_ucm_ctx_put(ctx); /* func reference */ | 1065 | ib_ucm_ctx_put(ctx); /* func reference */ |
1065 | done: | 1066 | done: |
1066 | if (data) | 1067 | kfree(data); |
1067 | kfree(data); | ||
1068 | 1068 | ||
1069 | return result; | 1069 | return result; |
1070 | } | 1070 | } |
@@ -1105,10 +1105,8 @@ static ssize_t ib_ucm_send_lap(struct ib_ucm_file *file, | |||
1105 | up(&ctx->file->mutex); | 1105 | up(&ctx->file->mutex); |
1106 | ib_ucm_ctx_put(ctx); /* func reference */ | 1106 | ib_ucm_ctx_put(ctx); /* func reference */ |
1107 | done: | 1107 | done: |
1108 | if (data) | 1108 | kfree(data); |
1109 | kfree(data); | 1109 | kfree(path); |
1110 | if (path) | ||
1111 | kfree(path); | ||
1112 | 1110 | ||
1113 | return result; | 1111 | return result; |
1114 | } | 1112 | } |
@@ -1157,10 +1155,8 @@ static ssize_t ib_ucm_send_sidr_req(struct ib_ucm_file *file, | |||
1157 | up(&ctx->file->mutex); | 1155 | up(&ctx->file->mutex); |
1158 | ib_ucm_ctx_put(ctx); /* func reference */ | 1156 | ib_ucm_ctx_put(ctx); /* func reference */ |
1159 | done: | 1157 | done: |
1160 | if (param.private_data) | 1158 | kfree(param.private_data); |
1161 | kfree(param.private_data); | 1159 | kfree(param.path); |
1162 | if (param.path) | ||
1163 | kfree(param.path); | ||
1164 | 1160 | ||
1165 | return result; | 1161 | return result; |
1166 | } | 1162 | } |
@@ -1209,10 +1205,8 @@ static ssize_t ib_ucm_send_sidr_rep(struct ib_ucm_file *file, | |||
1209 | up(&ctx->file->mutex); | 1205 | up(&ctx->file->mutex); |
1210 | ib_ucm_ctx_put(ctx); /* func reference */ | 1206 | ib_ucm_ctx_put(ctx); /* func reference */ |
1211 | done: | 1207 | done: |
1212 | if (param.private_data) | 1208 | kfree(param.private_data); |
1213 | kfree(param.private_data); | 1209 | kfree(param.info); |
1214 | if (param.info) | ||
1215 | kfree(param.info); | ||
1216 | 1210 | ||
1217 | return result; | 1211 | return result; |
1218 | } | 1212 | } |
@@ -1252,8 +1246,8 @@ static ssize_t ib_ucm_write(struct file *filp, const char __user *buf, | |||
1252 | if (copy_from_user(&hdr, buf, sizeof(hdr))) | 1246 | if (copy_from_user(&hdr, buf, sizeof(hdr))) |
1253 | return -EFAULT; | 1247 | return -EFAULT; |
1254 | 1248 | ||
1255 | printk(KERN_ERR "UCM: Write. cmd <%d> in <%d> out <%d> len <%Zu>\n", | 1249 | ucm_dbg("Write. cmd <%d> in <%d> out <%d> len <%Zu>\n", |
1256 | hdr.cmd, hdr.in, hdr.out, len); | 1250 | hdr.cmd, hdr.in, hdr.out, len); |
1257 | 1251 | ||
1258 | if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table)) | 1252 | if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table)) |
1259 | return -EINVAL; | 1253 | return -EINVAL; |
@@ -1300,7 +1294,7 @@ static int ib_ucm_open(struct inode *inode, struct file *filp) | |||
1300 | filp->private_data = file; | 1294 | filp->private_data = file; |
1301 | file->filp = filp; | 1295 | file->filp = filp; |
1302 | 1296 | ||
1303 | printk(KERN_ERR "UCM: Created struct\n"); | 1297 | ucm_dbg("Created struct\n"); |
1304 | 1298 | ||
1305 | return 0; | 1299 | return 0; |
1306 | } | 1300 | } |
@@ -1326,7 +1320,7 @@ static int ib_ucm_close(struct inode *inode, struct file *filp) | |||
1326 | 1320 | ||
1327 | kfree(file); | 1321 | kfree(file); |
1328 | 1322 | ||
1329 | printk(KERN_ERR "UCM: Deleted struct\n"); | 1323 | ucm_dbg("Deleted struct\n"); |
1330 | return 0; | 1324 | return 0; |
1331 | } | 1325 | } |
1332 | 1326 | ||
@@ -1348,7 +1342,7 @@ static int __init ib_ucm_init(void) | |||
1348 | 1342 | ||
1349 | result = register_chrdev_region(IB_UCM_DEV, 1, "infiniband_cm"); | 1343 | result = register_chrdev_region(IB_UCM_DEV, 1, "infiniband_cm"); |
1350 | if (result) { | 1344 | if (result) { |
1351 | printk(KERN_ERR "UCM: Error <%d> registering dev\n", result); | 1345 | ucm_dbg("Error <%d> registering dev\n", result); |
1352 | goto err_chr; | 1346 | goto err_chr; |
1353 | } | 1347 | } |
1354 | 1348 | ||
@@ -1356,14 +1350,14 @@ static int __init ib_ucm_init(void) | |||
1356 | 1350 | ||
1357 | result = cdev_add(&ib_ucm_cdev, IB_UCM_DEV, 1); | 1351 | result = cdev_add(&ib_ucm_cdev, IB_UCM_DEV, 1); |
1358 | if (result) { | 1352 | if (result) { |
1359 | printk(KERN_ERR "UCM: Error <%d> adding cdev\n", result); | 1353 | ucm_dbg("Error <%d> adding cdev\n", result); |
1360 | goto err_cdev; | 1354 | goto err_cdev; |
1361 | } | 1355 | } |
1362 | 1356 | ||
1363 | ib_ucm_class = class_create(THIS_MODULE, "infiniband_cm"); | 1357 | ib_ucm_class = class_create(THIS_MODULE, "infiniband_cm"); |
1364 | if (IS_ERR(ib_ucm_class)) { | 1358 | if (IS_ERR(ib_ucm_class)) { |
1365 | result = PTR_ERR(ib_ucm_class); | 1359 | result = PTR_ERR(ib_ucm_class); |
1366 | printk(KERN_ERR "UCM: Error <%d> creating class\n", result); | 1360 | ucm_dbg("Error <%d> creating class\n", result); |
1367 | goto err_class; | 1361 | goto err_class; |
1368 | } | 1362 | } |
1369 | 1363 | ||