Skip to contentSkip to conversation

misc: k3_avs: Fix possible NULL pointer deference

PATCH New Vignesh Raghavendra 3 participants 3 messages Feb 14, 2020 – Feb 27, 2020 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: k3_avs: Fix possible NULL pointer deference

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.

---
 drivers/misc/k3_avs.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/misc/k3_avs.c +4 -0
index c19c3c0646b7..adaf75b7165d 100644
@@ -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;
Signature · 1 line
2.25.0
#1 lore raw

PATCH 1/1 misc: k3_avs: Fix possible NULL pointer deference

Quoted 3 lines · Vignesh Raghavendra

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.

Quoted 22 lines
---
  drivers/misc/k3_avs.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/misc/k3_avs.c +4 -0
index c19c3c0646b7..adaf75b7165d 100644
@@ -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;