diff mbox series

[next] nouveau/svm: Use kvcalloc() instead of kvzalloc()

Message ID 20210928222513.GA294575@embeddedor (mailing list archive)
State Mainlined
Commit 71e4bbca070e84b85ee2f1748caf92f97e091c7b
Delegated to: Gustavo A. R. Silva
Headers show
Series [next] nouveau/svm: Use kvcalloc() instead of kvzalloc() | expand

Commit Message

Gustavo A. R. Silva Sept. 28, 2021, 10:25 p.m. UTC
Use 2-factor argument form kvcalloc() instead of kvzalloc().

Link: https://github.com/KSPP/linux/issues/162
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/gpu/drm/nouveau/nouveau_svm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Karol Herbst Sept. 29, 2021, 3:28 a.m. UTC | #1
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?

On Wed, Sep 29, 2021 at 12:21 AM Gustavo A. R. Silva
<gustavoars@kernel.org> wrote:
>
> Use 2-factor argument form kvcalloc() instead of kvzalloc().
>
> Link: https://github.com/KSPP/linux/issues/162
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
>  drivers/gpu/drm/nouveau/nouveau_svm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c
> index b0c3422cb01f..1a896a24288a 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_svm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c
> @@ -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
>
Kees Cook Oct. 21, 2021, 5:03 p.m. UTC | #2
On Wed, Sep 29, 2021 at 05:28:47AM +0200, Karol Herbst wrote:
> 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. :)

> On Wed, Sep 29, 2021 at 12:21 AM Gustavo A. R. Silva
> <gustavoars@kernel.org> wrote:
> >
> > Use 2-factor argument form kvcalloc() instead of kvzalloc().
> >
> > Link: https://github.com/KSPP/linux/issues/162
> > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Reviewed-by: Kees Cook <keescook@chromium.org>

> > ---
> >  drivers/gpu/drm/nouveau/nouveau_svm.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c
> > index b0c3422cb01f..1a896a24288a 100644
> > --- a/drivers/gpu/drm/nouveau/nouveau_svm.c
> > +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c
> > @@ -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
> >
>
Gustavo A. R. Silva Oct. 28, 2021, 5:38 p.m. UTC | #3
On Thu, Oct 21, 2021 at 10:03:19AM -0700, Kees Cook wrote:
> On Wed, Sep 29, 2021 at 05:28:47AM +0200, Karol Herbst wrote:
> > 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. :)
> 
> > On Wed, Sep 29, 2021 at 12:21 AM Gustavo A. R. Silva
> > <gustavoars@kernel.org> wrote:
> > >
> > > Use 2-factor argument form kvcalloc() instead of kvzalloc().
> > >
> > > Link: https://github.com/KSPP/linux/issues/162
> > > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> 
> Reviewed-by: Kees Cook <keescook@chromium.org>

I'll take this in my -next tree.

Thanks
--
Gustavo
diff mbox series

Patch

diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c
index b0c3422cb01f..1a896a24288a 100644
--- a/drivers/gpu/drm/nouveau/nouveau_svm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_svm.c
@@ -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;