Skip to contentSkip to conversation

nouveau/svm: Use kvcalloc() instead of kvzalloc()

PATCH In review Gustavo A. R. Silva 3 participants 4 messages Sep 28, 2021 – Oct 28, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nouveau/svm: Use kvcalloc() instead of kvzalloc()

Use 2-factor argument form kvcalloc() instead of kvzalloc().

---
 drivers/gpu/drm/nouveau/nouveau_svm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_svm.c +1 -1
index b0c3422cb01f..1a896a24288a 100644
@@ -992,7 +992,7 @@ nouveau_svm_fault_buffer_ctor(struct nouveau_svm *svm, s32 oclass, int id)
 	if (ret)
 		return ret;
 
-	buffer->fault = kvzalloc(sizeof(*buffer->fault) * buffer->entries, GFP_KERNEL);
+	buffer->fault = kvcalloc(sizeof(*buffer->fault), buffer->entries, GFP_KERNEL);
 	if (!buffer->fault)
 		return -ENOMEM;
 
Signature · 1 line
2.27.0
#1 lore raw

Lack of documentation inside Linux here is a bit annoying, but do I understand it correctly, that the main (and probably only) difference is that kvcalloc checks whether the multiplication overflows and returns NULL in this case?

Quoted 25 lines · Gustavo A. R. Silva

Use 2-factor argument form kvcalloc() instead of kvzalloc().

---
 drivers/gpu/drm/nouveau/nouveau_svm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_svm.c +1 -2
index b0c3422cb01f..1a896a24288a 100644
@@ -992,7 +992,7 @@ nouveau_svm_fault_buffer_ctor(struct nouveau_svm *svm, s32 oclass, int id)
        if (ret)
                return ret;
 
-       buffer->fault = kvzalloc(sizeof(*buffer->fault) * buffer->entries, GFP_KERNEL);
+       buffer->fault = kvcalloc(sizeof(*buffer->fault), buffer->entries, GFP_KERNEL);
        if (!buffer->fault)
                return -ENOMEM;
 
--

2.27.0

Reviewed-by
#2 lore raw
Quoted 4 lines · Karol Herbst

Lack of documentation inside Linux here is a bit annoying, but do I understand it correctly, that the main (and probably only) difference is that kvcalloc checks whether the multiplication overflows and returns NULL in this case?

That's correct. :)

Quoted 7 lines
Quoted 5 lines · Gustavo A. R. Silva

Use 2-factor argument form kvcalloc() instead of kvzalloc().

Quoted 21 lines
Quoted 20 lines
---
 drivers/gpu/drm/nouveau/nouveau_svm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_svm.c +1 -2
index b0c3422cb01f..1a896a24288a 100644
@@ -992,7 +992,7 @@ nouveau_svm_fault_buffer_ctor(struct nouveau_svm *svm, s32 oclass, int id)
        if (ret)
                return ret;
 
-       buffer->fault = kvzalloc(sizeof(*buffer->fault) * buffer->entries, GFP_KERNEL);
+       buffer->fault = kvcalloc(sizeof(*buffer->fault), buffer->entries, GFP_KERNEL);
        if (!buffer->fault)
                return -ENOMEM;
 
--

2.27.0

Signature · 1 line
Kees Cook
#3 lore raw
Quoted 11 lines · Kees Cook
Quoted 4 lines · Karol Herbst

Lack of documentation inside Linux here is a bit annoying, but do I understand it correctly, that the main (and probably only) difference is that kvcalloc checks whether the multiplication overflows and returns NULL in this case?

That's correct. :)

Quoted 3 lines
Quoted 1 line · Gustavo A. R. Silva
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

Use 2-factor argument form kvcalloc() instead of kvzalloc().

I'll take this in my -next tree.

Thanks
--
Gustavo