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

platform/x86: apple-gmux: return -EFAULT if copy fails

The copy_to/from_user() functions return the number of bytes remaining
to be copied, but we want to return -EFAULT to the user.

Fixes: ce3fef2eb235 ("platform/x86: apple-gmux: add debugfs interface")
Signed-off-by: Dan Carpenter <error27@gmail.com>
Reviewed-by: Orlando Chamberlain <orlandlch.dev@gmail.com>
Link: https://lore.kernel.org/r/0bdfa8c2-cb22-4bec-8773-584060613043@kili.mountain
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

Dan Carpenter and committed by
Hans de Goede
f0f2903d ad3d0ee8

+6 -7
+6 -7
drivers/platform/x86/apple-gmux.c
··· 694 694 const char __user *userbuf, size_t count, loff_t *ppos) 695 695 { 696 696 struct apple_gmux_data *gmux_data = file->private_data; 697 - int ret; 698 697 699 698 if (*ppos) 700 699 return -EINVAL; ··· 701 702 if (count == 1) { 702 703 u8 data; 703 704 704 - ret = copy_from_user(&data, userbuf, 1); 705 - if (ret) 706 - return ret; 705 + if (copy_from_user(&data, userbuf, 1)) 706 + return -EFAULT; 707 + 707 708 gmux_write8(gmux_data, gmux_data->selected_port, data); 708 709 } else if (count == 4) { 709 710 u32 data; 710 711 711 - ret = copy_from_user(&data, userbuf, 4); 712 - if (ret) 713 - return ret; 712 + if (copy_from_user(&data, userbuf, 4)) 713 + return -EFAULT; 714 + 714 715 gmux_write32(gmux_data, gmux_data->selected_port, data); 715 716 } else 716 717 return -EINVAL;