From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752314AbdEFUQi (ORCPT ); Sat, 6 May 2017 16:16:38 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33629 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750780AbdEFUQe (ORCPT ); Sat, 6 May 2017 16:16:34 -0400 Date: Sat, 6 May 2017 13:16:29 -0700 From: Guru Das Srinagesh To: Joe Perches Cc: oleg.drokin@intel.com, andreas.dilger@intel.com, jsimmons@infradead.org, gregkh@linuxfoundation.org, john.hammond@intel.com, lustre-devel@lists.lustre.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: lustre: llite: Fix variable length array warning Message-ID: <20170506201629.GA14929@alpha> References: <1493966486-6143-1-git-send-email-gurooodas@gmail.com> <1493974356.31950.13.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1493974356.31950.13.camel@perches.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 05, 2017 at 01:52:36AM -0700, Joe Perches wrote: > On Thu, 2017-05-04 at 23:41 -0700, Guru Das Srinagesh wrote: > > Fix sparse warning "warning: Variable length array is used." by using > > kmalloc_array to allocate the required amount of memory instead and > > kfree to deallocate memory after use. > [] > > diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c > [] > > @@ -86,7 +86,8 @@ ll_xattr_set_common(const struct xattr_handler *handler, > > const char *name, const void *value, size_t size, > > int flags) > > { > > - char fullname[strlen(handler->prefix) + strlen(name) + 1]; > > + int fullname_len = strlen(handler->prefix) + strlen(name) + 1; > > + char *fullname = kmalloc_array(fullname_len, sizeof(char), GFP_KERNEL); > > What happens when this allocation fails? > Thanks for rightly pointing out the omission of kmalloc_array failure case handling code. I could check for fullname being NULL and then return -ENOMEM right there in both functions. I'll go ahead and send a v2 of this patch, with this modification incorporated, unless there are any more comments or concerns. Could you please let me know? Thank you.