linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: mux: demux-pinctrl: handle failure case of devm_kstrdup()
@ 2018-12-01 10:01 Nicholas Mc Guire
  2018-12-04 11:16 ` Peter Rosin
  2018-12-04 14:11 ` Peter Rosin
  0 siblings, 2 replies; 10+ messages in thread
From: Nicholas Mc Guire @ 2018-12-01 10:01 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Peter Rosin, linux-i2c, linux-kernel, Nicholas Mc Guire

devm_kstrdup() may return NULL if internal allocation failed.
Thus using  name, value  is unsafe without being checked. As
i2c_demux_pinctrl_probe() can return -ENOMEM in other cases
a dev_err() message is included to make the failure location
clear.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Fixes: e35478eac030 ("i2c: mux: demux-pinctrl: run properly with multiple instances")
---

Problem located with experimental coccinelle script

Q: The use of devm_kstrdup() seems a bit odd while technically not wrong,
   personally I think devm_kasprintf() would be more suitable here.

Patch was compile tested with: multi_v7_defconfig 
(implies I2C_DEMUX_PINCTRL=y)

Patch is against 4.20-rc4 (localversion-next is next-20181130)

 drivers/i2c/muxes/i2c-demux-pinctrl.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/i2c/muxes/i2c-demux-pinctrl.c b/drivers/i2c/muxes/i2c-demux-pinctrl.c
index 035032e..c466999 100644
--- a/drivers/i2c/muxes/i2c-demux-pinctrl.c
+++ b/drivers/i2c/muxes/i2c-demux-pinctrl.c
@@ -244,6 +244,12 @@ 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) {
+			dev_err(&pdev->dev,
+				"chan %d name, value allocation failed\n", i);
+			err = -ENOMEM;
+			goto err_rollback;
+		}
 		props[i].length = 3;
 
 		of_changeset_init(&priv->chan[i].chgset);
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-12-04 14:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-01 10:01 [PATCH] i2c: mux: demux-pinctrl: handle failure case of devm_kstrdup() Nicholas Mc Guire
2018-12-04 11:16 ` Peter Rosin
2018-12-04 11:43   ` Nicholas Mc Guire
2018-12-04 12:13   ` Nicholas Mc Guire
2018-12-04 13:49     ` Peter Rosin
2018-12-04 14:25       ` Nicholas Mc Guire
2018-12-04 14:29         ` Peter Rosin
2018-12-04 14:11 ` Peter Rosin
2018-12-04 14:36   ` Nicholas Mc Guire
2018-12-04 14:50     ` Peter Rosin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).