Skip to contentSkip to conversation

iio: core: Fix an error pointer vs NULL bug in devm_iio_device_alloc()

PATCH In review Dan Carpenter 3 participants 3 messages May 15, 2021 – May 16, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: core: Fix an error pointer vs NULL bug in devm_iio_device_alloc()

The devm_iio_device_alloc() function is supposed to return NULL and not error pointers. Returning an error pointer will lead to a crash in the callers.

Fixes d240dc25e3b8 ("iio: core: simplify some devm functions")
---
 drivers/iio/industrialio-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/industrialio-core.c +1 -1
index bfa20a346f71..75e92bac78f3 100644
@@ -1711,7 +1711,7 @@ struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv)
 	ret = devm_add_action_or_reset(parent, devm_iio_device_release,
 				       iio_dev);
 	if (ret)
-		return ERR_PTR(ret);
+		return NULL;
 
 	return iio_dev;
 }
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Dan Carpenter

The devm_iio_device_alloc() function is supposed to return NULL and not error pointers. Returning an error pointer will lead to a crash in the callers.

oh
that's a good catch;

Quoted 22 lines
Fixes d240dc25e3b8 ("iio: core: simplify some devm functions")
---
 drivers/iio/industrialio-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/industrialio-core.c +1 -2
index bfa20a346f71..75e92bac78f3 100644
@@ -1711,7 +1711,7 @@ struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv)
        ret = devm_add_action_or_reset(parent, devm_iio_device_release,
                                       iio_dev);
        if (ret)
-               return ERR_PTR(ret);
+               return NULL;
 
        return iio_dev;
 }
--

2.30.2

maintainer
#2 lore raw
Quoted 11 lines · On Sun, 16 May 2021 08:30:20 +0300 Alexandru Ardelean <[email protected]>…
Quoted 5 lines · Dan Carpenter

The devm_iio_device_alloc() function is supposed to return NULL and not error pointers. Returning an error pointer will lead to a crash in the callers.

oh
that's a good catch;

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to poke at it.

Thanks,

Jonathan

Quoted 23 lines
Quoted 23 lines
Fixes d240dc25e3b8 ("iio: core: simplify some devm functions")
---
 drivers/iio/industrialio-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/industrialio-core.c +1 -2
index bfa20a346f71..75e92bac78f3 100644
@@ -1711,7 +1711,7 @@ struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv)
        ret = devm_add_action_or_reset(parent, devm_iio_device_release,
                                       iio_dev);
        if (ret)
-               return ERR_PTR(ret);
+               return NULL;
 
        return iio_dev;
 }
--

2.30.2