get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/2196997/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2196997,
    "url": "http://patchwork.ozlabs.org/api/patches/2196997/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/861a2d0ad1519879d8e2bfcd67ebec605e31f7a1.1771275704.git.daniel@makrotopia.org/",
    "project": {
        "id": 18,
        "url": "http://patchwork.ozlabs.org/api/projects/18/?format=api",
        "name": "U-Boot",
        "link_name": "uboot",
        "list_id": "u-boot.lists.denx.de",
        "list_email": "u-boot@lists.denx.de",
        "web_url": null,
        "scm_url": null,
        "webscm_url": null,
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<861a2d0ad1519879d8e2bfcd67ebec605e31f7a1.1771275704.git.daniel@makrotopia.org>",
    "list_archive_url": null,
    "date": "2026-02-16T21:21:40",
    "name": "[RFC,03/20] mtd: add mtd_read_skip_bad() helper",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "7f90bf2d25a227b4aa8539813c03eb7d77374946",
    "submitter": {
        "id": 64091,
        "url": "http://patchwork.ozlabs.org/api/people/64091/?format=api",
        "name": "Daniel Golle",
        "email": "daniel@makrotopia.org"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/uboot/patch/861a2d0ad1519879d8e2bfcd67ebec605e31f7a1.1771275704.git.daniel@makrotopia.org/mbox/",
    "series": [
        {
            "id": 492351,
            "url": "http://patchwork.ozlabs.org/api/series/492351/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/uboot/list/?series=492351",
            "date": "2026-02-16T21:21:14",
            "name": "boot: add OpenWrt boot method and on-demand FIT loading",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/492351/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2196997/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2196997/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<u-boot-bounces@lists.denx.de>",
        "X-Original-To": "incoming@patchwork.ozlabs.org",
        "Delivered-To": "patchwork-incoming@legolas.ozlabs.org",
        "Authentication-Results": [
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org)",
            "phobos.denx.de;\n dmarc=none (p=none dis=none) header.from=makrotopia.org",
            "phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de",
            "phobos.denx.de; dmarc=none (p=none dis=none)\n header.from=makrotopia.org",
            "phobos.denx.de;\n spf=pass smtp.mailfrom=daniel@makrotopia.org"
        ],
        "Received": [
            "from phobos.denx.de (phobos.denx.de\n [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fFG3R4qwxz1xwD\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 17 Feb 2026 08:23:31 +1100 (AEDT)",
            "from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id A349783CB9;\n\tMon, 16 Feb 2026 22:23:02 +0100 (CET)",
            "by phobos.denx.de (Postfix, from userid 109)\n id 6B2E583C67; Mon, 16 Feb 2026 22:22:05 +0100 (CET)",
            "from pidgin.makrotopia.org (pidgin.makrotopia.org\n [IPv6:2a07:2ec0:3002::65])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id 8425083AA9\n for <u-boot@lists.denx.de>; Mon, 16 Feb 2026 22:22:00 +0100 (CET)",
            "from local\n by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256)\n (Exim 4.99) (envelope-from <daniel@makrotopia.org>)\n id 1vs62K-000000002d2-1XXb; Mon, 16 Feb 2026 21:21:44 +0000"
        ],
        "X-Spam-Checker-Version": "SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de",
        "X-Spam-Level": "",
        "X-Spam-Status": "No, score=-1.9 required=5.0 tests=BAYES_00,\n RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham\n autolearn_force=no version=3.4.2",
        "Date": "Mon, 16 Feb 2026 21:21:40 +0000",
        "From": "Daniel Golle <daniel@makrotopia.org>",
        "To": "Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,\n Quentin Schulz <quentin.schulz@cherry.de>,\n Daniel Golle <daniel@makrotopia.org>,\n Kory Maincent <kory.maincent@bootlin.com>,\n Mattijs Korpershoek <mkorpershoek@kernel.org>,\n Martin Schwan <m.schwan@phytec.de>, Anshul Dalal <anshuld@ti.com>,\n Ilias Apalodimas <ilias.apalodimas@linaro.org>,\n Sughosh Ganu <sughosh.ganu@arm.com>, Aristo Chen <jj251510319013@gmail.com>,\n\t=?utf-8?b?54mbIOW/l+Wujw==?= <Zone.Niuzh@hotmail.com>,\n Marek Vasut <marek.vasut+renesas@mailbox.org>,\n Heinrich Schuchardt <xypron.glpk@gmx.de>,\n Wolfgang Wallner <wolfgang.wallner@at.abb.com>,\n Frank Wunderlich <frank-w@public-files.de>,\n David Lechner <dlechner@baylibre.com>,\n Osama Abdelkader <osama.abdelkader@gmail.com>,\n Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>,\n Michael Trimarchi <michael@amarulasolutions.com>,\n Miquel Raynal <miquel.raynal@bootlin.com>,\n Andrew Goodbody <andrew.goodbody@linaro.org>,\n Yegor Yefremov <yegorslists@googlemail.com>,\n Mike Looijmans <mike.looijmans@topic.nl>,\n Weijie Gao <weijie.gao@mediatek.com>,\n Alexander Stein <alexander.stein@ew.tq-group.com>,\n Neil Armstrong <neil.armstrong@linaro.org>,\n Mayuresh Chitale <mchitale@ventanamicro.com>,\n Paul HENRYS <paul.henrys_ext@softathome.com>, u-boot@lists.denx.de",
        "Cc": "John Crispin <john@phrozen.org>, Paul Spooren <mail@aparcar.org>",
        "Subject": "[RFC PATCH 03/20] mtd: add mtd_read_skip_bad() helper",
        "Message-ID": "\n <861a2d0ad1519879d8e2bfcd67ebec605e31f7a1.1771275704.git.daniel@makrotopia.org>",
        "References": "<cover.1771275704.git.daniel@makrotopia.org>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=utf-8",
        "Content-Disposition": "inline",
        "Content-Transfer-Encoding": "8bit",
        "In-Reply-To": "<cover.1771275704.git.daniel@makrotopia.org>",
        "X-Mailman-Approved-At": "Mon, 16 Feb 2026 22:22:55 +0100",
        "X-BeenThere": "u-boot@lists.denx.de",
        "X-Mailman-Version": "2.1.39",
        "Precedence": "list",
        "List-Id": "U-Boot discussion <u-boot.lists.denx.de>",
        "List-Unsubscribe": "<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>",
        "List-Archive": "<https://lists.denx.de/pipermail/u-boot/>",
        "List-Post": "<mailto:u-boot@lists.denx.de>",
        "List-Help": "<mailto:u-boot-request@lists.denx.de?subject=help>",
        "List-Subscribe": "<https://lists.denx.de/listinfo/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=subscribe>",
        "Errors-To": "u-boot-bounces@lists.denx.de",
        "Sender": "\"U-Boot\" <u-boot-bounces@lists.denx.de>",
        "X-Virus-Scanned": "clamav-milter 0.103.8 at phobos.denx.de",
        "X-Virus-Status": "Clean"
    },
    "content": "Add a generic mtd_read_skip_bad() helper to the MTD core that reads\ndata from an MTD device while transparently skipping bad erase blocks\non NAND.\n\nThe function takes a physical byte offset, reads in erase-block-sized\nchunks, and automatically skips any block where mtd_block_isbad()\nreturns true. Non-block-aligned start offsets are handled correctly.\nFor NOR and other device types without bad-block support, it falls\nthrough to a plain mtd_read().\n\nRefactor the plain-data read path in cmd/mtd.c (\"mtd read\", without\n.raw or .oob suffixes) to use the new helper instead of open-coding\nthe bad-block skip loop. The write path and OOB/raw read paths\nretain their existing page-at-a-time mtd_read_oob() loop.\n\nThis helper will also be used by the image_loader MTD backend in a\nsubsequent patch. It could also serve as a replacement for\nnand_read_skip_bad() in drivers/mtd/nand/raw/nand_util.c in the\nfuture.\n\nSigned-off-by: Daniel Golle <daniel@makrotopia.org>\n---\n cmd/mtd.c               | 65 +++++++++++++++++++++++------------------\n drivers/mtd/mtdcore.c   | 45 ++++++++++++++++++++++++++++\n include/linux/mtd/mtd.h | 24 +++++++++++++++\n 3 files changed, 106 insertions(+), 28 deletions(-)",
    "diff": "diff --git a/cmd/mtd.c b/cmd/mtd.c\nindex 7f25144098b..30e4845b26d 100644\n--- a/cmd/mtd.c\n+++ b/cmd/mtd.c\n@@ -551,12 +551,6 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,\n \t\tprintf(\"%s %lld byte(s) at offset 0x%08llx\\n\",\n \t\t       read ? \"Reading\" : \"Writing\", len, start_off);\n \n-\tio_op.mode = raw ? MTD_OPS_RAW : MTD_OPS_AUTO_OOB;\n-\tio_op.len = has_pages ? mtd->writesize : len;\n-\tio_op.ooblen = woob ? mtd->oobsize : 0;\n-\tio_op.datbuf = buf;\n-\tio_op.oobbuf = woob ? &buf[len] : NULL;\n-\n \t/* Search for the first good block after the given offset */\n \toff = start_off;\n \twhile (mtd_block_isbad(mtd, off))\n@@ -567,31 +561,46 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,\n \tif (benchmark)\n \t\tbench_start = timer_get_us();\n \n-\t/* Loop over the pages to do the actual read/write */\n-\twhile (remaining) {\n-\t\t/* Skip the block if it is bad */\n-\t\tif (mtd_is_aligned_with_block_size(mtd, off) &&\n-\t\t    mtd_block_isbad(mtd, off)) {\n-\t\t\toff += mtd->erasesize;\n-\t\t\tcontinue;\n-\t\t}\n+\tif (read && !raw && !woob) {\n+\t\t/* Plain data read — use the skip-bad-block helper */\n+\t\tsize_t rdlen;\n \n-\t\tif (read)\n-\t\t\tret = mtd_read_oob(mtd, off, &io_op);\n-\t\telse\n-\t\t\tret = mtd_special_write_oob(mtd, off, &io_op,\n-\t\t\t\t\t\t    write_empty_pages, woob);\n+\t\tret = mtd_read_skip_bad(mtd, off, remaining, &rdlen, buf);\n+\t\tremaining -= rdlen;\n+\t} else {\n+\t\tio_op.mode = raw ? MTD_OPS_RAW : MTD_OPS_AUTO_OOB;\n+\t\tio_op.len = has_pages ? mtd->writesize : len;\n+\t\tio_op.ooblen = woob ? mtd->oobsize : 0;\n+\t\tio_op.datbuf = buf;\n+\t\tio_op.oobbuf = woob ? &buf[len] : NULL;\n+\n+\t\t/* Loop over the pages to do the actual read/write */\n+\t\twhile (remaining) {\n+\t\t\t/* Skip the block if it is bad */\n+\t\t\tif (mtd_is_aligned_with_block_size(mtd, off) &&\n+\t\t\t    mtd_block_isbad(mtd, off)) {\n+\t\t\t\toff += mtd->erasesize;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \n-\t\tif (ret) {\n-\t\t\tprintf(\"Failure while %s at offset 0x%llx\\n\",\n-\t\t\t       read ? \"reading\" : \"writing\", off);\n-\t\t\tbreak;\n-\t\t}\n+\t\t\tif (read)\n+\t\t\t\tret = mtd_read_oob(mtd, off, &io_op);\n+\t\t\telse\n+\t\t\t\tret = mtd_special_write_oob(mtd, off, &io_op,\n+\t\t\t\t\t\t\t    write_empty_pages,\n+\t\t\t\t\t\t\t    woob);\n+\n+\t\t\tif (ret) {\n+\t\t\t\tprintf(\"Failure while %s at offset 0x%llx\\n\",\n+\t\t\t\t       read ? \"reading\" : \"writing\", off);\n+\t\t\t\tbreak;\n+\t\t\t}\n \n-\t\toff += io_op.retlen;\n-\t\tremaining -= io_op.retlen;\n-\t\tio_op.datbuf += io_op.retlen;\n-\t\tio_op.oobbuf += io_op.oobretlen;\n+\t\t\toff += io_op.retlen;\n+\t\t\tremaining -= io_op.retlen;\n+\t\t\tio_op.datbuf += io_op.retlen;\n+\t\t\tio_op.oobbuf += io_op.oobretlen;\n+\t\t}\n \t}\n \n \tif (benchmark && bench_start) {\ndiff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c\nindex 3bfa5aebbc6..eb36743af1f 100644\n--- a/drivers/mtd/mtdcore.c\n+++ b/drivers/mtd/mtdcore.c\n@@ -1684,6 +1684,51 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)\n }\n EXPORT_SYMBOL_GPL(mtd_block_markbad);\n \n+int mtd_read_skip_bad(struct mtd_info *mtd, loff_t from, size_t len,\n+\t\t      size_t *retlen, u_char *buf)\n+{\n+\tsize_t remaining = len;\n+\tu_char *p = buf;\n+\tint ret;\n+\n+\t*retlen = 0;\n+\n+\tif (!mtd_can_have_bb(mtd)) {\n+\t\tret = mtd_read(mtd, from, len, retlen, buf);\n+\t\tif (ret == -EUCLEAN)\n+\t\t\tret = 0;\n+\t\treturn ret;\n+\t}\n+\n+\twhile (remaining) {\n+\t\tloff_t block_start = from & ~(loff_t)(mtd->erasesize - 1);\n+\t\tsize_t block_off = from - block_start;\n+\t\tsize_t chunk, rdlen;\n+\n+\t\tif (from >= mtd->size)\n+\t\t\treturn -EINVAL;\n+\n+\t\tif (mtd_block_isbad(mtd, block_start)) {\n+\t\t\t/* Skip to start of next erase block */\n+\t\t\tfrom = block_start + mtd->erasesize;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tchunk = min(remaining, (size_t)mtd->erasesize - block_off);\n+\n+\t\tret = mtd_read(mtd, from, chunk, &rdlen, p);\n+\t\tif (ret && ret != -EUCLEAN)\n+\t\t\treturn ret;\n+\n+\t\tp += rdlen;\n+\t\tfrom += rdlen;\n+\t\tremaining -= rdlen;\n+\t\t*retlen += rdlen;\n+\t}\n+\n+\treturn 0;\n+}\n+\n #ifndef __UBOOT__\n /*\n  * default_mtd_writev - the default writev method\ndiff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h\nindex 1f97bc4fe11..ea3fa513c58 100644\n--- a/include/linux/mtd/mtd.h\n+++ b/include/linux/mtd/mtd.h\n@@ -471,6 +471,30 @@ int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs);\n int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs);\n int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs);\n \n+/**\n+ * mtd_read_skip_bad() - Read from an MTD device, skipping bad blocks\n+ *\n+ * Read @len bytes starting at physical offset @from into @buf. On NAND\n+ * devices, erase blocks that are marked bad are transparently skipped\n+ * so the caller always receives a contiguous stream of good data.\n+ *\n+ * If @from is not erase-block-aligned, reading starts at the correct\n+ * position within the first good block.\n+ *\n+ * For NOR and other device types without bad-block support, this is\n+ * equivalent to a plain mtd_read().\n+ *\n+ * @mtd:\tMTD device\n+ * @from:\tStart offset (physical, byte address)\n+ * @len:\tNumber of bytes to read\n+ * @retlen:\tActual number of bytes read (output)\n+ * @buf:\tDestination buffer\n+ * Return: 0 on success, negative errno on failure. -EUCLEAN is\n+ *\t   treated as success (ECC corrected).\n+ */\n+int mtd_read_skip_bad(struct mtd_info *mtd, loff_t from, size_t len,\n+\t\t      size_t *retlen, u_char *buf);\n+\n #ifndef __UBOOT__\n static inline int mtd_suspend(struct mtd_info *mtd)\n {\n",
    "prefixes": [
        "RFC",
        "03/20"
    ]
}