]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
gpiolib: Replace strcpy() with memcpy()
authorDavid Laight <david.laight.linux@gmail.com>
Sat, 6 Jun 2026 20:25:57 +0000 (21:25 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Mon, 8 Jun 2026 08:15:11 +0000 (10:15 +0200)
The length of the string is calculated in order to allocate the correct
sized memory block, use the same length to copy the string.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
Link: https://patch.msgid.link/20260606202633.5018-3-david.laight.linux@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
drivers/gpio/gpiolib.c

index ac2779dbe42b5768fb4460b9cbbe3d0135da03a5..7bb6f114d64d9ce3eb930f1d79d0224bf7920c37 100644 (file)
@@ -143,13 +143,15 @@ static void desc_free_label(struct rcu_head *rh)
 static int desc_set_label(struct gpio_desc *desc, const char *label)
 {
        struct gpio_desc_label *new = NULL, *old;
+       size_t len;
 
        if (label) {
-               new = kzalloc_flex(*new, str, strlen(label) + 1);
+               len = strlen(label);
+               new = kzalloc_flex(*new, str, len + 1);
                if (!new)
                        return -ENOMEM;
 
-               strcpy(new->str, label);
+               memcpy(new->str, label, len);
        }
 
        old = rcu_replace_pointer(desc->label, new, 1);