Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1471984

Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions

From Paolo Bonzini <pbonzini@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions
Date 2016-08-29 18:50 +0200
Message-ID <sbxV0-1fP-29@gated-at.bofh.it> (permalink)
References <s9YcW-6Yd-11@gated-at.bofh.it> <s9YcW-6Yd-9@gated-at.bofh.it> <sbrmx-5BR-7@gated-at.bofh.it> <sbtol-6P8-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



On 29/08/2016 13:57, walter harms wrote:
> > > -	buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL);
> > > +	buf = kmalloc_array(count + 1, sizeof(*buf), GFP_KERNEL);
> > >  	if (!buf)
> > >  		return -ENOMEM;
> > >  
> > 
> > Here it's probably best to just remove sizeof(char) completely, as it's
> > 1 by definition.
> 
> I would not do so, if you ever change buf to something else it would break,
> having a sizeof(*buf) here is harmless and a known pattern.

Fair enough, it's not code I maintain.

Paolo

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions Paolo Bonzini <pbonzini@redhat.com> - 2016-08-29 11:50 +0200
  Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-29 12:40 +0200
  Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions walter harms <wharms@bfs.de> - 2016-08-29 14:00 +0200
    Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions Paolo Bonzini <pbonzini@redhat.com> - 2016-08-29 18:50 +0200

csiph-web