Skip to content

Commit

Permalink
counter: fix an IS_ERR() vs NULL bug
Browse files Browse the repository at this point in the history
There are 8 callers for devm_counter_alloc() and they all check for NULL
instead of error pointers.  I think NULL is the better thing to return
for allocation functions so update counter_alloc() and devm_counter_alloc()
to return NULL instead of error pointers.

Fixes: c18e276 ("counter: Provide alternative counter registration functions")
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/20220111173243.GA2192@kili
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Dan Carpenter authored and Greg Kroah-Hartman committed Jan 26, 2022
1 parent a6501e4 commit fc55e63
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions drivers/counter/counter-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ struct counter_device *counter_alloc(size_t sizeof_priv)
int err;

ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
if (!ch) {
err = -ENOMEM;
goto err_alloc_ch;
}
if (!ch)
return NULL;

counter = &ch->counter;
dev = &counter->dev;
Expand Down Expand Up @@ -123,9 +121,8 @@ struct counter_device *counter_alloc(size_t sizeof_priv)
err_ida_alloc:

kfree(ch);
err_alloc_ch:

return ERR_PTR(err);
return NULL;
}
EXPORT_SYMBOL_GPL(counter_alloc);

Expand Down Expand Up @@ -208,12 +205,12 @@ struct counter_device *devm_counter_alloc(struct device *dev, size_t sizeof_priv
int err;

counter = counter_alloc(sizeof_priv);
if (IS_ERR(counter))
return counter;
if (!counter)
return NULL;

err = devm_add_action_or_reset(dev, devm_counter_put, counter);
if (err < 0)
return ERR_PTR(err);
return NULL;

return counter;
}
Expand Down

0 comments on commit fc55e63

Please sign in to comment.