Commit 79d81907 authored by Hal Rosenstock's avatar Hal Rosenstock Committed by Roland Dreier

[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: default avatarHal Rosenstock <halr@voltaire.com>
Signed-off-by: default avatarLibor Michalek <libor@topspin.com>
parent 2868bd28
...@@ -49,6 +49,11 @@ MODULE_AUTHOR("Libor Michalek"); ...@@ -49,6 +49,11 @@ MODULE_AUTHOR("Libor Michalek");
MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access"); MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access");
MODULE_LICENSE("Dual BSD/GPL"); MODULE_LICENSE("Dual BSD/GPL");
static int ucm_debug_level;
module_param_named(debug_level, ucm_debug_level, int, 0644);
MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
enum { enum {
IB_UCM_MAJOR = 231, IB_UCM_MAJOR = 231,
IB_UCM_MINOR = 255 IB_UCM_MINOR = 255
...@@ -56,6 +61,14 @@ enum { ...@@ -56,6 +61,14 @@ enum {
#define IB_UCM_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_MINOR) #define IB_UCM_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_MINOR)
#define PFX "UCM: "
#define ucm_dbg(format, arg...) \
do { \
if (ucm_debug_level > 0) \
printk(KERN_DEBUG PFX format, ## arg); \
} while (0)
static struct semaphore ctx_id_mutex; static struct semaphore ctx_id_mutex;
static struct idr ctx_id_table; static struct idr ctx_id_table;
static int ctx_id_rover = 0; static int ctx_id_rover = 0;
...@@ -107,7 +120,7 @@ static void ib_ucm_ctx_put(struct ib_ucm_context *ctx) ...@@ -107,7 +120,7 @@ static void ib_ucm_ctx_put(struct ib_ucm_context *ctx)
up(&ctx->file->mutex); up(&ctx->file->mutex);
printk(KERN_ERR "UCM: Destroyed CM ID <%d>\n", ctx->id); ucm_dbg("Destroyed CM ID <%d>\n", ctx->id);
ib_destroy_cm_id(ctx->cm_id); ib_destroy_cm_id(ctx->cm_id);
kfree(ctx); kfree(ctx);
...@@ -145,7 +158,7 @@ static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file) ...@@ -145,7 +158,7 @@ static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)
if (result) if (result)
goto error; goto error;
printk(KERN_ERR "UCM: Allocated CM ID <%d>\n", ctx->id); ucm_dbg("Allocated CM ID <%d>\n", ctx->id);
return ctx; return ctx;
error: error:
...@@ -378,9 +391,7 @@ static int ib_ucm_event_process(struct ib_cm_event *evt, ...@@ -378,9 +391,7 @@ static int ib_ucm_event_process(struct ib_cm_event *evt,
return 0; return 0;
error: error:
if (uvt->info)
kfree(uvt->info); kfree(uvt->info);
if (uvt->data)
kfree(uvt->data); kfree(uvt->data);
return result; return result;
} }
...@@ -407,8 +418,7 @@ static int ib_ucm_event_handler(struct ib_cm_id *cm_id, ...@@ -407,8 +418,7 @@ static int ib_ucm_event_handler(struct ib_cm_id *cm_id,
break; break;
} }
printk(KERN_ERR "UCM: Event. CM ID <%d> event <%d>\n", ucm_dbg("Event. CM ID <%d> event <%d>\n", id, event->event);
id, event->event);
ctx = ib_ucm_ctx_get(id); ctx = ib_ucm_ctx_get(id);
if (!ctx) if (!ctx)
...@@ -551,9 +561,7 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file, ...@@ -551,9 +561,7 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file,
list_del(&uevent->file_list); list_del(&uevent->file_list);
list_del(&uevent->ctx_list); list_del(&uevent->ctx_list);
if (uevent->data)
kfree(uevent->data); kfree(uevent->data);
if (uevent->info)
kfree(uevent->info); kfree(uevent->info);
kfree(uevent); kfree(uevent);
done: done:
...@@ -846,11 +854,8 @@ static ssize_t ib_ucm_send_req(struct ib_ucm_file *file, ...@@ -846,11 +854,8 @@ static ssize_t ib_ucm_send_req(struct ib_ucm_file *file,
up(&ctx->file->mutex); up(&ctx->file->mutex);
ib_ucm_ctx_put(ctx); /* func reference */ ib_ucm_ctx_put(ctx); /* func reference */
done: done:
if (param.private_data)
kfree(param.private_data); kfree(param.private_data);
if (param.primary_path)
kfree(param.primary_path); kfree(param.primary_path);
if (param.alternate_path)
kfree(param.alternate_path); kfree(param.alternate_path);
return result; return result;
...@@ -900,7 +905,6 @@ static ssize_t ib_ucm_send_rep(struct ib_ucm_file *file, ...@@ -900,7 +905,6 @@ static ssize_t ib_ucm_send_rep(struct ib_ucm_file *file,
up(&ctx->file->mutex); up(&ctx->file->mutex);
ib_ucm_ctx_put(ctx); /* func reference */ ib_ucm_ctx_put(ctx); /* func reference */
done: done:
if (param.private_data)
kfree(param.private_data); kfree(param.private_data);
return result; return result;
...@@ -939,7 +943,6 @@ static ssize_t ib_ucm_send_private_data(struct ib_ucm_file *file, ...@@ -939,7 +943,6 @@ static ssize_t ib_ucm_send_private_data(struct ib_ucm_file *file,
up(&ctx->file->mutex); up(&ctx->file->mutex);
ib_ucm_ctx_put(ctx); /* func reference */ ib_ucm_ctx_put(ctx); /* func reference */
done: done:
if (private_data)
kfree(private_data); kfree(private_data);
return result; return result;
...@@ -1009,9 +1012,7 @@ static ssize_t ib_ucm_send_info(struct ib_ucm_file *file, ...@@ -1009,9 +1012,7 @@ static ssize_t ib_ucm_send_info(struct ib_ucm_file *file,
up(&ctx->file->mutex); up(&ctx->file->mutex);
ib_ucm_ctx_put(ctx); /* func reference */ ib_ucm_ctx_put(ctx); /* func reference */
done: done:
if (data)
kfree(data); kfree(data);
if (info)
kfree(info); kfree(info);
return result; return result;
...@@ -1063,7 +1064,6 @@ static ssize_t ib_ucm_send_mra(struct ib_ucm_file *file, ...@@ -1063,7 +1064,6 @@ static ssize_t ib_ucm_send_mra(struct ib_ucm_file *file,
up(&ctx->file->mutex); up(&ctx->file->mutex);
ib_ucm_ctx_put(ctx); /* func reference */ ib_ucm_ctx_put(ctx); /* func reference */
done: done:
if (data)
kfree(data); kfree(data);
return result; return result;
...@@ -1105,9 +1105,7 @@ static ssize_t ib_ucm_send_lap(struct ib_ucm_file *file, ...@@ -1105,9 +1105,7 @@ static ssize_t ib_ucm_send_lap(struct ib_ucm_file *file,
up(&ctx->file->mutex); up(&ctx->file->mutex);
ib_ucm_ctx_put(ctx); /* func reference */ ib_ucm_ctx_put(ctx); /* func reference */
done: done:
if (data)
kfree(data); kfree(data);
if (path)
kfree(path); kfree(path);
return result; return result;
...@@ -1157,9 +1155,7 @@ static ssize_t ib_ucm_send_sidr_req(struct ib_ucm_file *file, ...@@ -1157,9 +1155,7 @@ static ssize_t ib_ucm_send_sidr_req(struct ib_ucm_file *file,
up(&ctx->file->mutex); up(&ctx->file->mutex);
ib_ucm_ctx_put(ctx); /* func reference */ ib_ucm_ctx_put(ctx); /* func reference */
done: done:
if (param.private_data)
kfree(param.private_data); kfree(param.private_data);
if (param.path)
kfree(param.path); kfree(param.path);
return result; return result;
...@@ -1209,9 +1205,7 @@ static ssize_t ib_ucm_send_sidr_rep(struct ib_ucm_file *file, ...@@ -1209,9 +1205,7 @@ static ssize_t ib_ucm_send_sidr_rep(struct ib_ucm_file *file,
up(&ctx->file->mutex); up(&ctx->file->mutex);
ib_ucm_ctx_put(ctx); /* func reference */ ib_ucm_ctx_put(ctx); /* func reference */
done: done:
if (param.private_data)
kfree(param.private_data); kfree(param.private_data);
if (param.info)
kfree(param.info); kfree(param.info);
return result; return result;
...@@ -1252,7 +1246,7 @@ static ssize_t ib_ucm_write(struct file *filp, const char __user *buf, ...@@ -1252,7 +1246,7 @@ static ssize_t ib_ucm_write(struct file *filp, const char __user *buf,
if (copy_from_user(&hdr, buf, sizeof(hdr))) if (copy_from_user(&hdr, buf, sizeof(hdr)))
return -EFAULT; return -EFAULT;
printk(KERN_ERR "UCM: Write. cmd <%d> in <%d> out <%d> len <%Zu>\n", ucm_dbg("Write. cmd <%d> in <%d> out <%d> len <%Zu>\n",
hdr.cmd, hdr.in, hdr.out, len); hdr.cmd, hdr.in, hdr.out, len);
if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table)) if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table))
...@@ -1300,7 +1294,7 @@ static int ib_ucm_open(struct inode *inode, struct file *filp) ...@@ -1300,7 +1294,7 @@ static int ib_ucm_open(struct inode *inode, struct file *filp)
filp->private_data = file; filp->private_data = file;
file->filp = filp; file->filp = filp;
printk(KERN_ERR "UCM: Created struct\n"); ucm_dbg("Created struct\n");
return 0; return 0;
} }
...@@ -1326,7 +1320,7 @@ static int ib_ucm_close(struct inode *inode, struct file *filp) ...@@ -1326,7 +1320,7 @@ static int ib_ucm_close(struct inode *inode, struct file *filp)
kfree(file); kfree(file);
printk(KERN_ERR "UCM: Deleted struct\n"); ucm_dbg("Deleted struct\n");
return 0; return 0;
} }
...@@ -1348,7 +1342,7 @@ static int __init ib_ucm_init(void) ...@@ -1348,7 +1342,7 @@ static int __init ib_ucm_init(void)
result = register_chrdev_region(IB_UCM_DEV, 1, "infiniband_cm"); result = register_chrdev_region(IB_UCM_DEV, 1, "infiniband_cm");
if (result) { if (result) {
printk(KERN_ERR "UCM: Error <%d> registering dev\n", result); ucm_dbg("Error <%d> registering dev\n", result);
goto err_chr; goto err_chr;
} }
...@@ -1356,14 +1350,14 @@ static int __init ib_ucm_init(void) ...@@ -1356,14 +1350,14 @@ static int __init ib_ucm_init(void)
result = cdev_add(&ib_ucm_cdev, IB_UCM_DEV, 1); result = cdev_add(&ib_ucm_cdev, IB_UCM_DEV, 1);
if (result) { if (result) {
printk(KERN_ERR "UCM: Error <%d> adding cdev\n", result); ucm_dbg("Error <%d> adding cdev\n", result);
goto err_cdev; goto err_cdev;
} }
ib_ucm_class = class_create(THIS_MODULE, "infiniband_cm"); ib_ucm_class = class_create(THIS_MODULE, "infiniband_cm");
if (IS_ERR(ib_ucm_class)) { if (IS_ERR(ib_ucm_class)) {
result = PTR_ERR(ib_ucm_class); result = PTR_ERR(ib_ucm_class);
printk(KERN_ERR "UCM: Error <%d> creating class\n", result); ucm_dbg("Error <%d> creating class\n", result);
goto err_class; goto err_class;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment