From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751886AbdLNKtv (ORCPT ); Thu, 14 Dec 2017 05:49:51 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:40652 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751705AbdLNKts (ORCPT ); Thu, 14 Dec 2017 05:49:48 -0500 X-Google-Smtp-Source: ACJfBos8DILY6F5WCpsM9Oir1Xij+kDDtDVM4cG+bCP+7RpkkoMVW1TzMVCJLklTgvlgVPVfaUnVug== References: <20171212092528.19636-1-mashimiao.fnst@cn.fujitsu.com> User-agent: mu4e 0.9.18; emacs 27.0.50 From: Rui Miguel Silva To: Ma Shimiao Cc: linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org, greybus-dev@lists.linaro.org, Greg Kroah-Hartman Subject: Re: [PATCH] drivers/staging/greybus: fix max dup length for kstrndup In-reply-to: <20171212092528.19636-1-mashimiao.fnst@cn.fujitsu.com> Date: Thu, 14 Dec 2017 10:49:45 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ma, Thanks for your patch. Please make sure you use scripts/get_maintainer.pl so that your patches goes to the right lists and people. I CC's them now. ;) On Tue 12 Dec 2017 at 09:25, Ma Shimiao wrote: > If source string longer than max, kstrndup will alloc max+1 space. > So, we should make sure the result will not over limit. I think we are good here. kstrndup alloc memory for us the max+1, and in fact we want to have the 32 chars plus the \0 set by kstrndup. So, I think the code as is now is ok. --- Cheers, Rui > > Signed-off-by: Ma Shimiao > --- > drivers/staging/greybus/light.c | 9 ++++++--- > drivers/staging/greybus/power_supply.c | 10 ++++++---- > 2 files changed, 12 insertions(+), 7 deletions(-) > > diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c > index 010ae1e9c7fb..c7ac2ead5a07 100644 > --- a/drivers/staging/greybus/light.c > +++ b/drivers/staging/greybus/light.c > @@ -965,10 +965,12 @@ static int gb_lights_channel_config(struct gb_light *light, > channel->mode = le32_to_cpu(conf.mode); > channel->flags = le32_to_cpu(conf.flags); > channel->color = le32_to_cpu(conf.color); > - channel->color_name = kstrndup(conf.color_name, NAMES_MAX, GFP_KERNEL); > + channel->color_name = kstrndup(conf.color_name, > + NAMES_MAX - 1, GFP_KERNEL); > if (!channel->color_name) > return -ENOMEM; > - channel->mode_name = kstrndup(conf.mode_name, NAMES_MAX, GFP_KERNEL); > + channel->mode_name = kstrndup(conf.mode_name, > + NAMES_MAX - 1, GFP_KERNEL); > if (!channel->mode_name) > return -ENOMEM; > > @@ -1027,7 +1029,8 @@ static int gb_lights_light_config(struct gb_lights *glights, u8 id) > return -EINVAL; > > light->channels_count = conf.channel_count; > - light->name = kstrndup(conf.name, NAMES_MAX, GFP_KERNEL); > + light->name = kstrndup(conf.name, > + NAMES_MAX - 1, GFP_KERNEL); > > light->channels = kcalloc(light->channels_count, > sizeof(struct gb_channel), GFP_KERNEL); > diff --git a/drivers/staging/greybus/power_supply.c b/drivers/staging/greybus/power_supply.c > index 0529e5628c24..7bc76633866b 100644 > --- a/drivers/staging/greybus/power_supply.c > +++ b/drivers/staging/greybus/power_supply.c > @@ -487,14 +487,16 @@ static int gb_power_supply_description_get(struct gb_power_supply *gbpsy) > if (ret < 0) > return ret; > > - gbpsy->manufacturer = kstrndup(resp.manufacturer, PROP_MAX, GFP_KERNEL); > + gbpsy->manufacturer = kstrndup(resp.manufacturer, > + PROP_MAX - 1, GFP_KERNEL); > if (!gbpsy->manufacturer) > return -ENOMEM; > - gbpsy->model_name = kstrndup(resp.model, PROP_MAX, GFP_KERNEL); > + gbpsy->model_name = kstrndup(resp.model, > + PROP_MAX - 1, GFP_KERNEL); > if (!gbpsy->model_name) > return -ENOMEM; > - gbpsy->serial_number = kstrndup(resp.serial_number, PROP_MAX, > - GFP_KERNEL); > + gbpsy->serial_number = kstrndup(resp.serial_number, > + PROP_MAX - 1, GFP_KERNEL); > if (!gbpsy->serial_number) > return -ENOMEM;