From patchwork Fri Apr 26 17:56:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Riesch X-Patchwork-Id: 239897 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A6CDE2C0115 for ; Sat, 27 Apr 2013 03:57:12 +1000 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UVmt8-0006Or-4h; Fri, 26 Apr 2013 17:56:50 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UVmt5-0001NI-UU; Fri, 26 Apr 2013 17:56:47 +0000 Received: from ns.omicron.at ([212.183.10.25]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UVmt3-0001MS-3v for linux-mtd@lists.infradead.org; Fri, 26 Apr 2013 17:56:46 +0000 Received: from counter.omicron.at ([212.183.10.29]) by ns.omicron.at (8.13.1/8.13.1) with ESMTP id r3QHuJ06008798 for ; Fri, 26 Apr 2013 19:56:24 +0200 Received: from mary.at.omicron.at (mary.at.omicron.at [172.22.100.48]) by counter.omicron.at (8.14.4/8.14.4) with ESMTP id r3QHuJpi016171 for ; Fri, 26 Apr 2013 19:56:19 +0200 Received: from ChrRie22.omicron.at (172.22.3.184) by mary-special.at.omicron.at (172.22.100.48) with Microsoft SMTP Server id 8.3.297.1; Fri, 26 Apr 2013 19:56:18 +0200 From: Christian Riesch To: Subject: [PATCH] mtd: mtdchar: Exit write loop when hitting end of OTP memory Date: Fri, 26 Apr 2013 19:56:09 +0200 X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Message-ID: <29483dd6-387c-4b28-b689-88795e0bbbde@mary.at.omicron.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130426_135645_406892_58D802E9 X-CRM114-Status: UNSURE ( 6.61 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Christian Riesch X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 --- drivers/mtd/mtdchar.c | 4 ++++ 1 file changed, 4 insertions(+) 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: