Skip to contentSkip to conversation

fs/ntfs3: use kcalloc() instead of kzalloc()

PATCH Superseded Lenko Donchev 2 participants 2 messages Feb 11, 2024 NTFS3 filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/ntfs3: use kcalloc() instead of kzalloc()

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows[1]. Here the multiplication is obviously safe, but using kcalloc() is more appropriate and improves readability. This patch has no effect on runtime behavior.

---
 fs/ntfs3/frecord.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/frecord.c +1 -1
index 3b42938a9d3b..d435446537ca 100644
@@ -2636,7 +2636,7 @@ int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages,
 		goto out1;
 	}
 
-	pages_disk = kzalloc(npages_disk * sizeof(struct page *), GFP_NOFS);
+	pages_disk = kcalloc(npages_disk, sizeof(struct page *), GFP_NOFS);
 	if (!pages_disk) {
 		err = -ENOMEM;
 		goto out2;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 18 lines · Lenko Donchev

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows[1]. Here the multiplication is obviously safe, but using kcalloc() is more appropriate and improves readability. This patch has no effect on runtime behavior.

---
  fs/ntfs3/frecord.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/frecord.c +0 -0
index 3b42938a9d3b..d435446537ca 100644

fs/ntfs3/frecord.c int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages, · line 2639

Quoted 5 lines
fs/ntfs3/frecord.c +1 -1
@@ -2636,7 +2636,7 @@ int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages,
  		goto out1;
  	}
 
-	pages_disk = kzalloc(npages_disk * sizeof(struct page *), GFP_NOFS);
+	pages_disk = kcalloc(npages_disk, sizeof(struct page *), GFP_NOFS);

sizeof(*pages_disk) is preferable over sizeof(struct page *)

Thanks
--
Gustavo

Quoted 3 lines
fs/ntfs3/frecord.c +0 -0
  	if (!pages_disk) {
  		err = -ENOMEM;
  		goto out2;