ASoC: rsnd: Fix possible NULL pointer dereference
Subsystems (3)
PATCH 1/1 ASoC: rsnd: Fix possible NULL pointer dereference
In case the "clock-frequency" DT property is not present, the of_find_property(np, "clock-frequency", NULL) will return NULL and the subsequent req_size = prop->length / sizeof(u32); will trigger a NULL pointer dereference.
This patch adds check for the NULL return value and propagates the error into the caller of the function.
--- sound/soc/sh/rcar/adg.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
sound/soc/sh/rcar/adg.c +9 -4
@@ -425,8 +425,7 @@ static void rsnd_adg_get_clkin(struct rsnd_priv *priv,dev_dbg (dev,"clk %d : %p : %ld\n" , i, clk,clk_get_rate (clk)); } -static void rsnd_adg_get_clkout (struct rsnd_priv *priv, -struct rsnd_adg *adg) +static int rsnd_adg_get_clkout (struct rsnd_priv *priv,struct rsnd_adg *adg) {struct clk *clk;struct device *dev =rsnd_priv_to_dev (priv);
@@ -459,7 +458,10 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,* ADG supports BRRA/BRRB output only * this means all clkout0/1/2/3 will be same rate */ - prop =of_find_property (np,"clock-frequency" ,NULL );; + prop =of_find_property (np,"clock-frequency" ,NULL ); +if (!prop) +return -EINVAL ; + req_size = prop->length /sizeof (u32);of_property_read_u32_array (np,"clock-frequency" , req_rate, req_size);
@@ -568,6 +570,7 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,dev_dbg (dev,"clkout %d : %p : %ld\n" , i, clk,clk_get_rate (clk));dev_dbg (dev,"BRGCKR = 0x%08x, BRRA/BRRB = 0x%x/0x%x\n" , ckr, rbga, rbgb); +return 0 ; }int rsnd_adg_probe (struct rsnd_priv *priv)
@@ -589,7 +592,9 @@ int rsnd_adg_probe(struct rsnd_priv *priv)return ret;rsnd_adg_get_clkin (priv, adg); -rsnd_adg_get_clkout (priv, adg); + ret =rsnd_adg_get_clkout (priv, adg); +if (ret) +return ret;if (of_get_property (np,"clkout-lr-asynchronous" ,NULL )) adg->flags =LRCLK_ASYNC ;
Signature · 1 line
2.11.0
Hi Marek
Quoted 8 lines
In case the "clock-frequency" DT property is not present, the
of_find_property(np, "clock-frequency", NULL)will return NULL and the subsequentreq_size=prop->length/ sizeof(u32); will trigger a NULL pointer dereference.This patch adds check for the NULL return value and propagates the error into the caller of the function.
Quoted 7 lines
Signed-off-by Marek Vasut <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Hiroyuki Yokoyama <[email protected]>Cc Kuninori Morimoto <[email protected]>Cc Mark Brown <[email protected]>---
Thank you for your patch, it was my fail.
But your patch will breaks Lager board sound
(= it doesn't need clkout, and have no "clock-frequency")
I will try to fix this issue
Quoted 51 lines
sound/soc/sh/rcar/adg.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)sound/soc/sh/rcar/adg.c +9
-4@@ -425,8 +425,7 @@ static void rsnd_adg_get_clkin(struct rsnd_priv *priv,dev_dbg (dev,"clk %d : %p : %ld\n" , i, clk,clk_get_rate (clk)); } -static void rsnd_adg_get_clkout (struct rsnd_priv *priv, -struct rsnd_adg *adg) +static int rsnd_adg_get_clkout (struct rsnd_priv *priv,struct rsnd_adg *adg) {struct clk *clk;struct device *dev =rsnd_priv_to_dev (priv);@@ -459,7 +458,10 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,* ADG supports BRRA/BRRB output only * this means all clkout0/1/2/3 will be same rate */ - prop =of_find_property (np,"clock-frequency" ,NULL );; + prop =of_find_property (np,"clock-frequency" ,NULL ); +if (!prop) +return -EINVAL ; + req_size = prop->length /sizeof (u32);of_property_read_u32_array (np,"clock-frequency" , req_rate, req_size);@@ -568,6 +570,7 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,dev_dbg (dev,"clkout %d : %p : %ld\n" , i, clk,clk_get_rate (clk));dev_dbg (dev,"BRGCKR = 0x%08x, BRRA/BRRB = 0x%x/0x%x\n" , ckr, rbga, rbgb); +return 0 ; }int rsnd_adg_probe (struct rsnd_priv *priv)@@ -589,7 +592,9 @@ int rsnd_adg_probe(struct rsnd_priv *priv)return ret;rsnd_adg_get_clkin (priv, adg); -rsnd_adg_get_clkout (priv, adg); + ret =rsnd_adg_get_clkout (priv, adg); +if (ret) +return ret;if (of_get_property (np,"clkout-lr-asynchronous" ,NULL )) adg->flags =LRCLK_ASYNC ;Signature · 1 line
2.11.0
Quoted 2 lines · Kuninori Morimoto
Hi Marek
Hi!
Quoted 16 lines
Quoted 8 lines
In case the "clock-frequency" DT property is not present, the
of_find_property(np, "clock-frequency", NULL)will return NULL and the subsequentreq_size=prop->length/ sizeof(u32); will trigger a NULL pointer dereference.This patch adds check for the NULL return value and propagates the error into the caller of the function.
Quoted 7 lines
Signed-off-by Marek Vasut <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Hiroyuki Yokoyama <[email protected]>Cc Kuninori Morimoto <[email protected]>Cc Mark Brown <[email protected]>---
Quoted 5 lines
Thank you for your patch, it was my fail.
But your patch will breaks Lager board sound
(= it doesn't need clkout, and have no "clock-frequency")I will try to fix this issue
Cool, thanks!
Quoted 51 lines
Quoted 51 lines
sound/soc/sh/rcar/adg.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)sound/soc/sh/rcar/adg.c +9
-4@@ -425,8 +425,7 @@ static void rsnd_adg_get_clkin(struct rsnd_priv *priv,dev_dbg (dev,"clk %d : %p : %ld\n" , i, clk,clk_get_rate (clk)); } -static void rsnd_adg_get_clkout (struct rsnd_priv *priv, -struct rsnd_adg *adg) +static int rsnd_adg_get_clkout (struct rsnd_priv *priv,struct rsnd_adg *adg) {struct clk *clk;struct device *dev =rsnd_priv_to_dev (priv);@@ -459,7 +458,10 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,* ADG supports BRRA/BRRB output only * this means all clkout0/1/2/3 will be same rate */ - prop =of_find_property (np,"clock-frequency" ,NULL );; + prop =of_find_property (np,"clock-frequency" ,NULL ); +if (!prop) +return -EINVAL ; + req_size = prop->length /sizeof (u32);of_property_read_u32_array (np,"clock-frequency" , req_rate, req_size);@@ -568,6 +570,7 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,dev_dbg (dev,"clkout %d : %p : %ld\n" , i, clk,clk_get_rate (clk));dev_dbg (dev,"BRGCKR = 0x%08x, BRRA/BRRB = 0x%x/0x%x\n" , ckr, rbga, rbgb); +return 0 ; }int rsnd_adg_probe (struct rsnd_priv *priv)@@ -589,7 +592,9 @@ int rsnd_adg_probe(struct rsnd_priv *priv)return ret;rsnd_adg_get_clkin (priv, adg); -rsnd_adg_get_clkout (priv, adg); + ret =rsnd_adg_get_clkout (priv, adg); +if (ret) +return ret;if (of_get_property (np,"clkout-lr-asynchronous" ,NULL )) adg->flags =LRCLK_ASYNC ;Signature · 1 line
2.11.0
Signature · 2 lines
Best regards, Marek Vasut