Skip to content

Commit fc55e63

Browse files
Dan Carpentergregkh
authored andcommitted
counter: fix an IS_ERR() vs NULL bug
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 <[email protected]> Acked-by: William Breathitt Gray <[email protected]> Signed-off-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/20220111173243.GA2192@kili Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a6501e4 commit fc55e63

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

drivers/counter/counter-core.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ struct counter_device *counter_alloc(size_t sizeof_priv)
9090
int err;
9191

9292
ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
93-
if (!ch) {
94-
err = -ENOMEM;
95-
goto err_alloc_ch;
96-
}
93+
if (!ch)
94+
return NULL;
9795

9896
counter = &ch->counter;
9997
dev = &counter->dev;
@@ -123,9 +121,8 @@ struct counter_device *counter_alloc(size_t sizeof_priv)
123121
err_ida_alloc:
124122

125123
kfree(ch);
126-
err_alloc_ch:
127124

128-
return ERR_PTR(err);
125+
return NULL;
129126
}
130127
EXPORT_SYMBOL_GPL(counter_alloc);
131128

@@ -208,12 +205,12 @@ struct counter_device *devm_counter_alloc(struct device *dev, size_t sizeof_priv
208205
int err;
209206

210207
counter = counter_alloc(sizeof_priv);
211-
if (IS_ERR(counter))
212-
return counter;
208+
if (!counter)
209+
return NULL;
213210

214211
err = devm_add_action_or_reset(dev, devm_counter_put, counter);
215212
if (err < 0)
216-
return ERR_PTR(err);
213+
return NULL;
217214

218215
return counter;
219216
}

0 commit comments

Comments
 (0)