mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
IB/core: Use kmemdup() instead of kmalloc()+memcpy()
Use kmemdup when some other buffer is immediately copied into the allocated region. A simplified version of the semantic patch that makes this change is as follows: (http://coccinelle.lip6.fr/) // <smpl> @@ expression from,to,size,flag; statement S; @@ - to = \(kmalloc\|kzalloc\)(size,flag); + to = kmemdup(from,size,flag); if (to==NULL || ...) S - memcpy(to, from, size); // </smpl> Signed-off-by: Julia Lawall <julia@diku.dk> Signed-off-by: Roland Dreier <rolandd@cisco.com>
This commit is contained in:
parent
0eddb519b9
commit
9893e742a0
2 changed files with 3 additions and 5 deletions
|
@ -1677,13 +1677,13 @@ int rdma_set_ib_paths(struct rdma_cm_id *id,
|
||||||
if (!cma_comp_exch(id_priv, CMA_ADDR_RESOLVED, CMA_ROUTE_RESOLVED))
|
if (!cma_comp_exch(id_priv, CMA_ADDR_RESOLVED, CMA_ROUTE_RESOLVED))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
id->route.path_rec = kmalloc(sizeof *path_rec * num_paths, GFP_KERNEL);
|
id->route.path_rec = kmemdup(path_rec, sizeof *path_rec * num_paths,
|
||||||
|
GFP_KERNEL);
|
||||||
if (!id->route.path_rec) {
|
if (!id->route.path_rec) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(id->route.path_rec, path_rec, sizeof *path_rec * num_paths);
|
|
||||||
id->route.num_paths = num_paths;
|
id->route.num_paths = num_paths;
|
||||||
return 0;
|
return 0;
|
||||||
err:
|
err:
|
||||||
|
|
|
@ -291,13 +291,11 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mad_reg_req) {
|
if (mad_reg_req) {
|
||||||
reg_req = kmalloc(sizeof *reg_req, GFP_KERNEL);
|
reg_req = kmemdup(mad_reg_req, sizeof *reg_req, GFP_KERNEL);
|
||||||
if (!reg_req) {
|
if (!reg_req) {
|
||||||
ret = ERR_PTR(-ENOMEM);
|
ret = ERR_PTR(-ENOMEM);
|
||||||
goto error3;
|
goto error3;
|
||||||
}
|
}
|
||||||
/* Make a copy of the MAD registration request */
|
|
||||||
memcpy(reg_req, mad_reg_req, sizeof *reg_req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now, fill in the various structures */
|
/* Now, fill in the various structures */
|
||||||
|
|
Loading…
Reference in a new issue