Skip to content

Commit d9d5b89

Browse files
andy-shevkuba-moo
authored andcommitted
wwan: core: Avoid returning NULL from wwan_create_dev()
Make wwan_create_dev() to return either valid or error pointer, In some cases it may return NULL. Prevent this by converting it to the respective error pointer. Fixes: 9a44c1c ("net: Add a WWAN subsystem") Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Sergey Ryazanov <ryazanov.s.a@gmail.com> Reviewed-by: Loic Poulain <loic.poulain@linaro.org> Link: https://lore.kernel.org/r/20210811124845.10955-1-andriy.shevchenko@linux.intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 700fa08 commit d9d5b89

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

drivers/net/wwan/wwan_core.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,14 @@ static struct wwan_device *wwan_create_dev(struct device *parent)
164164
goto done_unlock;
165165

166166
id = ida_alloc(&wwan_dev_ids, GFP_KERNEL);
167-
if (id < 0)
167+
if (id < 0) {
168+
wwandev = ERR_PTR(id);
168169
goto done_unlock;
170+
}
169171

170172
wwandev = kzalloc(sizeof(*wwandev), GFP_KERNEL);
171173
if (!wwandev) {
174+
wwandev = ERR_PTR(-ENOMEM);
172175
ida_free(&wwan_dev_ids, id);
173176
goto done_unlock;
174177
}
@@ -182,7 +185,8 @@ static struct wwan_device *wwan_create_dev(struct device *parent)
182185
err = device_register(&wwandev->dev);
183186
if (err) {
184187
put_device(&wwandev->dev);
185-
wwandev = NULL;
188+
wwandev = ERR_PTR(err);
189+
goto done_unlock;
186190
}
187191

188192
done_unlock:
@@ -1014,8 +1018,8 @@ int wwan_register_ops(struct device *parent, const struct wwan_ops *ops,
10141018
return -EINVAL;
10151019

10161020
wwandev = wwan_create_dev(parent);
1017-
if (!wwandev)
1018-
return -ENOMEM;
1021+
if (IS_ERR(wwandev))
1022+
return PTR_ERR(wwandev);
10191023

10201024
if (WARN_ON(wwandev->ops)) {
10211025
wwan_remove_dev(wwandev);

0 commit comments

Comments
 (0)