Commit 9f5610e20b322347ce3e55e75a78965717a62412
Committed by
Florian Tobias Schandinat
1 parent
c1f58f1e1e
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
video/via: Convert to kstrtou8_from_user
This patch replaces the code for getting an number from a userspace buffer by a simple call to kstrou8_from_user. This makes it easier to read and less error prone. Signed-off-by: Peter Huewe <peterhuewe@gmx.de> Acked-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Showing 1 changed file with 12 additions and 22 deletions Side-by-side Diff
drivers/video/via/viafbdev.c
... | ... | @@ -1276,17 +1276,12 @@ |
1276 | 1276 | static ssize_t viafb_dfph_proc_write(struct file *file, |
1277 | 1277 | const char __user *buffer, size_t count, loff_t *pos) |
1278 | 1278 | { |
1279 | - char buf[20]; | |
1280 | - u8 reg_val = 0; | |
1281 | - unsigned long length; | |
1282 | - if (count < 1) | |
1283 | - return -EINVAL; | |
1284 | - length = count > 20 ? 20 : count; | |
1285 | - if (copy_from_user(&buf[0], buffer, length)) | |
1286 | - return -EFAULT; | |
1287 | - buf[length - 1] = '\0'; /*Ensure end string */ | |
1288 | - if (kstrtou8(buf, 0, ®_val) < 0) | |
1289 | - return -EINVAL; | |
1279 | + int err; | |
1280 | + u8 reg_val; | |
1281 | + err = kstrtou8_from_user(buffer, count, 0, ®_val); | |
1282 | + if (err) | |
1283 | + return err; | |
1284 | + | |
1290 | 1285 | viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f); |
1291 | 1286 | return count; |
1292 | 1287 | } |
... | ... | @@ -1316,17 +1311,12 @@ |
1316 | 1311 | static ssize_t viafb_dfpl_proc_write(struct file *file, |
1317 | 1312 | const char __user *buffer, size_t count, loff_t *pos) |
1318 | 1313 | { |
1319 | - char buf[20]; | |
1320 | - u8 reg_val = 0; | |
1321 | - unsigned long length; | |
1322 | - if (count < 1) | |
1323 | - return -EINVAL; | |
1324 | - length = count > 20 ? 20 : count; | |
1325 | - if (copy_from_user(&buf[0], buffer, length)) | |
1326 | - return -EFAULT; | |
1327 | - buf[length - 1] = '\0'; /*Ensure end string */ | |
1328 | - if (kstrtou8(buf, 0, ®_val) < 0) | |
1329 | - return -EINVAL; | |
1314 | + int err; | |
1315 | + u8 reg_val; | |
1316 | + err = kstrtou8_from_user(buffer, count, 0, ®_val); | |
1317 | + if (err) | |
1318 | + return err; | |
1319 | + | |
1330 | 1320 | viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f); |
1331 | 1321 | return count; |
1332 | 1322 | } |