slimbus: ngd: Fix to avoid potential NULL pointer dereference
diff mbox series

Message ID 20190319012523.14644-1-pakki001@umn.edu
State New
Headers show
Series
  • slimbus: ngd: Fix to avoid potential NULL pointer dereference
Related show

Commit Message

Aditya Pakki March 19, 2019, 1:25 a.m. UTC
In of_qcom_slim_ngd_register, of_match_node may fail and return a NULL
pointer. This patch avoids such a scenario leading to NULL pointer
dereference.

Fixes: 458a445deb9c ("slimbus: ngd: Fix build error on x86")
Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/slimbus/qcom-ngd-ctrl.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Srinivas Kandagatla March 20, 2019, 2:47 p.m. UTC | #1
On 19/03/2019 01:25, Aditya Pakki wrote:
> In of_qcom_slim_ngd_register, of_match_node may fail and return a NULL
> pointer. This patch avoids such a scenario leading to NULL pointer
> dereference.
> 
> Fixes: 458a445deb9c ("slimbus: ngd: Fix build error on x86")
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
>   drivers/slimbus/qcom-ngd-ctrl.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/slimbus/qcom-ngd-ctrl.c b/drivers/slimbus/qcom-ngd-ctrl.c
> index 71f094c9ec68..9cc7256028c9 100644
> --- a/drivers/slimbus/qcom-ngd-ctrl.c
> +++ b/drivers/slimbus/qcom-ngd-ctrl.c
> @@ -1332,6 +1332,8 @@ static int of_qcom_slim_ngd_register(struct device *parent,
>   	u32 id;
>   
>   	match = of_match_node(qcom_slim_ngd_dt_match, parent->of_node);
> +	if (!match)
> +		return -ENXIO;

We would not even enter this path without matching compatible, so I 
think a check here is not really necessary.

thanks,
srini

Patch
diff mbox series

diff --git a/drivers/slimbus/qcom-ngd-ctrl.c b/drivers/slimbus/qcom-ngd-ctrl.c
index 71f094c9ec68..9cc7256028c9 100644
--- a/drivers/slimbus/qcom-ngd-ctrl.c
+++ b/drivers/slimbus/qcom-ngd-ctrl.c
@@ -1332,6 +1332,8 @@  static int of_qcom_slim_ngd_register(struct device *parent,
 	u32 id;
 
 	match = of_match_node(qcom_slim_ngd_dt_match, parent->of_node);
+	if (!match)
+		return -ENXIO;
 	data = match->data;
 	for_each_available_child_of_node(parent->of_node, node) {
 		if (of_property_read_u32(node, "reg", &id))