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