linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regulator: fix pointer table overallocation
@ 2020-08-09 19:21 Michał Mirosław
  2020-08-09 19:44 ` Dmitry Osipenko
  0 siblings, 1 reply; 6+ messages in thread
From: Michał Mirosław @ 2020-08-09 19:21 UTC (permalink / raw)
  To: Dmitry Osipenko, Liam Girdwood, Mark Brown; +Cc: linux-kernel

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.
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] regulator: fix pointer table overallocation
  2020-08-09 19:21 [PATCH] regulator: fix pointer table overallocation Michał Mirosław
@ 2020-08-09 19:44 ` Dmitry Osipenko
  2020-08-10 12:37   ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Osipenko @ 2020-08-09 19:44 UTC (permalink / raw)
  To: Michał Mirosław, Liam Girdwood, Mark Brown; +Cc: linux-kernel

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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] regulator: fix pointer table overallocation
  2020-08-09 19:44 ` Dmitry Osipenko
@ 2020-08-10 12:37   ` Mark Brown
  2020-08-10 16:25     ` Michał Mirosław
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2020-08-10 12:37 UTC (permalink / raw)
  To: Dmitry Osipenko; +Cc: Michał Mirosław, Liam Girdwood, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 646 bytes --]

On Sun, Aug 09, 2020 at 10:44:25PM +0300, Dmitry Osipenko wrote:
> 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")

> 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.

Yeah, this is more a performance improvement than a fix.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] regulator: fix pointer table overallocation
  2020-08-10 12:37   ` Mark Brown
@ 2020-08-10 16:25     ` Michał Mirosław
  2020-08-10 17:33       ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Michał Mirosław @ 2020-08-10 16:25 UTC (permalink / raw)
  To: Mark Brown; +Cc: Dmitry Osipenko, Liam Girdwood, linux-kernel

On Mon, Aug 10, 2020 at 01:37:47PM +0100, Mark Brown wrote:
> On Sun, Aug 09, 2020 at 10:44:25PM +0300, Dmitry Osipenko wrote:
> > 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")
> 
> > 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.
> 
> Yeah, this is more a performance improvement than a fix.

Should I resend without Cc: stable?

Best Regards,
Michał Mirosław

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] regulator: fix pointer table overallocation
  2020-08-10 16:25     ` Michał Mirosław
@ 2020-08-10 17:33       ` Mark Brown
  2020-08-10 19:20         ` Michał Mirosław
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2020-08-10 17:33 UTC (permalink / raw)
  To: Michał Mirosław; +Cc: Dmitry Osipenko, Liam Girdwood, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 332 bytes --]

On Mon, Aug 10, 2020 at 06:25:56PM +0200, Michał Mirosław wrote:
> On Mon, Aug 10, 2020 at 01:37:47PM +0100, Mark Brown wrote:

> > Yeah, this is more a performance improvement than a fix.

> Should I resend without Cc: stable?

I've already queued it to be applied to -next with that removed and an
edited subject line.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] regulator: fix pointer table overallocation
  2020-08-10 17:33       ` Mark Brown
@ 2020-08-10 19:20         ` Michał Mirosław
  0 siblings, 0 replies; 6+ messages in thread
From: Michał Mirosław @ 2020-08-10 19:20 UTC (permalink / raw)
  To: Mark Brown; +Cc: Dmitry Osipenko, Liam Girdwood, linux-kernel

On Mon, Aug 10, 2020 at 06:33:37PM +0100, Mark Brown wrote:
> On Mon, Aug 10, 2020 at 06:25:56PM +0200, Michał Mirosław wrote:
> > On Mon, Aug 10, 2020 at 01:37:47PM +0100, Mark Brown wrote:
> > > Yeah, this is more a performance improvement than a fix.
> > Should I resend without Cc: stable?
> I've already queued it to be applied to -next with that removed and an
> edited subject line.

Ok, thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-08-10 19:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-09 19:21 [PATCH] regulator: fix pointer table overallocation Michał Mirosław
2020-08-09 19:44 ` Dmitry Osipenko
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

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).