mirror of
https://github.com/richardghirst/PiBits.git
synced 2024-11-28 12:24:11 +01:00
Refactor dev_write prior to allowing it to take partial strings.
This commit is contained in:
parent
e993a088eb
commit
b14044eba1
@ -403,18 +403,21 @@ static ssize_t dev_read(struct file *filp,char *buf,size_t count,loff_t *f_pos)
|
||||
}
|
||||
|
||||
static ssize_t dev_write(struct file *filp,const char *buf,size_t count,loff_t *f_pos)
|
||||
{
|
||||
char str[32];
|
||||
|
||||
if (count > 31) count = 31;
|
||||
if (copy_from_user(str, buf, count)) {
|
||||
return -EFAULT;
|
||||
}
|
||||
str[count] = '\0';
|
||||
|
||||
// Process the complete user string.
|
||||
{
|
||||
int servo;
|
||||
int cnt;
|
||||
int n;
|
||||
char str[32];
|
||||
char dummy;
|
||||
|
||||
cnt = count < 32 ? count : 31;
|
||||
if (copy_from_user(str, buf, cnt)) {
|
||||
return -EFAULT;
|
||||
}
|
||||
str[cnt] = '\0';
|
||||
n = sscanf(str, "%d=%d\n%c", &servo, &cnt, &dummy);
|
||||
if (n != 2) {
|
||||
printk(KERN_WARNING "ServoBlaster: Failed to parse command (n=%d)\n", n);
|
||||
@ -443,6 +446,7 @@ static ssize_t dev_write(struct file *filp,const char *buf,size_t count,loff_t *
|
||||
}
|
||||
written_data[servo] = cnt; // Record data for use by dev_read
|
||||
local_irq_enable();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user