[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>

authored by Hal Rosenstock and committed by Roland Dreier 79d81907 2868bd28

+41 -47
+41 -47
drivers/infiniband/core/ucm.c
··· 49 49 MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access"); 50 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 57 enum { 53 58 IB_UCM_MAJOR = 231, 54 59 IB_UCM_MINOR = 255 55 60 }; 56 61 57 62 #define IB_UCM_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_MINOR) 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) 58 71 59 72 static struct semaphore ctx_id_mutex; 60 73 static struct idr ctx_id_table; ··· 120 107 121 108 up(&ctx->file->mutex); 122 109 123 - printk(KERN_ERR "UCM: Destroyed CM ID <%d>\n", ctx->id); 110 + ucm_dbg("Destroyed CM ID <%d>\n", ctx->id); 124 111 125 112 ib_destroy_cm_id(ctx->cm_id); 126 113 kfree(ctx); ··· 158 145 if (result) 159 146 goto error; 160 147 161 - printk(KERN_ERR "UCM: Allocated CM ID <%d>\n", ctx->id); 148 + ucm_dbg("Allocated CM ID <%d>\n", ctx->id); 162 149 163 150 return ctx; 164 151 error: ··· 391 378 392 379 return 0; 393 380 error: 394 - if (uvt->info) 395 - kfree(uvt->info); 396 - if (uvt->data) 397 - kfree(uvt->data); 381 + kfree(uvt->info); 382 + kfree(uvt->data); 398 383 return result; 399 384 } 400 385 ··· 418 407 break; 419 408 } 420 409 421 - printk(KERN_ERR "UCM: Event. CM ID <%d> event <%d>\n", 422 - id, event->event); 410 + ucm_dbg("Event. CM ID <%d> event <%d>\n", id, event->event); 423 411 424 412 ctx = ib_ucm_ctx_get(id); 425 413 if (!ctx) ··· 561 551 list_del(&uevent->file_list); 562 552 list_del(&uevent->ctx_list); 563 553 564 - if (uevent->data) 565 - kfree(uevent->data); 566 - if (uevent->info) 567 - kfree(uevent->info); 554 + kfree(uevent->data); 555 + kfree(uevent->info); 568 556 kfree(uevent); 569 557 done: 570 558 up(&file->mutex); ··· 854 846 up(&ctx->file->mutex); 855 847 ib_ucm_ctx_put(ctx); /* func reference */ 856 848 done: 857 - if (param.private_data) 858 - kfree(param.private_data); 859 - if (param.primary_path) 860 - kfree(param.primary_path); 861 - if (param.alternate_path) 862 - kfree(param.alternate_path); 849 + kfree(param.private_data); 850 + kfree(param.primary_path); 851 + kfree(param.alternate_path); 863 852 864 853 return result; 865 854 } ··· 905 900 up(&ctx->file->mutex); 906 901 ib_ucm_ctx_put(ctx); /* func reference */ 907 902 done: 908 - if (param.private_data) 909 - kfree(param.private_data); 903 + kfree(param.private_data); 910 904 911 905 return result; 912 906 } ··· 943 939 up(&ctx->file->mutex); 944 940 ib_ucm_ctx_put(ctx); /* func reference */ 945 941 done: 946 - if (private_data) 947 - kfree(private_data); 942 + kfree(private_data); 948 943 949 944 return result; 950 945 } ··· 1012 1009 up(&ctx->file->mutex); 1013 1010 ib_ucm_ctx_put(ctx); /* func reference */ 1014 1011 done: 1015 - if (data) 1016 - kfree(data); 1017 - if (info) 1018 - kfree(info); 1012 + kfree(data); 1013 + kfree(info); 1019 1014 1020 1015 return result; 1021 1016 } ··· 1064 1063 up(&ctx->file->mutex); 1065 1064 ib_ucm_ctx_put(ctx); /* func reference */ 1066 1065 done: 1067 - if (data) 1068 - kfree(data); 1066 + kfree(data); 1069 1067 1070 1068 return result; 1071 1069 } ··· 1105 1105 up(&ctx->file->mutex); 1106 1106 ib_ucm_ctx_put(ctx); /* func reference */ 1107 1107 done: 1108 - if (data) 1109 - kfree(data); 1110 - if (path) 1111 - kfree(path); 1108 + kfree(data); 1109 + kfree(path); 1112 1110 1113 1111 return result; 1114 1112 } ··· 1155 1157 up(&ctx->file->mutex); 1156 1158 ib_ucm_ctx_put(ctx); /* func reference */ 1157 1159 done: 1158 - if (param.private_data) 1159 - kfree(param.private_data); 1160 - if (param.path) 1161 - kfree(param.path); 1160 + kfree(param.private_data); 1161 + kfree(param.path); 1162 1162 1163 1163 return result; 1164 1164 } ··· 1205 1209 up(&ctx->file->mutex); 1206 1210 ib_ucm_ctx_put(ctx); /* func reference */ 1207 1211 done: 1208 - if (param.private_data) 1209 - kfree(param.private_data); 1210 - if (param.info) 1211 - kfree(param.info); 1212 + kfree(param.private_data); 1213 + kfree(param.info); 1212 1214 1213 1215 return result; 1214 1216 } ··· 1246 1252 if (copy_from_user(&hdr, buf, sizeof(hdr))) 1247 1253 return -EFAULT; 1248 1254 1249 - printk(KERN_ERR "UCM: Write. cmd <%d> in <%d> out <%d> len <%Zu>\n", 1250 - hdr.cmd, hdr.in, hdr.out, len); 1255 + ucm_dbg("Write. cmd <%d> in <%d> out <%d> len <%Zu>\n", 1256 + hdr.cmd, hdr.in, hdr.out, len); 1251 1257 1252 1258 if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table)) 1253 1259 return -EINVAL; ··· 1294 1300 filp->private_data = file; 1295 1301 file->filp = filp; 1296 1302 1297 - printk(KERN_ERR "UCM: Created struct\n"); 1303 + ucm_dbg("Created struct\n"); 1298 1304 1299 1305 return 0; 1300 1306 } ··· 1320 1326 1321 1327 kfree(file); 1322 1328 1323 - printk(KERN_ERR "UCM: Deleted struct\n"); 1329 + ucm_dbg("Deleted struct\n"); 1324 1330 return 0; 1325 1331 } 1326 1332 ··· 1342 1348 1343 1349 result = register_chrdev_region(IB_UCM_DEV, 1, "infiniband_cm"); 1344 1350 if (result) { 1345 - printk(KERN_ERR "UCM: Error <%d> registering dev\n", result); 1351 + ucm_dbg("Error <%d> registering dev\n", result); 1346 1352 goto err_chr; 1347 1353 } 1348 1354 ··· 1350 1356 1351 1357 result = cdev_add(&ib_ucm_cdev, IB_UCM_DEV, 1); 1352 1358 if (result) { 1353 - printk(KERN_ERR "UCM: Error <%d> adding cdev\n", result); 1359 + ucm_dbg("Error <%d> adding cdev\n", result); 1354 1360 goto err_cdev; 1355 1361 } 1356 1362 1357 1363 ib_ucm_class = class_create(THIS_MODULE, "infiniband_cm"); 1358 1364 if (IS_ERR(ib_ucm_class)) { 1359 1365 result = PTR_ERR(ib_ucm_class); 1360 - printk(KERN_ERR "UCM: Error <%d> creating class\n", result); 1366 + ucm_dbg("Error <%d> creating class\n", result); 1361 1367 goto err_class; 1362 1368 } 1363 1369