Skip to content

Commit dc2a633

Browse files
brglgregkh
authored andcommitted
devres: move the size check from alloc_dr() into a separate function
We will perform the same size check in devm_krealloc(). Move the relevant code into a separate helper. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Link: https://lore.kernel.org/r/20200629065008.27620-3-brgl@bgdev.pl Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 63160c0 commit dc2a633

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎drivers/base/devres.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,23 @@ static struct devres_group * node_to_group(struct devres_node *node)
8989
return NULL;
9090
}
9191

92+
static bool check_dr_size(size_t size, size_t *tot_size)
93+
{
94+
/* We must catch any near-SIZE_MAX cases that could overflow. */
95+
if (unlikely(check_add_overflow(sizeof(struct devres),
96+
size, tot_size)))
97+
return false;
98+
99+
return true;
100+
}
101+
92102
static __always_inline struct devres * alloc_dr(dr_release_t release,
93103
size_t size, gfp_t gfp, int nid)
94104
{
95105
size_t tot_size;
96106
struct devres *dr;
97107

98-
/* We must catch any near-SIZE_MAX cases that could overflow. */
99-
if (unlikely(check_add_overflow(sizeof(struct devres), size,
100-
&tot_size)))
108+
if (!check_dr_size(size, &tot_size))
101109
return NULL;
102110

103111
dr = kmalloc_node_track_caller(tot_size, gfp, nid);

0 commit comments

Comments
 (0)