i2c: mux: demux-pinctrl: check the return value of devm_kstrdup()
authorXiaoke Wang <xkernel.wang@foxmail.com>
Thu, 3 Mar 2022 12:39:14 +0000 (20:39 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Oct 2023 12:56:43 +0000 (14:56 +0200)
[ Upstream commit 7c0195fa9a9e263df204963f88a22b21688ffb66 ]

devm_kstrdup() returns pointer to allocated string on success,
NULL on failure. So it is better to check the return value of it.

Fixes: e35478eac030 ("i2c: mux: demux-pinctrl: run properly with multiple instances")
Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/i2c/muxes/i2c-demux-pinctrl.c

index f7a7405..8e8688e 100644 (file)
@@ -243,6 +243,10 @@ static int i2c_demux_pinctrl_probe(struct platform_device *pdev)
 
                props[i].name = devm_kstrdup(&pdev->dev, "status", GFP_KERNEL);
                props[i].value = devm_kstrdup(&pdev->dev, "ok", GFP_KERNEL);
+               if (!props[i].name || !props[i].value) {
+                       err = -ENOMEM;
+                       goto err_rollback;
+               }
                props[i].length = 3;
 
                of_changeset_init(&priv->chan[i].chgset);