mfd: syscon: Fix null pointer dereference in of_syscon_register

Message ID 20231204092443.2462115-1-chentao@kylinos.cn
State New
Headers
Series mfd: syscon: Fix null pointer dereference in of_syscon_register |

Commit Message

Kunwu Chan Dec. 4, 2023, 9:24 a.m. UTC
  kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Fixes: e15d7f2b81d2 ("mfd: syscon: Use a unique name with regmap_config")
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 drivers/mfd/syscon.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Arnd Bergmann Dec. 4, 2023, 10:06 a.m. UTC | #1
On Mon, Dec 4, 2023, at 10:24, Kunwu Chan wrote:
> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.
>
> Fixes: e15d7f2b81d2 ("mfd: syscon: Use a unique name with regmap_config")
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>

Reviewed-by: Arnd Bergmann <arnd@arndb.de>
  
Lee Jones Dec. 7, 2023, 4:05 p.m. UTC | #2
On Mon, 04 Dec 2023 17:24:43 +0800, Kunwu Chan wrote:
> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.
> 
> 

Applied, thanks!

[1/1] mfd: syscon: Fix null pointer dereference in of_syscon_register
      commit: 41673c66b3d0c09915698fec5c13b24336f18dd1

--
Lee Jones [李琼斯]
  

Patch

diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 57b29c325131..c9550368d9ea 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -105,6 +105,10 @@  static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
 	}
 
 	syscon_config.name = kasprintf(GFP_KERNEL, "%pOFn@%pa", np, &res.start);
+	if (!syscon_config.name) {
+		ret = -ENOMEM;
+		goto err_regmap;
+	}
 	syscon_config.reg_stride = reg_io_width;
 	syscon_config.val_bits = reg_io_width * 8;
 	syscon_config.max_register = resource_size(&res) - reg_io_width;