[v2] net: wan: Add checks for NULL. If uhdlc_priv_tsa != 1 then utdm is not initialized. And if ret != NULL then goto undo_uhdlc_init, where utdm is dereferenced. Same if dev == NULL.

Message ID 20230110114745.43894-1-eesina@astralinux.ru
State New
Headers
Series [v2] net: wan: Add checks for NULL. If uhdlc_priv_tsa != 1 then utdm is not initialized. And if ret != NULL then goto undo_uhdlc_init, where utdm is dereferenced. Same if dev == NULL. |

Commit Message

Ekaterina Esina Jan. 10, 2023, 11:47 a.m. UTC
  Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Esina Ekaterina <eesina@astralinux.ru>

v2: Add check for NULL for unmap_si_regs
---
 drivers/net/wan/fsl_ucc_hdlc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Jakub Kicinski Jan. 11, 2023, 4:44 a.m. UTC | #1
On Tue, 10 Jan 2023 14:47:45 +0300 Esina Ekaterina wrote:
> Subject: [PATCH v2] net: wan: Add checks for NULL. If uhdlc_priv_tsa != 1 then utdm is not initialized. And if ret != NULL then goto undo_uhdlc_init, where utdm is dereferenced. Same if dev == NULL.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Signed-off-by: Esina Ekaterina <eesina@astralinux.ru>
> 
> v2: Add check for NULL for unmap_si_regs
> ---

The format of your commit is wrong. You should make the commit message
look like this in git:

  net: wan: Add checks for NULL

  If uhdlc_priv_tsa != 1 then utdm is not initialized. 
  And if ret != NULL then goto undo_uhdlc_init, where 
  utdm is dereferenced. Same if dev == NULL.

  Found by Linux Verification Center (linuxtesting.org) with SVACE.
 
  Signed-off-by: Esina Ekaterina <eesina@astralinux.ru>
  ---
  v2: Add check for NULL for unmap_si_regs

But the first line (subject) is still not specific enough.
Refer to the bug that's being fixed, not how it's fixed.

Also no braces needed around single-line if blocks.
  

Patch

diff --git a/drivers/net/wan/fsl_ucc_hdlc.c b/drivers/net/wan/fsl_ucc_hdlc.c
index 22edea6ca4b8..ed7886bde727 100644
--- a/drivers/net/wan/fsl_ucc_hdlc.c
+++ b/drivers/net/wan/fsl_ucc_hdlc.c
@@ -1243,9 +1243,13 @@  static int ucc_hdlc_probe(struct platform_device *pdev)
 free_dev:
 	free_netdev(dev);
 undo_uhdlc_init:
-	iounmap(utdm->siram);
+	if (utdm != NULL) {
+		iounmap(utdm->siram);
+	}
 unmap_si_regs:
-	iounmap(utdm->si_regs);
+	if (utdm != NULL) {
+		iounmap(utdm->si_regs);
+	}
 free_utdm:
 	if (uhdlc_priv->tsa)
 		kfree(utdm);