diff mbox series

EDAC/versal: Fix possible null pointer dereference in emif_get_id()

Message ID 20240709135830.1172936-1-make24@iscas.ac.cn (mailing list archive)
State New
Headers show
Series EDAC/versal: Fix possible null pointer dereference in emif_get_id() | expand

Commit Message

Ma Ke July 9, 2024, 1:58 p.m. UTC
In emif_get_id(), of_get_address() may return NULL which is later
dereferenced. Fix this bug by adding NULL check.

Fixes: 6f15b178cd63 ("EDAC/versal: Add a Xilinx Versal memory controller driver")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
 drivers/edac/versal_edac.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Datta, Shubhrajyoti July 9, 2024, 3 p.m. UTC | #1
[AMD Official Use Only - AMD Internal Distribution Only]

> -----Original Message-----
> From: Ma Ke <make24@iscas.ac.cn>
> Sent: Tuesday, July 9, 2024 7:29 PM
> To: Datta, Shubhrajyoti <shubhrajyoti.datta@amd.com>; Potthuri, Sai
> Krishna <sai.krishna.potthuri@amd.com>; bp@alien8.de;
> tony.luck@intel.com; james.morse@arm.com; mchehab@kernel.org;
> rric@kernel.org
> Cc: linux-edac@vger.kernel.org; linux-kernel@vger.kernel.org; Ma Ke
> <make24@iscas.ac.cn>
> Subject: [PATCH] EDAC/versal: Fix possible null pointer dereference in
> emif_get_id()
>
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
>
>
> In emif_get_id(), of_get_address() may return NULL which is later
> dereferenced. Fix this bug by adding NULL check.
>
> Fixes: 6f15b178cd63 ("EDAC/versal: Add a Xilinx Versal memory controller
> driver")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
>  drivers/edac/versal_edac.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/drivers/edac/versal_edac.c b/drivers/edac/versal_edac.c index
> a556d23e8261..6ab87277d439 100644
> --- a/drivers/edac/versal_edac.c
> +++ b/drivers/edac/versal_edac.c
> @@ -1053,6 +1053,9 @@ static u32 emif_get_id(struct device_node *node)
>         const __be32 *addrp;
>
>         addrp = of_get_address(node, 0, NULL, NULL);
> +       if (!addrp)
> +               return -EINVAL;
> +
>         my_addr = (u32)of_translate_address(node, addrp);
>
>         for_each_matching_node(np, xlnx_edac_match) { @@ -1060,6 +1063,9
> @@ static u32 emif_get_id(struct device_node *node)
>                         continue;
>
>                 addrp = of_get_address(np, 0, NULL, NULL);
> +               if (!addrp)
> +                       return _EINVAL;
Please fix the typo.
> +
>                 addr = (u32)of_translate_address(np, addrp);
>
>                 edac_printk(KERN_INFO, EDAC_MC,
> --
> 2.25.1
diff mbox series

Patch

diff --git a/drivers/edac/versal_edac.c b/drivers/edac/versal_edac.c
index a556d23e8261..6ab87277d439 100644
--- a/drivers/edac/versal_edac.c
+++ b/drivers/edac/versal_edac.c
@@ -1053,6 +1053,9 @@  static u32 emif_get_id(struct device_node *node)
 	const __be32 *addrp;
 
 	addrp = of_get_address(node, 0, NULL, NULL);
+	if (!addrp)
+		return -EINVAL;
+
 	my_addr = (u32)of_translate_address(node, addrp);
 
 	for_each_matching_node(np, xlnx_edac_match) {
@@ -1060,6 +1063,9 @@  static u32 emif_get_id(struct device_node *node)
 			continue;
 
 		addrp = of_get_address(np, 0, NULL, NULL);
+		if (!addrp)
+			return _EINVAL;
+
 		addr = (u32)of_translate_address(np, addrp);
 
 		edac_printk(KERN_INFO, EDAC_MC,