Skip to content

Commit 7d5079a

Browse files
himangi774idryomov
authored andcommitted
rbd: use rbd_segment_name_free() instead of kfree()
Free memory allocated using kmem_cache_zalloc using kmem_cache_free rather than kfree. The helper rbd_segment_name_free does the job here. Its position is shifted above the calling function. The Coccinelle semantic patch that detects this change is as follows: // <smpl> @@ expression x,E,c; @@ x = \(kmem_cache_alloc\|kmem_cache_zalloc\|kmem_cache_alloc_node\)(c,...) ... when != x = E when != &x ?-kfree(x) +kmem_cache_free(c,x) // </smpl> Signed-off-by: Himangi Saraogi <himangi774@gmail.com> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
1 parent d0d0db2 commit 7d5079a

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎drivers/block/rbd.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,13 @@ static void rbd_dev_mapping_clear(struct rbd_device *rbd_dev)
11391139
rbd_dev->mapping.features = 0;
11401140
}
11411141

1142+
static void rbd_segment_name_free(const char *name)
1143+
{
1144+
/* The explicit cast here is needed to drop the const qualifier */
1145+
1146+
kmem_cache_free(rbd_segment_name_cache, (void *)name);
1147+
}
1148+
11421149
static const char *rbd_segment_name(struct rbd_device *rbd_dev, u64 offset)
11431150
{
11441151
char *name;
@@ -1158,20 +1165,13 @@ static const char *rbd_segment_name(struct rbd_device *rbd_dev, u64 offset)
11581165
if (ret < 0 || ret > CEPH_MAX_OID_NAME_LEN) {
11591166
pr_err("error formatting segment name for #%llu (%d)\n",
11601167
segment, ret);
1161-
kfree(name);
1168+
rbd_segment_name_free(name);
11621169
name = NULL;
11631170
}
11641171

11651172
return name;
11661173
}
11671174

1168-
static void rbd_segment_name_free(const char *name)
1169-
{
1170-
/* The explicit cast here is needed to drop the const qualifier */
1171-
1172-
kmem_cache_free(rbd_segment_name_cache, (void *)name);
1173-
}
1174-
11751175
static u64 rbd_segment_offset(struct rbd_device *rbd_dev, u64 offset)
11761176
{
11771177
u64 segment_size = (u64) 1 << rbd_dev->header.obj_order;

0 commit comments

Comments
 (0)