Commit 99be3e37 authored by Vladimir Zapolskiy's avatar Vladimir Zapolskiy Committed by Alexandre Belloni

rtc: m48t59: clean up m48t59_nvram_read()/m48t59_nvram_write()

The change removes redundant sysfs binary file boundary checks, since
this task is already done on caller side in fs/sysfs/file.c

Spinlock acquisition/release is moved out of the loop body to get
atomic states of NVRAM reading and writing operations.
Signed-off-by: default avatarVladimir Zapolskiy <vz@mleia.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
parent c472d7de
...@@ -345,11 +345,12 @@ static ssize_t m48t59_nvram_read(struct file *filp, struct kobject *kobj, ...@@ -345,11 +345,12 @@ static ssize_t m48t59_nvram_read(struct file *filp, struct kobject *kobj,
ssize_t cnt = 0; ssize_t cnt = 0;
unsigned long flags; unsigned long flags;
for (; size > 0 && pos < pdata->offset; cnt++, size--) { spin_lock_irqsave(&m48t59->lock, flags);
spin_lock_irqsave(&m48t59->lock, flags);
for (; cnt < size; cnt++)
*buf++ = M48T59_READ(cnt); *buf++ = M48T59_READ(cnt);
spin_unlock_irqrestore(&m48t59->lock, flags);
} spin_unlock_irqrestore(&m48t59->lock, flags);
return cnt; return cnt;
} }
...@@ -365,11 +366,12 @@ static ssize_t m48t59_nvram_write(struct file *filp, struct kobject *kobj, ...@@ -365,11 +366,12 @@ static ssize_t m48t59_nvram_write(struct file *filp, struct kobject *kobj,
ssize_t cnt = 0; ssize_t cnt = 0;
unsigned long flags; unsigned long flags;
for (; size > 0 && pos < pdata->offset; cnt++, size--) { spin_lock_irqsave(&m48t59->lock, flags);
spin_lock_irqsave(&m48t59->lock, flags);
for (; cnt < size; cnt++)
M48T59_WRITE(*buf++, cnt); M48T59_WRITE(*buf++, cnt);
spin_unlock_irqrestore(&m48t59->lock, flags);
} spin_unlock_irqrestore(&m48t59->lock, flags);
return cnt; return cnt;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment