mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [RFC PATCH] ddr: fsl: fix null pointer dereference handling DDR4 memories
@ 2020-04-29  6:40 Ahmad Fatoum
  2020-04-29  7:25 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2020-04-29  6:40 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

cppcheck reports:

  drivers/ddr/fsl/util.c:42:27: error: Null pointer dereference:
	  c [ctunullpointer]
   unsigned int data_rate = c->ddr_freq;
                            ^
  drivers/ddr/fsl/ctrl_regs.c:1114:55: note: Calling function
      get_memory_clk_period_ps, 1st argument is null
   const unsigned int mclk_ps = get_memory_clk_period_ps(0);

Because get_memory_clk_period_ps expects a valid pointer, but is instead
passed NULL. Fix this by passing along the DDR controller handle like all
other calls to the function do. This is untested.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/ddr/fsl/ctrl_regs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ddr/fsl/ctrl_regs.c b/drivers/ddr/fsl/ctrl_regs.c
index 4957320d600c..eb99e0ea21e7 100644
--- a/drivers/ddr/fsl/ctrl_regs.c
+++ b/drivers/ddr/fsl/ctrl_regs.c
@@ -1111,7 +1111,7 @@ static void set_ddr_sdram_mode_9(struct fsl_ddr_controller *c,
 	unsigned short esdmode5;	/* Extended SDRAM mode 5 */
 	int rtt_park = 0;
 	bool four_cs = false;
-	const unsigned int mclk_ps = get_memory_clk_period_ps(0);
+	const unsigned int mclk_ps = get_memory_clk_period_ps(c);
 
 	if ((ddr->cs[0].config & SDRAM_CS_CONFIG_EN) &&
 	    (ddr->cs[1].config & SDRAM_CS_CONFIG_EN) &&
-- 
2.26.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [RFC PATCH] ddr: fsl: fix null pointer dereference handling DDR4 memories
  2020-04-29  6:40 [RFC PATCH] ddr: fsl: fix null pointer dereference handling DDR4 memories Ahmad Fatoum
@ 2020-04-29  7:25 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2020-04-29  7:25 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Wed, Apr 29, 2020 at 08:40:14AM +0200, Ahmad Fatoum wrote:
> cppcheck reports:
> 
>   drivers/ddr/fsl/util.c:42:27: error: Null pointer dereference:
> 	  c [ctunullpointer]
>    unsigned int data_rate = c->ddr_freq;
>                             ^
>   drivers/ddr/fsl/ctrl_regs.c:1114:55: note: Calling function
>       get_memory_clk_period_ps, 1st argument is null
>    const unsigned int mclk_ps = get_memory_clk_period_ps(0);
> 
> Because get_memory_clk_period_ps expects a valid pointer, but is instead
> passed NULL. Fix this by passing along the DDR controller handle like all
> other calls to the function do. This is untested.

This is obviously correct, so applied.

> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/ddr/fsl/ctrl_regs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ddr/fsl/ctrl_regs.c b/drivers/ddr/fsl/ctrl_regs.c
> index 4957320d600c..eb99e0ea21e7 100644
> --- a/drivers/ddr/fsl/ctrl_regs.c
> +++ b/drivers/ddr/fsl/ctrl_regs.c
> @@ -1111,7 +1111,7 @@ static void set_ddr_sdram_mode_9(struct fsl_ddr_controller *c,
>  	unsigned short esdmode5;	/* Extended SDRAM mode 5 */
>  	int rtt_park = 0;
>  	bool four_cs = false;
> -	const unsigned int mclk_ps = get_memory_clk_period_ps(0);
> +	const unsigned int mclk_ps = get_memory_clk_period_ps(c);

mclk_ps is only used under certain circumstances. It seems on my
layersape board it is unused. This NULL pointer deref doesn't trigger
there.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2020-04-29  7:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-29  6:40 [RFC PATCH] ddr: fsl: fix null pointer dereference handling DDR4 memories Ahmad Fatoum
2020-04-29  7:25 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox