diff options
-rw-r--r-- | drivers/mfd/ab3550-core.c | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/drivers/mfd/ab3550-core.c b/drivers/mfd/ab3550-core.c index 3d7dce671b93..56ba1943c91d 100644 --- a/drivers/mfd/ab3550-core.c +++ b/drivers/mfd/ab3550-core.c | |||
@@ -879,20 +879,13 @@ static ssize_t ab3550_bank_write(struct file *file, | |||
879 | size_t count, loff_t *ppos) | 879 | size_t count, loff_t *ppos) |
880 | { | 880 | { |
881 | struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private; | 881 | struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private; |
882 | char buf[32]; | ||
883 | int buf_size; | ||
884 | unsigned long user_bank; | 882 | unsigned long user_bank; |
885 | int err; | 883 | int err; |
886 | 884 | ||
887 | /* Get userspace string and assure termination */ | 885 | /* Get userspace string and assure termination */ |
888 | buf_size = min(count, (sizeof(buf) - 1)); | 886 | err = kstrtoul_from_user(user_buf, count, 0, &user_bank); |
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); | ||
894 | if (err) | 887 | if (err) |
895 | return -EINVAL; | 888 | return err; |
896 | 889 | ||
897 | if (user_bank >= AB3550_NUM_BANKS) { | 890 | if (user_bank >= AB3550_NUM_BANKS) { |
898 | dev_err(&ab->i2c_client[0]->dev, | 891 | dev_err(&ab->i2c_client[0]->dev, |
@@ -902,7 +895,7 @@ static ssize_t ab3550_bank_write(struct file *file, | |||
902 | 895 | ||
903 | ab->debug_bank = user_bank; | 896 | ab->debug_bank = user_bank; |
904 | 897 | ||
905 | return buf_size; | 898 | return count; |
906 | } | 899 | } |
907 | 900 | ||
908 | static int ab3550_address_print(struct seq_file *s, void *p) | 901 | static int ab3550_address_print(struct seq_file *s, void *p) |
@@ -923,27 +916,21 @@ static ssize_t ab3550_address_write(struct file *file, | |||
923 | size_t count, loff_t *ppos) | 916 | size_t count, loff_t *ppos) |
924 | { | 917 | { |
925 | struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private; | 918 | struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private; |
926 | char buf[32]; | ||
927 | int buf_size; | ||
928 | unsigned long user_address; | 919 | unsigned long user_address; |
929 | int err; | 920 | int err; |
930 | 921 | ||
931 | /* Get userspace string and assure termination */ | 922 | /* Get userspace string and assure termination */ |
932 | buf_size = min(count, (sizeof(buf) - 1)); | 923 | err = kstrtoul_from_user(user_buf, count, 0, &user_address); |
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); | ||
938 | if (err) | 924 | if (err) |
939 | return -EINVAL; | 925 | return err; |
926 | |||
940 | if (user_address > 0xff) { | 927 | if (user_address > 0xff) { |
941 | dev_err(&ab->i2c_client[0]->dev, | 928 | dev_err(&ab->i2c_client[0]->dev, |
942 | "debugfs error input > 0xff\n"); | 929 | "debugfs error input > 0xff\n"); |
943 | return -EINVAL; | 930 | return -EINVAL; |
944 | } | 931 | } |
945 | ab->debug_address = user_address; | 932 | ab->debug_address = user_address; |
946 | return buf_size; | 933 | return count; |
947 | } | 934 | } |
948 | 935 | ||
949 | static int ab3550_val_print(struct seq_file *s, void *p) | 936 | static int ab3550_val_print(struct seq_file *s, void *p) |
@@ -971,21 +958,15 @@ static ssize_t ab3550_val_write(struct file *file, | |||
971 | size_t count, loff_t *ppos) | 958 | size_t count, loff_t *ppos) |
972 | { | 959 | { |
973 | struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private; | 960 | struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private; |
974 | char buf[32]; | ||
975 | int buf_size; | ||
976 | unsigned long user_val; | 961 | unsigned long user_val; |
977 | int err; | 962 | int err; |
978 | u8 regvalue; | 963 | u8 regvalue; |
979 | 964 | ||
980 | /* Get userspace string and assure termination */ | 965 | /* Get userspace string and assure termination */ |
981 | buf_size = min(count, (sizeof(buf)-1)); | 966 | err = kstrtoul_from_user(user_buf, count, 0, &user_val); |
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); | ||
987 | if (err) | 967 | if (err) |
988 | return -EINVAL; | 968 | return err; |
969 | |||
989 | if (user_val > 0xff) { | 970 | if (user_val > 0xff) { |
990 | dev_err(&ab->i2c_client[0]->dev, | 971 | dev_err(&ab->i2c_client[0]->dev, |
991 | "debugfs error input > 0xff\n"); | 972 | "debugfs error input > 0xff\n"); |
@@ -1002,7 +983,7 @@ static ssize_t ab3550_val_write(struct file *file, | |||
1002 | if (err) | 983 | if (err) |
1003 | return -EINVAL; | 984 | return -EINVAL; |
1004 | 985 | ||
1005 | return buf_size; | 986 | return count; |
1006 | } | 987 | } |
1007 | 988 | ||
1008 | static const struct file_operations ab3550_bank_fops = { | 989 | static const struct file_operations ab3550_bank_fops = { |