All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pwm: meson: fix allocation of meson_pwm_channel array
@ 2018-04-28 21:25 ` Martin Blumenstingl
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Blumenstingl @ 2018-04-28 21:25 UTC (permalink / raw)
  To: thierry.reding, linux-pwm, linux-amlogic, narmstrong
  Cc: khilman, carlo, Martin Blumenstingl

Using the pwm-meson driver on the 32-bit SoCs causes memory corruption.
The result are some hard-to-explain errors, for example
devm_clk_register crashes with a NULL dereference somewhere deep in the
common clock framework code.
In some cases the kernel even refused to boot when any of the PWM
controllers were enables on Meson8b.

The root cause seems to be an incorrect memory size in the devm_kcalloc
call in meson_pwm_probe. The code allocates an array of meson_pwm_channel
structs, but the size given is the size of the meson_pwm struct (which
seems like a small copy-and-paste error, as meson_pwm is allocated a few
lines above).
Even with this typo the code seemed to work fine on the 64-bit GX SoCs
(maybe due to the structs having the same size in the compiled result,
but I haven't checked this further).

Fixes: 211ed630753d2f ("pwm: Add support for Meson PWM Controller")
Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/pwm/pwm-meson.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
index 0767deba8e62..822860b4801a 100644
--- a/drivers/pwm/pwm-meson.c
+++ b/drivers/pwm/pwm-meson.c
@@ -541,8 +541,8 @@ static int meson_pwm_probe(struct platform_device *pdev)
 	meson->data = of_device_get_match_data(&pdev->dev);
 	meson->inverter_mask = BIT(meson->chip.npwm) - 1;
 
-	channels = devm_kcalloc(&pdev->dev, meson->chip.npwm, sizeof(*meson),
-				GFP_KERNEL);
+	channels = devm_kcalloc(&pdev->dev, meson->chip.npwm,
+				sizeof(*channels), GFP_KERNEL);
 	if (!channels)
 		return -ENOMEM;
 
-- 
2.17.0

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

* [PATCH] pwm: meson: fix allocation of meson_pwm_channel array
@ 2018-04-28 21:25 ` Martin Blumenstingl
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Blumenstingl @ 2018-04-28 21:25 UTC (permalink / raw)
  To: linus-amlogic

Using the pwm-meson driver on the 32-bit SoCs causes memory corruption.
The result are some hard-to-explain errors, for example
devm_clk_register crashes with a NULL dereference somewhere deep in the
common clock framework code.
In some cases the kernel even refused to boot when any of the PWM
controllers were enables on Meson8b.

The root cause seems to be an incorrect memory size in the devm_kcalloc
call in meson_pwm_probe. The code allocates an array of meson_pwm_channel
structs, but the size given is the size of the meson_pwm struct (which
seems like a small copy-and-paste error, as meson_pwm is allocated a few
lines above).
Even with this typo the code seemed to work fine on the 64-bit GX SoCs
(maybe due to the structs having the same size in the compiled result,
but I haven't checked this further).

Fixes: 211ed630753d2f ("pwm: Add support for Meson PWM Controller")
Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/pwm/pwm-meson.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
index 0767deba8e62..822860b4801a 100644
--- a/drivers/pwm/pwm-meson.c
+++ b/drivers/pwm/pwm-meson.c
@@ -541,8 +541,8 @@ static int meson_pwm_probe(struct platform_device *pdev)
 	meson->data = of_device_get_match_data(&pdev->dev);
 	meson->inverter_mask = BIT(meson->chip.npwm) - 1;
 
-	channels = devm_kcalloc(&pdev->dev, meson->chip.npwm, sizeof(*meson),
-				GFP_KERNEL);
+	channels = devm_kcalloc(&pdev->dev, meson->chip.npwm,
+				sizeof(*channels), GFP_KERNEL);
 	if (!channels)
 		return -ENOMEM;
 
-- 
2.17.0

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

* Re: [PATCH] pwm: meson: fix allocation of meson_pwm_channel array
  2018-04-28 21:25 ` Martin Blumenstingl
@ 2018-04-30  8:34   ` Thierry Reding
  -1 siblings, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2018-04-30  8:34 UTC (permalink / raw)
  To: Martin Blumenstingl; +Cc: linux-pwm, linux-amlogic, narmstrong, khilman, carlo

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

On Sat, Apr 28, 2018 at 11:25:21PM +0200, Martin Blumenstingl wrote:
> Using the pwm-meson driver on the 32-bit SoCs causes memory corruption.
> The result are some hard-to-explain errors, for example
> devm_clk_register crashes with a NULL dereference somewhere deep in the
> common clock framework code.
> In some cases the kernel even refused to boot when any of the PWM
> controllers were enables on Meson8b.
> 
> The root cause seems to be an incorrect memory size in the devm_kcalloc
> call in meson_pwm_probe. The code allocates an array of meson_pwm_channel
> structs, but the size given is the size of the meson_pwm struct (which
> seems like a small copy-and-paste error, as meson_pwm is allocated a few
> lines above).
> Even with this typo the code seemed to work fine on the 64-bit GX SoCs
> (maybe due to the structs having the same size in the compiled result,
> but I haven't checked this further).
> 
> Fixes: 211ed630753d2f ("pwm: Add support for Meson PWM Controller")
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> ---
>  drivers/pwm/pwm-meson.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks.

Thierry

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

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

* [PATCH] pwm: meson: fix allocation of meson_pwm_channel array
@ 2018-04-30  8:34   ` Thierry Reding
  0 siblings, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2018-04-30  8:34 UTC (permalink / raw)
  To: linus-amlogic

On Sat, Apr 28, 2018 at 11:25:21PM +0200, Martin Blumenstingl wrote:
> Using the pwm-meson driver on the 32-bit SoCs causes memory corruption.
> The result are some hard-to-explain errors, for example
> devm_clk_register crashes with a NULL dereference somewhere deep in the
> common clock framework code.
> In some cases the kernel even refused to boot when any of the PWM
> controllers were enables on Meson8b.
> 
> The root cause seems to be an incorrect memory size in the devm_kcalloc
> call in meson_pwm_probe. The code allocates an array of meson_pwm_channel
> structs, but the size given is the size of the meson_pwm struct (which
> seems like a small copy-and-paste error, as meson_pwm is allocated a few
> lines above).
> Even with this typo the code seemed to work fine on the 64-bit GX SoCs
> (maybe due to the structs having the same size in the compiled result,
> but I haven't checked this further).
> 
> Fixes: 211ed630753d2f ("pwm: Add support for Meson PWM Controller")
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> ---
>  drivers/pwm/pwm-meson.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-amlogic/attachments/20180430/cdaf4204/attachment.sig>

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

end of thread, other threads:[~2018-04-30  8:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-28 21:25 [PATCH] pwm: meson: fix allocation of meson_pwm_channel array Martin Blumenstingl
2018-04-28 21:25 ` Martin Blumenstingl
2018-04-30  8:34 ` Thierry Reding
2018-04-30  8:34   ` Thierry Reding

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.