* [PATCH] fs: f2fs: Use kmemdup
@ 2013-03-28 0:24 Alexandru Gheorghiu
2013-03-28 7:24 ` Namjae Jeon
0 siblings, 1 reply; 6+ messages in thread
From: Alexandru Gheorghiu @ 2013-03-28 0:24 UTC (permalink / raw)
To: linkinjeon
Cc: Jaegeuk Kim, linux-f2fs-devel, linux-kernel, Alexandru Gheorghiu
Use kmemdup instead of kzalloc and memcpy.
Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
---
fs/f2fs/node.c | 12 +++++-------
fs/f2fs/segment.c | 3 +--
2 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index e275218..9f5eca4 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1661,19 +1661,17 @@ static int init_node_manager(struct f2fs_sb_info *sbi)
spin_lock_init(&nm_i->free_nid_list_lock);
rwlock_init(&nm_i->nat_tree_lock);
- nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP);
nm_i->init_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid);
nm_i->next_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid);
-
- nm_i->nat_bitmap = kzalloc(nm_i->bitmap_size, GFP_KERNEL);
- if (!nm_i->nat_bitmap)
- return -ENOMEM;
+ nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP);
version_bitmap = __bitmap_ptr(sbi, NAT_BITMAP);
if (!version_bitmap)
return -EFAULT;
- /* copy version bitmap */
- memcpy(nm_i->nat_bitmap, version_bitmap, nm_i->bitmap_size);
+ nm_i->nat_bitmap = kmemdup(version_bitmap, nm_i->bitmap_size,
+ GFP_KERNEL);
+ if (!nm_i->nat_bitmap)
+ return -ENOMEM;
return 0;
}
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 777f17e..1758149 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1403,10 +1403,9 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
bitmap_size = __bitmap_size(sbi, SIT_BITMAP);
src_bitmap = __bitmap_ptr(sbi, SIT_BITMAP);
- dst_bitmap = kzalloc(bitmap_size, GFP_KERNEL);
+ dst_bitmap = kmemdup(src_bitmap, bitmap_size, GFP_KERNEL);
if (!dst_bitmap)
return -ENOMEM;
- memcpy(dst_bitmap, src_bitmap, bitmap_size);
/* init SIT information */
sit_i->s_ops = &default_salloc_ops;
--
1.7.9.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] fs: f2fs: Use kmemdup
@ 2013-03-27 23:47 Alexandru Gheorghiu
2013-03-28 0:05 ` Namjae Jeon
0 siblings, 1 reply; 6+ messages in thread
From: Alexandru Gheorghiu @ 2013-03-27 23:47 UTC (permalink / raw)
To: linkinjeon
Cc: Jaegeuk Kim, linux-f2fs-devel, linux-kernel, Alexandru Gheorghiu
Used kmemdup instead of kzalloc and memcpy.
Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
---
fs/f2fs/node.c | 11 ++++-------
fs/f2fs/segment.c | 3 +--
2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index e275218..920f53a 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1661,19 +1661,16 @@ static int init_node_manager(struct f2fs_sb_info *sbi)
spin_lock_init(&nm_i->free_nid_list_lock);
rwlock_init(&nm_i->nat_tree_lock);
- nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP);
nm_i->init_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid);
nm_i->next_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid);
-
- nm_i->nat_bitmap = kzalloc(nm_i->bitmap_size, GFP_KERNEL);
- if (!nm_i->nat_bitmap)
- return -ENOMEM;
+ nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP);
version_bitmap = __bitmap_ptr(sbi, NAT_BITMAP);
if (!version_bitmap)
return -EFAULT;
- /* copy version bitmap */
- memcpy(nm_i->nat_bitmap, version_bitmap, nm_i->bitmap_size);
+ nm_i->nat_bitmap = kmemdup(version_bitmap, nm_i->bitmap_size, GFP_KERNEL);
+ if (!nm_i->nat_bitmap)
+ return -ENOMEM;
return 0;
}
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 777f17e..1758149 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1403,10 +1403,9 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
bitmap_size = __bitmap_size(sbi, SIT_BITMAP);
src_bitmap = __bitmap_ptr(sbi, SIT_BITMAP);
- dst_bitmap = kzalloc(bitmap_size, GFP_KERNEL);
+ dst_bitmap = kmemdup(src_bitmap, bitmap_size, GFP_KERNEL);
if (!dst_bitmap)
return -ENOMEM;
- memcpy(dst_bitmap, src_bitmap, bitmap_size);
/* init SIT information */
sit_i->s_ops = &default_salloc_ops;
--
1.7.9.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs: f2fs: Use kmemdup
2013-03-27 23:47 Alexandru Gheorghiu
@ 2013-03-28 0:05 ` Namjae Jeon
0 siblings, 0 replies; 6+ messages in thread
From: Namjae Jeon @ 2013-03-28 0:05 UTC (permalink / raw)
To: Alexandru Gheorghiu; +Cc: Jaegeuk Kim, linux-f2fs-devel, linux-kernel
2013/3/28, Alexandru Gheorghiu <gheorghiuandru@gmail.com>:
> Used kmemdup instead of kzalloc and memcpy.
>
> Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
> ---
> fs/f2fs/node.c | 11 ++++-------
> fs/f2fs/segment.c | 3 +--
> 2 files changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> index e275218..920f53a 100644
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -1661,19 +1661,16 @@ static int init_node_manager(struct f2fs_sb_info
> *sbi)
> spin_lock_init(&nm_i->free_nid_list_lock);
> rwlock_init(&nm_i->nat_tree_lock);
>
> - nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP);
> nm_i->init_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid);
> nm_i->next_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid);
> -
> - nm_i->nat_bitmap = kzalloc(nm_i->bitmap_size, GFP_KERNEL);
> - if (!nm_i->nat_bitmap)
> - return -ENOMEM;
> + nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP);
> version_bitmap = __bitmap_ptr(sbi, NAT_BITMAP);
> if (!version_bitmap)
> return -EFAULT;
>
> - /* copy version bitmap */
> - memcpy(nm_i->nat_bitmap, version_bitmap, nm_i->bitmap_size);
> + nm_i->nat_bitmap = kmemdup(version_bitmap, nm_i->bitmap_size,
> GFP_KERNEL);
maybe, this line is over 80 characters.
plz fix it after running checkpatch.pl.
Thanks.
> + if (!nm_i->nat_bitmap)
> + return -ENOMEM;
> return 0;
> }
>
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 777f17e..1758149 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -1403,10 +1403,9 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
> bitmap_size = __bitmap_size(sbi, SIT_BITMAP);
> src_bitmap = __bitmap_ptr(sbi, SIT_BITMAP);
>
> - dst_bitmap = kzalloc(bitmap_size, GFP_KERNEL);
> + dst_bitmap = kmemdup(src_bitmap, bitmap_size, GFP_KERNEL);
> if (!dst_bitmap)
> return -ENOMEM;
> - memcpy(dst_bitmap, src_bitmap, bitmap_size);
>
> /* init SIT information */
> sit_i->s_ops = &default_salloc_ops;
> --
> 1.7.9.5
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] fs: f2fs: Use kmemdup
@ 2013-03-27 19:53 Alexandru Gheorghiu
2013-03-27 23:24 ` Namjae Jeon
0 siblings, 1 reply; 6+ messages in thread
From: Alexandru Gheorghiu @ 2013-03-27 19:53 UTC (permalink / raw)
To: Jaegeuk Kim; +Cc: linux-f2fs-devel, linux-kernel, Alexandru Gheorghiu
Used kmemdup instead of kzalloc followed by memcpy.
Patch found using coccinelle.
Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
---
fs/f2fs/segment.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 777f17e..1758149 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1403,10 +1403,9 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
bitmap_size = __bitmap_size(sbi, SIT_BITMAP);
src_bitmap = __bitmap_ptr(sbi, SIT_BITMAP);
- dst_bitmap = kzalloc(bitmap_size, GFP_KERNEL);
+ dst_bitmap = kmemdup(src_bitmap, bitmap_size, GFP_KERNEL);
if (!dst_bitmap)
return -ENOMEM;
- memcpy(dst_bitmap, src_bitmap, bitmap_size);
/* init SIT information */
sit_i->s_ops = &default_salloc_ops;
--
1.7.9.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs: f2fs: Use kmemdup
2013-03-27 19:53 Alexandru Gheorghiu
@ 2013-03-27 23:24 ` Namjae Jeon
0 siblings, 0 replies; 6+ messages in thread
From: Namjae Jeon @ 2013-03-27 23:24 UTC (permalink / raw)
To: Alexandru Gheorghiu; +Cc: Jaegeuk Kim, linux-f2fs-devel, linux-kernel
2013/3/28, Alexandru Gheorghiu <gheorghiuandru@gmail.com>:
> Used kmemdup instead of kzalloc followed by memcpy.
> Patch found using coccinelle.
>
> Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
> ---
> fs/f2fs/segment.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 777f17e..1758149 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -1403,10 +1403,9 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
> bitmap_size = __bitmap_size(sbi, SIT_BITMAP);
> src_bitmap = __bitmap_ptr(sbi, SIT_BITMAP);
>
> - dst_bitmap = kzalloc(bitmap_size, GFP_KERNEL);
> + dst_bitmap = kmemdup(src_bitmap, bitmap_size, GFP_KERNEL);
> if (!dst_bitmap)
> return -ENOMEM;
> - memcpy(dst_bitmap, src_bitmap, bitmap_size);
>
> /* init SIT information */
> sit_i->s_ops = &default_salloc_ops;
> --
> 1.7.9.5
Hi Alexandru.
There is another point to change kmemdup.
------------------------------------------------------------------------------------------------------
- nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP);
- nm_i->init_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid);
- nm_i->next_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid);
+ nm_i->init_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid);
+ nm_i->next_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid);
+ nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP);
+ version_bitmap = __bitmap_ptr(sbi, NAT_BITMAP);
+ if (!version_bitmap)
+ return -EFAULT;
- nm_i->nat_bitmap = kzalloc(nm_i->bitmap_size, GFP_KERNEL);
- if (!nm_i->nat_bitmap)
- return -ENOMEM;
- version_bitmap = __bitmap_ptr(sbi, NAT_BITMAP);
- if (!version_bitmap)
- return -EFAULT;
+ nm_i->nat_bitmap = kmemdup(version_bitmap, nm_i->bitmap_size,
GFP_KERNEL);
+ if (!nm_i->nat_bitmap)
+ return -ENOMEM;
- /* copy version bitmap */
- memcpy(nm_i->nat_bitmap, version_bitmap, nm_i->bitmap_size);
-----------------------------------------------------------------------------------------------------
If you agree, Could you send the patch include the above one again ?
Thanks.
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-03-28 7:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-28 0:24 [PATCH] fs: f2fs: Use kmemdup Alexandru Gheorghiu
2013-03-28 7:24 ` Namjae Jeon
-- strict thread matches above, loose matches on Subject: below --
2013-03-27 23:47 Alexandru Gheorghiu
2013-03-28 0:05 ` Namjae Jeon
2013-03-27 19:53 Alexandru Gheorghiu
2013-03-27 23:24 ` Namjae Jeon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®