Skip to content

Commit d388f06

Browse files
James-A-Clarkgregkh
authored andcommitted
devres: Provide krealloc_array
There is no krealloc_array equivalent in devres. Users would have to do their own multiplication overflow check so provide one. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: James Clark <james.clark@arm.com> Link: https://lore.kernel.org/r/20230509094942.396150-2-james.clark@arm.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7877cb9 commit d388f06

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Documentation/driver-api/driver-model/devres.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ MEM
364364
devm_kmalloc_array()
365365
devm_kmemdup()
366366
devm_krealloc()
367+
devm_krealloc_array()
367368
devm_kstrdup()
368369
devm_kstrdup_const()
369370
devm_kvasprintf()

include/linux/device.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ static inline void *devm_kcalloc(struct device *dev,
223223
{
224224
return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
225225
}
226+
static inline __realloc_size(3, 4) void * __must_check
227+
devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags)
228+
{
229+
size_t bytes;
230+
231+
if (unlikely(check_mul_overflow(new_n, new_size, &bytes)))
232+
return NULL;
233+
234+
return devm_krealloc(dev, p, bytes, flags);
235+
}
236+
226237
void devm_kfree(struct device *dev, const void *p);
227238
char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc;
228239
const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp);

0 commit comments

Comments
 (0)