From patchwork Sat Nov 21 01:10:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4211 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 14AF81C50E2 for ; Sat, 21 Nov 2026 02:12:03 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27951-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27951-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id D030C879BC for ; Sat, 21 Nov 2026 01:11:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223479; b=kYx61WFtMt/PkkrmtZ9HFGOxHlUX3Jp9gv8YO096PaOC0qyjhbdGJpNqYupHSq3ahRVv pCOafhOj+wBQqUwr6bZC/lht9nlux1m97tpFKsdHP3AHUu1nM66WfT4MwPiD/7H5zBu4q Jmo6EBOBhx8clz1FUOBsL3hhXNeJxLRwE0tPHdpivp1g6TpqdnGKIkdUoA9Ijq9AOG1QG BSafOv3a18FvX1UfQ7I1qDpbIAI+uUFXSxH+ELwyYa2RrDX+UFx6IHvU8OeOS2hAQUKzW wkQRJe2nq/wqB5sPQdij4PBHvIohiHxD7RnKHLB4R9aeIiS3HK2oQa96vrA7RnU0UEQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223479; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature: X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State: X-Gm-Gg:X-Received:Received:From:Date:Subject:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=V/ZOEZdBIX9Ht5ZtaAIcNRRvXcoTuAbgmishigtjssc=; b=PtX7jfvoKZmd5t7ot6R6C6ZfbY/iDRzkacc0DFLByrIPvzXxXQH4lzmLEijJyIIFoKxH EGzxDMQ4sKkZHFhN+vsjZK9mqhble/oR8Aq5BFrx1Oo3ZGR1ZDqcKSiWMHQKk8aMF/UzQ KpvRyqKYCgM8Us5EkqpRBkDLamaR3pIDYM4XlVj/DD2cK82vO1TUKDG5j5UX48ejnoCj4 ma6fa+LSIrimET1ZFqbx3EovD5ZwolzBdg6+wGBelxMv0Ei8e32RbmK0o+GA4LHeO+imK byt10v4SHBQD+JZP/azIA347Et1KoJRieGKsAVRssurFcIlN7DsDkMUapAF7m6RJwyQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=v4aJI0Jc; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9955860A6F43; Sat, 21 Nov 2026 01:11:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=v4aJI0Jc X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223479; b=xGHIWCWLm61dsiAnzQcrHauMkHajvynj5nMznjAI2vbNeo6D8+zrwwFAPxQYJDPjKjpI GqgqSNztlzrJBekG0IEM7tVRMfVtJ8bSdXd30fql/McSDrbMRUkTs7Ut+9QyoPHBMfm4D co3VFzjRNKzursl1G5sefZ6HStDJDJrF6cPqLRVLErXnowQtK435HMnOEuRrGjybN4bN9 EtLjf5kuriSi2WPY8ZaYoxllzWumwW0qye99fTisxaMp4xccqbiyjbBmP77L0Lzjfxowq eUcL0eFoh5kY8Le9rocOg62h8p5JbyulckS9V1EqMWpQZIuzmHLaNTGRzSSvuF61Yng== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223479; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=V/ZOEZdBIX9Ht5ZtaAIcNRRvXcoTuAbgmishigtjssc=; b=V0boMNuEsg8z/S91ny/WxMHd+JJC2VsKURryuCQaQaffJj7mziUaKohCQE+HJhdpLMRH cQfmVgySZmngFRDs4myjcoS+BKJ/hFQq5S0Mq8q147lKmI6OQhQmb5kjsScGbEDC91WMr 07/vMa+jF2tvFLoiW1YXuwXyz6dl4ZyXdWX6aJ5sRKALSXWRbslH98CZWBIatPWQb5es2 Mwy8MXXolksciv/bllzgK2x00a7INSGy4KwF3nDCIm/kjgRl5YNV0BWU9h5MLNNKMc/XA hhHZkJZMZjF/Je3jmD6cRkIj5vt5AomG/+0umhPFfxQcf8jp3UmUbB+2pRkvYBueU4g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=v4aJI0Jc; arc=none smtp.remote-ip=209.85.167.180 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6ACC360A263C for ; Sat, 21 Nov 2026 01:11:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6ACC360A263C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-5642e0910a3so741984b6e.0 for ; Fri, 20 Nov 2026 17:11:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223474; x=1795828274; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=V/ZOEZdBIX9Ht5ZtaAIcNRRvXcoTuAbgmishigtjssc=; b=v4aJI0JcfuEB8CsSkCsuUjD3GgUkXBC0u/cHK6Mwl+TgrdNiQMG/iriB1SoWIGzDMD +dXGvTtLb+pEWw4ms2U/ko+fua2BSTXMV0P8pl8roVyiMjlTorIEfDrzqr6JxQ5n7JWS H8kKiAPMzN2FyophA5BNTV9FQRoyJM2YL5a4FDn+7xBwvIL2zmPj1vbK6PR8sxgodvxc TSDZcHesNUcDUgeB+Gon6jAQOKcBBZoKAtcPQDGI+ZTpRK6HYYnpaXYj2m6TBgSfc0tI p/HAcrKmgRrFzCEOEioyyF2LT+QetIw+i+dibLGPVEsmqUwDFQ2UxLFxa/eJ2dvKHe8C m+Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223474; x=1795828274; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=V/ZOEZdBIX9Ht5ZtaAIcNRRvXcoTuAbgmishigtjssc=; b=fQZY4dD0DAdEsIM8zEpv4OC01LIybWwQYl0R87F0vgitpr5ltdCxPbpi4SEMWusVa2 U9uKgKUQWTkbKb/3zCvjAXdOV3Dr0Hu4BLOnub+Z0N4/14F3mo2i6v7S5zfTrLG4RKGO q6IEW08wyNWbfO+g2Q/ygtSunmjjfNKs0HBZ2Lm3VOtdcr5OmqW7/l44dgGB6jSbe+YE HdckPsBz/0GUR+t2T64qbTQt+dAIBsP8DYVpF8z5bZ8/uUw3yex9927tEAN5V5B86swe moKmhj9Z4iSkAi/abH+FFM1B8G0lDJagiBe21OUQYTrRBFg1F6CBFCVsP3i8y+CnPeRJ wECg== X-Forwarded-Encrypted: i=1; AL+hErEcq9mPs3FLybcyamREX+c5PaeLroK2ssWoAHZPuD3ImfvMAN80CQRaFdvobQW7R5NVX1YtRIqSTVFlSA==@lists.linux.dev X-Gm-Message-State: APuU4Z/pcTd8WtilIHkIXrmYrHIPa6wjbq5MaosX9zkq+o+vh+UpJ4ML O1tZPwhCGMJ57Xq2w4vnNMsMH8htOy8qJ8EnxO6lTE1qTIigPmD27juT X-Gm-Gg: AYBFou0bt/dNCYjalVbK2oYcFUhavcWyuDkTFtJ0yZlWEumpb+uTSOejDKDDAaZLo5s XF8OnLBo7DEKQcztnRsSWoZPsPsj18Ro6wNOIooiBvauoVNCnlP9y+ZH50h6WQU1ros34kL+gCM aeenO5qesppWYyIuhhArWe/5wQVQys5UgUq8SFBmpNfdP3kQfRtBBAd9wLemi7RKEwiuLKejjdh F9l8RPR5F3EFtkwmGYjLVd3tzyzQa8pUe9559yjRmn7+cK3N2/j9Pf99ZCK4IY+ONm+VsshTVVG oAUb06GsEJLyWGolOD4dg9xA78Czy1jGsH1U7i/hC/BCWsZGQTbIvTWGDSbF41vW8uYJUvOWNcY juEJOS8lJ4co5fs0BC89aS3/L/Psrbd+xT5GoYx9D9JKh9E5AXfcG09BiR8Oes6GRMk6DUaE1Vq Ai4jtSuBHn23UzPCPiF9kYQ/ooUTlfjFJTOvycFEWW1h9O6Bgx9VPnhQkUKOoEiUUaAUvtvyrSS UBbahyJOGEeaix/E8rEHotPt1BaZNFt3ArIaBUcGfgJ+8tQMH+IExmvWGZPAmFr4s7DfQmwXj8c eZsUtAOQwcgK7SVDby5dK7FPWOGkK4bsiXTgKN5wnKdoZoVd+W2VtXOBzM+zR4nDOhiIcESkNLn gBIYb6pllOUwQbRwV1t5RSEnYaBiB1IMbePDnns97twCoBk6Wdm09jj/vDcWzpZbtRTcjjwFYdA 9CRPOHXKWnAtM+hbl9a2TGWYkt/mMSWTdzR44H8t30Evxu7LSIvqeA X-Received: by 2002:a05:6808:130a:b0:573:7a6b:f32c with SMTP id 5614622812f47-57a0c4b923bmr5275123b6e.50.1795223474187; Fri, 20 Nov 2026 17:11:14 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:13 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:36 -0700 Subject: [PATCH v11 13/26] mtd: rawnand: sunxi: propagate buffer and column transfer errors X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-13-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.31 / 15.00]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; RCVD_COUNT_FIVE(0.00)[6]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; TAGGED_RCPT(0.00)[dt]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27951-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,209.85.167.180:received,174.29.1.49:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 14AF81C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX A NAND read can report success with missing bytes or bytes from the wrong column. A write can send PAGEPROG after transferring only part of the intended data. The SRAM transfer helpers stop on a FIFO or completion timeout but return no status, and the hardware-ECC paths ignore some column-change errors, including when fetching OOB after DMA. Return the transfer status through the randomizer and OOB helpers to the page callbacks. A read with a NULL destination still fills controller SRAM for ECC and must report errors even though it does not copy to memory. Disable the randomizer after either transfer outcome, and use the page callbacks' error exits to disable ECC and skip program-end. Update a tracked OOB column only after the requested transfer succeeds. Keep transport status separate from the maximum corrected-bit count: zero from a successful OOB read must not erase a positive correction result. If an OOB read after DMA fails, restore that attempt's corrected/failed counters before the caller retries the page in PIO. Compare the tracked write column against the absolute column of the OOB tail. Otherwise a small-page PIO write that has already reached the right column would now fail on an unnecessary change-column command. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 175 +++++++++++++++++++++++++------------- 1 file changed, 117 insertions(+), 58 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index e76f7cc67081..712648864407 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -663,7 +663,7 @@ static int sunxi_nfc_buf_chunk_size(struct sunxi_nfc *nfc, int len) return min(len, nfc->caps->sram_size); } -static void sunxi_nfc_read_buf(struct nand_chip *nand, uint8_t *buf, int len) +static int sunxi_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len) { struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); @@ -679,7 +679,7 @@ static void sunxi_nfc_read_buf(struct nand_chip *nand, uint8_t *buf, int len) ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) - break; + return ret; writel(cnt, nfc->regs + NFC_REG_CNT); tmp = NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD; @@ -691,17 +691,19 @@ static void sunxi_nfc_read_buf(struct nand_chip *nand, uint8_t *buf, int len) ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, poll, 0); if (ret) - break; + return ret; if (buf) memcpy_fromio(buf + offs, nfc->regs + NFC_RAM0_BASE, cnt); offs += cnt; } + + return 0; } -static void sunxi_nfc_write_buf(struct nand_chip *nand, const uint8_t *buf, - int len) +static int sunxi_nfc_write_buf(struct nand_chip *nand, const u8 *buf, + int len) { struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); @@ -717,7 +719,7 @@ static void sunxi_nfc_write_buf(struct nand_chip *nand, const uint8_t *buf, ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) - break; + return ret; writel(cnt, nfc->regs + NFC_REG_CNT); memcpy_toio(nfc->regs + NFC_RAM0_BASE, buf + offs, cnt); @@ -731,10 +733,12 @@ static void sunxi_nfc_write_buf(struct nand_chip *nand, const uint8_t *buf, ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, poll, 0); if (ret) - break; + return ret; offs += cnt; } + + return 0; } /* These seed values have been extracted from Allwinner's BSP */ @@ -884,23 +888,31 @@ static void sunxi_nfc_randomize_bbm(struct nand_chip *nand, int page, u8 *bbm) bbm[1] ^= sunxi_nfc_randomizer_step(state, 8); } -static void sunxi_nfc_randomizer_write_buf(struct nand_chip *nand, - const uint8_t *buf, int len, - bool ecc, int page) +static int sunxi_nfc_randomizer_write_buf(struct nand_chip *nand, + const u8 *buf, int len, + bool ecc, int page) { + int ret; + sunxi_nfc_randomizer_config(nand, page, ecc); sunxi_nfc_randomizer_enable(nand); - sunxi_nfc_write_buf(nand, buf, len); + ret = sunxi_nfc_write_buf(nand, buf, len); sunxi_nfc_randomizer_disable(nand); + + return ret; } -static void sunxi_nfc_randomizer_read_buf(struct nand_chip *nand, uint8_t *buf, - int len, bool ecc, int page) +static int sunxi_nfc_randomizer_read_buf(struct nand_chip *nand, u8 *buf, + int len, bool ecc, int page) { + int ret; + sunxi_nfc_randomizer_config(nand, page, ecc); sunxi_nfc_randomizer_enable(nand); - sunxi_nfc_read_buf(nand, buf, len); + ret = sunxi_nfc_read_buf(nand, buf, len); sunxi_nfc_randomizer_disable(nand); + + return ret; } static void sunxi_nfc_hw_ecc_enable(struct nand_chip *nand) @@ -1135,31 +1147,39 @@ static int sunxi_nfc_hw_ecc_read_error(struct nand_chip *nand, return 0; } -static void sunxi_nfc_hw_ecc_read_extra_oob(struct nand_chip *nand, - u8 *oob, int *cur_off, - bool randomize, int page) +static int sunxi_nfc_hw_ecc_read_extra_oob(struct nand_chip *nand, + u8 *oob, int *cur_off, + bool randomize, int page) { struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); struct mtd_info *mtd = nand_to_mtd(nand); struct nand_ecc_ctrl *ecc = &nand->ecc; int offset = sunxi_get_oob_offset(sunxi_nand, ecc, ecc->steps); int len = mtd->oobsize - offset; + int ret; if (len <= 0) - return; + return 0; - if (!cur_off || *cur_off != (offset + mtd->writesize)) - sunxi_nfc_read_column(nand, page, mtd->writesize + offset, - NULL, 0); + if (!cur_off || *cur_off != (offset + mtd->writesize)) { + ret = sunxi_nfc_read_column(nand, page, mtd->writesize + offset, + NULL, 0); + if (ret) + return ret; + } if (!randomize) - sunxi_nfc_read_buf(nand, oob + offset, len); + ret = sunxi_nfc_read_buf(nand, oob + offset, len); else - sunxi_nfc_randomizer_read_buf(nand, oob + offset, len, - false, page); + ret = sunxi_nfc_randomizer_read_buf(nand, oob + offset, len, + false, page); + if (ret) + return ret; if (cur_off) *cur_off = mtd->oobsize + mtd->writesize; + + return 0; } /* Interpret one PIO step or a completed DMA batch before reusing its status. */ @@ -1212,15 +1232,22 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, if (read->oob_required) { /* Keep the existing PIO and DMA representations of parity. */ if (read->dma) { - sunxi_nfc_read_column(nand, read->page, - mtd->writesize + oob_off, - oob, ecc->bytes + user_data_sz); + ret = sunxi_nfc_read_column(nand, read->page, + mtd->writesize + oob_off, + oob, ecc->bytes + user_data_sz); + if (ret) + return ret; } else { - sunxi_nfc_read_column(nand, read->page, - mtd->writesize + oob_off, NULL, 0); - sunxi_nfc_randomizer_read_buf(nand, oob, - ecc->bytes + user_data_sz, - true, read->page); + ret = sunxi_nfc_read_column(nand, read->page, + mtd->writesize + oob_off, NULL, 0); + if (ret) + return ret; + + ret = sunxi_nfc_randomizer_read_buf(nand, oob, + ecc->bytes + user_data_sz, + true, read->page); + if (ret) + return ret; } sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, reg_index, !step, @@ -1251,9 +1278,14 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, static int sunxi_nfc_oob_finish_read(struct nand_chip *nand, struct sunxi_nfc_ecc_read *read, int *cur_off) { - if (read->oob_required) - sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi, cur_off, - !read->has_erased_chunk, read->page); + int ret; + + if (read->oob_required) { + ret = sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi, cur_off, + !read->has_erased_chunk, read->page); + if (ret) + return ret; + } return read->max_bitflips; } @@ -1272,13 +1304,21 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chip *nand, u32 pattern_found; int ret; - if (*cur_off != data_off) - sunxi_nfc_read_column(nand, page, data_off, NULL, 0); + if (*cur_off != data_off) { + ret = sunxi_nfc_read_column(nand, page, data_off, NULL, 0); + if (ret) + return ret; + } - sunxi_nfc_randomizer_read_buf(nand, NULL, ecc->size, false, page); + ret = sunxi_nfc_randomizer_read_buf(nand, NULL, ecc->size, false, page); + if (ret) + return ret; - if (data_off + ecc->size != oob_off) - sunxi_nfc_read_column(nand, page, oob_off, NULL, 0); + if (data_off + ecc->size != oob_off) { + ret = sunxi_nfc_read_column(nand, page, oob_off, NULL, 0); + if (ret) + return ret; + } ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) @@ -1401,13 +1441,21 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct nand_chip *nand, /* From the controller point of view, we are at step 0 */ const int nfc_step = 0; - if (data_off != *cur_off) - nand_change_write_column_op(nand, data_off, NULL, 0, false); + if (data_off != *cur_off) { + ret = nand_change_write_column_op(nand, data_off, NULL, 0, false); + if (ret) + return ret; + } - sunxi_nfc_randomizer_write_buf(nand, data, ecc->size, false, page); + ret = sunxi_nfc_randomizer_write_buf(nand, data, ecc->size, false, page); + if (ret) + return ret; - if (data_off + ecc->size != oob_off) - nand_change_write_column_op(nand, oob_off, NULL, 0, false); + if (data_off + ecc->size != oob_off) { + ret = nand_change_write_column_op(nand, oob_off, NULL, 0, false); + if (ret) + return ret; + } ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) @@ -1433,27 +1481,35 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct nand_chip *nand, return 0; } -static void sunxi_nfc_hw_ecc_write_extra_oob(struct nand_chip *nand, - u8 *oob, int *cur_off, - int page) +static int sunxi_nfc_hw_ecc_write_extra_oob(struct nand_chip *nand, + u8 *oob, int *cur_off, + int page) { struct mtd_info *mtd = nand_to_mtd(nand); struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); struct nand_ecc_ctrl *ecc = &nand->ecc; int offset = sunxi_get_oob_offset(sunxi_nand, ecc, ecc->steps); int len = mtd->oobsize - offset; + int ret; if (len <= 0) - return; + return 0; - if (!cur_off || *cur_off != offset) - nand_change_write_column_op(nand, offset + mtd->writesize, - NULL, 0, false); + if (!cur_off || *cur_off != offset + mtd->writesize) { + ret = nand_change_write_column_op(nand, offset + mtd->writesize, + NULL, 0, false); + if (ret) + return ret; + } - sunxi_nfc_randomizer_write_buf(nand, oob + offset, len, false, page); + ret = sunxi_nfc_randomizer_write_buf(nand, oob + offset, len, false, page); + if (ret) + return ret; if (cur_off) *cur_off = mtd->oobsize + mtd->writesize; + + return 0; } static int sunxi_nfc_hw_ecc_read_chunks_pio(struct nand_chip *nand, u8 *buf, @@ -1574,8 +1630,8 @@ static int sunxi_nfc_hw_ecc_write_page(struct nand_chip *nand, } if (oob_required || (nand->options & NAND_NEED_SCRAMBLING)) - sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, - &cur_off, page); + ret = sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, + &cur_off, page); out: sunxi_nfc_hw_ecc_disable(nand); @@ -1698,10 +1754,13 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *nand, if (ret) return ret; - if (oob_required || (nand->options & NAND_NEED_SCRAMBLING)) + if (oob_required || (nand->options & NAND_NEED_SCRAMBLING)) { /* TODO: use DMA to transfer extra OOB bytes ? */ - sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, - NULL, page); + ret = sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, + NULL, page); + if (ret) + return ret; + } return nand_prog_page_end_op(nand);