Commit 402fb487005d0fcbd4ce627b10426b3491ac0590
Committed by
Samuel Ortiz
1 parent
914e6d4e36
Exists in
master
and in
4 other branches
mfd: Use kstrtoul_from_user in ab3550
This patch replaces the code for getting an unsigned long from a userspace buffer by a simple call to kstroul_from_user. This makes it easier to read and less error prone. Signed-off-by: Peter Huewe <peterhuewe@gmx.de> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Showing 1 changed file with 11 additions and 30 deletions Side-by-side Diff
drivers/mfd/ab3550-core.c
... | ... | @@ -879,20 +879,13 @@ |
879 | 879 | size_t count, loff_t *ppos) |
880 | 880 | { |
881 | 881 | struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private; |
882 | - char buf[32]; | |
883 | - int buf_size; | |
884 | 882 | unsigned long user_bank; |
885 | 883 | int err; |
886 | 884 | |
887 | 885 | /* Get userspace string and assure termination */ |
888 | - buf_size = min(count, (sizeof(buf) - 1)); | |
889 | - if (copy_from_user(buf, user_buf, buf_size)) | |
890 | - return -EFAULT; | |
891 | - buf[buf_size] = 0; | |
892 | - | |
893 | - err = strict_strtoul(buf, 0, &user_bank); | |
886 | + err = kstrtoul_from_user(user_buf, count, 0, &user_bank); | |
894 | 887 | if (err) |
895 | - return -EINVAL; | |
888 | + return err; | |
896 | 889 | |
897 | 890 | if (user_bank >= AB3550_NUM_BANKS) { |
898 | 891 | dev_err(&ab->i2c_client[0]->dev, |
... | ... | @@ -902,7 +895,7 @@ |
902 | 895 | |
903 | 896 | ab->debug_bank = user_bank; |
904 | 897 | |
905 | - return buf_size; | |
898 | + return count; | |
906 | 899 | } |
907 | 900 | |
908 | 901 | static int ab3550_address_print(struct seq_file *s, void *p) |
909 | 902 | |
910 | 903 | |
911 | 904 | |
... | ... | @@ -923,27 +916,21 @@ |
923 | 916 | size_t count, loff_t *ppos) |
924 | 917 | { |
925 | 918 | struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private; |
926 | - char buf[32]; | |
927 | - int buf_size; | |
928 | 919 | unsigned long user_address; |
929 | 920 | int err; |
930 | 921 | |
931 | 922 | /* Get userspace string and assure termination */ |
932 | - buf_size = min(count, (sizeof(buf) - 1)); | |
933 | - if (copy_from_user(buf, user_buf, buf_size)) | |
934 | - return -EFAULT; | |
935 | - buf[buf_size] = 0; | |
936 | - | |
937 | - err = strict_strtoul(buf, 0, &user_address); | |
923 | + err = kstrtoul_from_user(user_buf, count, 0, &user_address); | |
938 | 924 | if (err) |
939 | - return -EINVAL; | |
925 | + return err; | |
926 | + | |
940 | 927 | if (user_address > 0xff) { |
941 | 928 | dev_err(&ab->i2c_client[0]->dev, |
942 | 929 | "debugfs error input > 0xff\n"); |
943 | 930 | return -EINVAL; |
944 | 931 | } |
945 | 932 | ab->debug_address = user_address; |
946 | - return buf_size; | |
933 | + return count; | |
947 | 934 | } |
948 | 935 | |
949 | 936 | static int ab3550_val_print(struct seq_file *s, void *p) |
950 | 937 | |
951 | 938 | |
... | ... | @@ -971,21 +958,15 @@ |
971 | 958 | size_t count, loff_t *ppos) |
972 | 959 | { |
973 | 960 | struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private; |
974 | - char buf[32]; | |
975 | - int buf_size; | |
976 | 961 | unsigned long user_val; |
977 | 962 | int err; |
978 | 963 | u8 regvalue; |
979 | 964 | |
980 | 965 | /* Get userspace string and assure termination */ |
981 | - buf_size = min(count, (sizeof(buf)-1)); | |
982 | - if (copy_from_user(buf, user_buf, buf_size)) | |
983 | - return -EFAULT; | |
984 | - buf[buf_size] = 0; | |
985 | - | |
986 | - err = strict_strtoul(buf, 0, &user_val); | |
966 | + err = kstrtoul_from_user(user_buf, count, 0, &user_val); | |
987 | 967 | if (err) |
988 | - return -EINVAL; | |
968 | + return err; | |
969 | + | |
989 | 970 | if (user_val > 0xff) { |
990 | 971 | dev_err(&ab->i2c_client[0]->dev, |
991 | 972 | "debugfs error input > 0xff\n"); |
... | ... | @@ -1002,7 +983,7 @@ |
1002 | 983 | if (err) |
1003 | 984 | return -EINVAL; |
1004 | 985 | |
1005 | - return buf_size; | |
986 | + return count; | |
1006 | 987 | } |
1007 | 988 | |
1008 | 989 | static const struct file_operations ab3550_bank_fops = { |