diff mbox series

i2c: mux: demux-pinctrl: check the return value of devm_kstrdup()

Message ID tencent_190A7366EE04872C45417894D2D33F240806@qq.com
State New
Headers show
Series i2c: mux: demux-pinctrl: check the return value of devm_kstrdup() | expand

Commit Message

Xiaoke Wang March 3, 2022, 12:39 p.m. UTC
From: Xiaoke Wang <xkernel.wang@foxmail.com>

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

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 drivers/i2c/muxes/i2c-demux-pinctrl.c | 4 ++++
 1 file changed, 4 insertions(+)

--

Comments

Wolfram Sang Sept. 20, 2023, 9:30 p.m. UTC | #1
On Thu, Mar 03, 2022 at 08:39:14PM +0800, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
> 
> devm_kstrdup() returns pointer to allocated string on success,
> NULL on failure. So it is better to check the return value of it.
> 
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>

Applied to for-current, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/muxes/i2c-demux-pinctrl.c b/drivers/i2c/muxes/i2c-demux-pinctrl.c
index 5365199..3203361 100644
--- a/drivers/i2c/muxes/i2c-demux-pinctrl.c
+++ b/drivers/i2c/muxes/i2c-demux-pinctrl.c
@@ -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);