]> www.infradead.org Git - users/willy/linux.git/commitdiff
devres: move the size check from alloc_dr() into a separate function
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Mon, 29 Jun 2020 06:50:04 +0000 (08:50 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 Jul 2020 12:36:02 +0000 (14:36 +0200)
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>
drivers/base/devres.c

index c34327219c3418dba8270de940d4e5e3b26a8a38..1df1fb10b2d99d6a7ce8475faad962521211ec52 100644 (file)
@@ -89,15 +89,23 @@ static struct devres_group * node_to_group(struct devres_node *node)
        return NULL;
 }
 
+static bool check_dr_size(size_t size, size_t *tot_size)
+{
+       /* We must catch any near-SIZE_MAX cases that could overflow. */
+       if (unlikely(check_add_overflow(sizeof(struct devres),
+                                       size, tot_size)))
+               return false;
+
+       return true;
+}
+
 static __always_inline struct devres * alloc_dr(dr_release_t release,
                                                size_t size, gfp_t gfp, int nid)
 {
        size_t tot_size;
        struct devres *dr;
 
-       /* We must catch any near-SIZE_MAX cases that could overflow. */
-       if (unlikely(check_add_overflow(sizeof(struct devres), size,
-                                       &tot_size)))
+       if (!check_dr_size(size, &tot_size))
                return NULL;
 
        dr = kmalloc_node_track_caller(tot_size, gfp, nid);