usb: gadget: configfs: Use memcpy_and_pad()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 2 Feb 2023 15:17:36 +0000 (17:17 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 6 Feb 2023 12:46:41 +0000 (13:46 +0100)
Instead of zeroing some memory and then copying data in part or all of it,
use memcpy_and_pad().
This avoids writing some memory twice and should save a few cycles.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20230202151736.64552-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/configfs.c

index c102adbcd4e1a11f95f61a3004a536fb1c570c53..e89aa2877a33d4f9721ab56d370d0c47633c84f4 100644 (file)
@@ -915,8 +915,7 @@ static ssize_t webusb_landingPage_store(struct config_item *item, const char *pa
 
        mutex_lock(&gi->lock);
        // ensure 0 bytes are set, in case the new landing page is shorter then the old one.
-       memset(gi->landing_page, 0, sizeof(gi->landing_page));
-       memcpy(gi->landing_page, page, l);
+       memcpy_and_pad(gi->landing_page, sizeof(gi->landing_page), page, l, 0);
        mutex_unlock(&gi->lock);
 
        return len;