On Thu, Aug 17, 2017 at 03:44:08PM -0700, Andrew Morton wrote:
> On Wed, 16 Aug 2017 10:44:40 +0800 Aaron Lu <aaron...@intel.com> wrote:
> > ...
> >
> > +static int __init swapfile_init(void)
> > +{
> > +   int nid;
> > +
> > +   swap_avail_heads = kmalloc(nr_node_ids * sizeof(struct plist_head), 
> > GFP_KERNEL);
> 
> I suppose we should use kmalloc_array(), as someone wrote it for us.
> 
> --- a/mm/swapfile.c~swap-choose-swap-device-according-to-numa-node-v2-fix
> +++ a/mm/swapfile.c
> @@ -3700,7 +3700,8 @@ static int __init swapfile_init(void)
>  {
>       int nid;
>  
> -     swap_avail_heads = kmalloc(nr_node_ids * sizeof(struct plist_head), 
> GFP_KERNEL);
> +     swap_avail_heads = kmalloc_array(nr_node_ids, sizeof(struct plist_head),
> +                                      GFP_KERNEL);
>       if (!swap_avail_heads) {
>               pr_emerg("Not enough memory for swap heads, swap is 
> disabled\n");
>               return -ENOMEM;
> 
> > +   if (!swap_avail_heads) {
> > +           pr_emerg("Not enough memory for swap heads, swap is 
> > disabled\n");
> 
> checkpatch tells us that the "Not enough memory" is a bit redundant, as
> the memory allocator would have already warned.  So it's sufficient to
> additionally say only "swap is disabled" here.  But it's hardly worth
> changing.

Thanks Andrew for taking care of this.

Reply via email to