From: Rui Miguel Silva <rmfrfs@gmail.com>
To: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
Cc: linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org,
greybus-dev@lists.linaro.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH] drivers/staging/greybus: fix max dup length for kstrndup
Date: Thu, 14 Dec 2017 10:49:45 +0000 [thread overview]
Message-ID: <m38te5oa7q.fsf@gmail.com> (raw)
In-Reply-To: <20171212092528.19636-1-mashimiao.fnst@cn.fujitsu.com>
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 <mashimiao.fnst@cn.fujitsu.com>
> ---
> 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;
prev parent reply other threads:[~2017-12-14 10:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-12 9:25 [PATCH] drivers/staging/greybus: fix max dup length for kstrndup Ma Shimiao
2017-12-14 10:49 ` Rui Miguel Silva [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m38te5oa7q.fsf@gmail.com \
--to=rmfrfs@gmail.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=greybus-dev@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mashimiao.fnst@cn.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.