misc: k3_avs: Fix possible NULL pointer deference
diff mbox series

Message ID 20200214122217.24671-1-vigneshr@ti.com
State Accepted
Delegated to: Lokesh Vutla
Headers show
Series
  • misc: k3_avs: Fix possible NULL pointer deference
Related show

Commit Message

Vignesh Raghavendra Feb. 14, 2020, 12:22 p.m. UTC
Its possible that k3_avs_priv is NULL because the driver may not have
been probed yet. Therefore check if pointer is valid before
dereferencing it.

Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
---
 drivers/misc/k3_avs.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

J, KEERTHY Feb. 17, 2020, 4:44 a.m. UTC | #1
On 14/02/20 5:52 pm, Vignesh Raghavendra wrote:
> Its possible that k3_avs_priv is NULL because the driver may not have
> been probed yet. Therefore check if pointer is valid before
> dereferencing it.

Reviewed-by: Keerthy <j-keerthy@ti.com>

> 
> Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
> ---
>   drivers/misc/k3_avs.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/misc/k3_avs.c b/drivers/misc/k3_avs.c
> index c19c3c0646b7..adaf75b7165d 100644
> --- a/drivers/misc/k3_avs.c
> +++ b/drivers/misc/k3_avs.c
> @@ -190,6 +190,10 @@ int k3_avs_notify_freq(int dev_id, int clk_id, u32 freq)
>   	struct k3_avs_privdata *priv = k3_avs_priv;
>   	struct vd_data *vd;
>   
> +	/* Driver may not be probed yet */
> +	if (!priv)
> +		return -EINVAL;
> +
>   	for (vd = priv->vd_config->vds; vd->id >= 0; vd++) {
>   		if (vd->dev_id != dev_id || vd->clk_id != clk_id)
>   			continue;
>
Lokesh Vutla Feb. 27, 2020, 3:19 a.m. UTC | #2
On 14/02/20 5:52 PM, Vignesh Raghavendra wrote:
> Its possible that k3_avs_priv is NULL because the driver may not have
> been probed yet. Therefore check if pointer is valid before
> dereferencing it.
> 
> Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>

Applied to u-boot-ti

Thanks and regards,
Lokesh

Patch
diff mbox series

diff --git a/drivers/misc/k3_avs.c b/drivers/misc/k3_avs.c
index c19c3c0646b7..adaf75b7165d 100644
--- a/drivers/misc/k3_avs.c
+++ b/drivers/misc/k3_avs.c
@@ -190,6 +190,10 @@  int k3_avs_notify_freq(int dev_id, int clk_id, u32 freq)
 	struct k3_avs_privdata *priv = k3_avs_priv;
 	struct vd_data *vd;
 
+	/* Driver may not be probed yet */
+	if (!priv)
+		return -EINVAL;
+
 	for (vd = priv->vd_config->vds; vd->id >= 0; vd++) {
 		if (vd->dev_id != dev_id || vd->clk_id != clk_id)
 			continue;