Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

misc: eeprom/idt_89hpesx: Switch to memdup_user_nul() helper

Use memdup_user_nul() helper instead of open-coding to simplify the code.

Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Link: https://lore.kernel.org/r/20230810121608.2110328-1-ruanjinjie@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ruan Jinjie and committed by
Greg Kroah-Hartman
183238ff 25a7de32

+3 -9
+3 -9
drivers/misc/eeprom/idt_89hpesx.c
··· 913 913 return 0; 914 914 915 915 /* Copy data from User-space */ 916 - buf = kmalloc(count + 1, GFP_KERNEL); 917 - if (!buf) 918 - return -ENOMEM; 919 - 920 - if (copy_from_user(buf, ubuf, count)) { 921 - ret = -EFAULT; 922 - goto free_buf; 923 - } 924 - buf[count] = 0; 916 + buf = memdup_user_nul(ubuf, count); 917 + if (IS_ERR(buf)) 918 + return PTR_ERR(buf); 925 919 926 920 /* Find position of colon in the buffer */ 927 921 colon_ch = strnchr(buf, count, ':');