linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Osipenko <digetx@gmail.com>
To: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] regulator: fix pointer table overallocation
Date: Sun, 9 Aug 2020 22:44:25 +0300	[thread overview]
Message-ID: <5ef51b56-c533-46c8-621d-7907129594e9@gmail.com> (raw)
In-Reply-To: <407fbd06a02caf038a9ba3baa51c7d6d47cd6517.1597000795.git.mirq-linux@rere.qmqm.pl>

09.08.2020 22:21, Michał Mirosław пишет:
> The code allocates sizeof(regulator_dev) for a pointer. Make it less
> generous. Let kcalloc() calculate the size, while at it.
> 
> Cc: stable@vger.kernel.org
> Fixes: d8ca7d184b33 ("regulator: core: Introduce API for regulators coupling customization")
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---
>  drivers/regulator/core.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index 75ff7c563c5d..9e18997777d3 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -5011,20 +5011,20 @@ static void regulator_remove_coupling(struct regulator_dev *rdev)
>  
>  static int regulator_init_coupling(struct regulator_dev *rdev)
>  {
> +	struct regulator_dev **coupled;
>  	int err, n_phandles;
> -	size_t alloc_size;
>  
>  	if (!IS_ENABLED(CONFIG_OF))
>  		n_phandles = 0;
>  	else
>  		n_phandles = of_get_n_coupled(rdev);
>  
> -	alloc_size = sizeof(*rdev) * (n_phandles + 1);
> -
> -	rdev->coupling_desc.coupled_rdevs = kzalloc(alloc_size, GFP_KERNEL);
> -	if (!rdev->coupling_desc.coupled_rdevs)
> +	coupled = kcalloc(n_phandles + 1, sizeof(*coupled), GFP_KERNEL);
> +	if (!coupled)
>  		return -ENOMEM;
>  
> +	rdev->coupling_desc.coupled_rdevs = coupled;
> +
>  	/*
>  	 * Every regulator should always have coupling descriptor filled with
>  	 * at least pointer to itself.
> 

Hello, Michał! Thank you for the patch! Not sure whether it's worthwhile
to backport this change since it's an improvement, I'll leave it to Mark
to decide, otherwise looks good to me.

Reviewed-by: Dmitry Osipenko <digetx@gmail.com>

  reply	other threads:[~2020-08-09 19:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-09 19:21 Michał Mirosław
2020-08-09 19:44 ` Dmitry Osipenko [this message]
2020-08-10 12:37   ` Mark Brown
2020-08-10 16:25     ` Michał Mirosław
2020-08-10 17:33       ` Mark Brown
2020-08-10 19:20         ` Michał Mirosław

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=5ef51b56-c533-46c8-621d-7907129594e9@gmail.com \
    --to=digetx@gmail.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mirq-linux@rere.qmqm.pl \
    --subject='Re: [PATCH] regulator: fix pointer table overallocation' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).