Patchwork [RESEND] mtd: mtdchar: Exit write loop when hitting end of OTP memory

login
register
mail settings
Submitter Christian Riesch
Date May 23, 2013, 9:56 a.m.
Message ID <924bb94e-8254-46b8-8942-2d5de8ab2985@mary.at.omicron.at>
Download mbox | patch
Permalink /patch/245865/
State Superseded
Headers show

Comments

Christian Riesch - May 23, 2013, 9:56 a.m.
If a write to one time programmable memory (OTP) hits the end
of this memory area, no more data can be written and count does not
decrease anymore. We are trapped in the loop forever.

Therefore drop the remaining data if retlen != len.

Signed-off-by: Christian Riesch <christian.riesch@omicron.at>
---
 drivers/mtd/mtdchar.c |    4 ++++
 1 file changed, 4 insertions(+)

Patch

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index e0e59bf..70c18c2 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -321,6 +321,10 @@  static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t c
 		case MTD_FILE_MODE_OTP_USER:
 			ret = mtd_write_user_prot_reg(mtd, *ppos, len,
 						      &retlen, kbuf);
+
+			/* if we hit the end of otp memory, drop the rest */
+			if (retlen != len)
+				count -= len - retlen;
 			break;
 
 		case MTD_FILE_MODE_RAW: