get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 1820092,
    "url": "http://patchwork.ozlabs.org/api/patches/1820092/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/linux-mtd/patch/df8cfc16a0047c1041a8f8d0069c6312bb83da0d.1691717480.git.daniel@makrotopia.org/",
    "project": {
        "id": 3,
        "url": "http://patchwork.ozlabs.org/api/projects/3/?format=api",
        "name": "Linux MTD development",
        "link_name": "linux-mtd",
        "list_id": "linux-mtd.lists.infradead.org",
        "list_email": "linux-mtd@lists.infradead.org",
        "web_url": null,
        "scm_url": null,
        "webscm_url": null,
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<df8cfc16a0047c1041a8f8d0069c6312bb83da0d.1691717480.git.daniel@makrotopia.org>",
    "list_archive_url": null,
    "date": "2023-08-11T01:37:49",
    "name": "[v4,5/8] mtd: ubi: attach MTD partition from device-tree",
    "commit_ref": null,
    "pull_url": null,
    "state": "changes-requested",
    "archived": false,
    "hash": "576b98d93309463630ef227da2f0539edc0b6c5e",
    "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/linux-mtd/patch/df8cfc16a0047c1041a8f8d0069c6312bb83da0d.1691717480.git.daniel@makrotopia.org/mbox/",
    "series": [
        {
            "id": 368347,
            "url": "http://patchwork.ozlabs.org/api/series/368347/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/linux-mtd/list/?series=368347",
            "date": "2023-08-11T01:36:37",
            "name": "mtd: ubi: allow UBI volumes to provide NVMEM",
            "version": 4,
            "mbox": "http://patchwork.ozlabs.org/series/368347/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/1820092/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/1820092/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "\n <linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>",
        "X-Original-To": "incoming@patchwork.ozlabs.org",
        "Delivered-To": "patchwork-incoming@legolas.ozlabs.org",
        "Authentication-Results": [
            "legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=<UNKNOWN>)",
            "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=4FVOxltW;\n\tdkim-atps=neutral"
        ],
        "Received": [
            "from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4RMRK95YYsz1yf2\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 11 Aug 2023 11:38:53 +1000 (AEST)",
            "from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux))\n\tid 1qUH6P-0095G3-0p;\n\tFri, 11 Aug 2023 01:38:09 +0000",
            "from pidgin.makrotopia.org ([185.142.180.65])\n\tby bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux))\n\tid 1qUH6L-0095Ej-2z\n\tfor linux-mtd@lists.infradead.org;\n\tFri, 11 Aug 2023 01:38:08 +0000",
            "from local\n\tby pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256)\n\t (Exim 4.96)\n\t(envelope-from <daniel@makrotopia.org>)\n\tid 1qUH6C-00055K-0m;\n\tFri, 11 Aug 2023 01:37:57 +0000"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:\n\tMessage-ID:Subject:To:From:Date:Reply-To:Cc:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=CdQDipgvANEBrbyE9hq7sOs1JaXstko5q0jOtVng8mg=; b=4FVOxltWGHhMM8\n\tfJMQXkzCEyo1ZLMaPtjWDHhmRyxb/OJo9D8XwICqAgCJIyFy7o7YK6tf1ngvzywbUznvbwqB9erUx\n\thfJOkuRloO6cUq/logX6Iv563v8hWalEUrILW3P1QJA1hClnl1pemq9a28QkcJmrUViXHMnkmTti+\n\tprxcXiM0azGn5vl7fwu+apKuYLXecZbIASaMH08jzd0+NVFyltXZi17PVDznIPdPwP3jmt47S+CBP\n\tTZ9NVr6taXY8BJnySWhvyqEHY+JF4Im14TNWru0Q2aS5sBmdG/8c6C0tuM7/9hUtfuTF5L+wmVt6N\n\tzlmiLvWhsqKHko7mfWVA==;",
        "Date": "Fri, 11 Aug 2023 02:37:49 +0100",
        "From": "Daniel Golle <daniel@makrotopia.org>",
        "To": "Randy Dunlap <rdunlap@infradead.org>,\n\tMiquel Raynal <miquel.raynal@bootlin.com>,\n\tRichard Weinberger <richard@nod.at>,\n\tVignesh Raghavendra <vigneshr@ti.com>,\n\tRob Herring <robh+dt@kernel.org>,\n\tKrzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,\n\tConor Dooley <conor+dt@kernel.org>,\n\tDaniel Golle <daniel@makrotopia.org>, linux-mtd@lists.infradead.org,\n\tdevicetree@vger.kernel.org, linux-kernel@vger.kernel.org",
        "Subject": "[PATCH v4 5/8] mtd: ubi: attach MTD partition from device-tree",
        "Message-ID": "\n <df8cfc16a0047c1041a8f8d0069c6312bb83da0d.1691717480.git.daniel@makrotopia.org>",
        "References": "<cover.1691717480.git.daniel@makrotopia.org>",
        "MIME-Version": "1.0",
        "Content-Disposition": "inline",
        "In-Reply-To": "<cover.1691717480.git.daniel@makrotopia.org>",
        "X-CRM114-Version": "20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ",
        "X-CRM114-CacheID": "sfid-20230810_183806_154328_7B2DDC76 ",
        "X-CRM114-Status": "GOOD (  31.37  )",
        "X-Spam-Score": "0.0 (/)",
        "X-Spam-Report": "Spam detection software,\n running on the system \"bombadil.infradead.org\",\n has NOT identified this incoming email as spam.  The original\n message has been attached to this so you can view it or label\n similar future email.  If you have any questions, see\n the administrator of that system for details.\n Content preview:  Split ubi_init() function into early function to be called\n    by device_initcall() and keep cmdline attachment in late_initcall(). (when\n    building ubi as module, both is still done in a single module_init [...]\n Content analysis details:   (0.0 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n -0.0 SPF_PASS               SPF: sender matches SPF record\n  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record",
        "X-BeenThere": "linux-mtd@lists.infradead.org",
        "X-Mailman-Version": "2.1.34",
        "Precedence": "list",
        "List-Id": "Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>",
        "List-Unsubscribe": "<http://lists.infradead.org/mailman/options/linux-mtd>,\n <mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>",
        "List-Archive": "<http://lists.infradead.org/pipermail/linux-mtd/>",
        "List-Post": "<mailto:linux-mtd@lists.infradead.org>",
        "List-Help": "<mailto:linux-mtd-request@lists.infradead.org?subject=help>",
        "List-Subscribe": "<http://lists.infradead.org/mailman/listinfo/linux-mtd>,\n <mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Sender": "\"linux-mtd\" <linux-mtd-bounces@lists.infradead.org>",
        "Errors-To": "linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"
    },
    "content": "Split ubi_init() function into early function to be called by\ndevice_initcall() and keep cmdline attachment in late_initcall().\n(when building ubi as module, both is still done in a single\nmodule_init() call)\n\nRegister MTD notifier and attach MTD devices which are marked as\ncompatible with 'linux,ubi' in OF device-tree when being added, detach\nUBI device from MTD device when it is being removed.\n\nFor existing users this should not change anything besides automatic\nremoval of (dead) UBI devices when their underlying MTD devices are\nalready gone, e.g. in case of MTD driver module or (SPI) bus driver\nmodule being removed.\n\nFor new users this opens up the option to attach UBI using device-tree\nwhich then happens early and in parallel with other drivers being\nprobed which slightly reduces the total boot time.\n\nAttachment no longer happening late is also a requirement for other\ndrivers to make use of UBI, e.g. drivers/nvmem/u-boot-env.c can now\nbe extended to support U-Boot environment stored in UBI volumes.\n\nSigned-off-by: Daniel Golle <daniel@makrotopia.org>\n---\n drivers/mtd/ubi/block.c |   2 +-\n drivers/mtd/ubi/build.c | 153 +++++++++++++++++++++++++++++-----------\n drivers/mtd/ubi/cdev.c  |   2 +-\n drivers/mtd/ubi/ubi.h   |   2 +-\n 4 files changed, 115 insertions(+), 44 deletions(-)",
    "diff": "diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c\nindex e0618bbde3613..99b5f502c9dbc 100644\n--- a/drivers/mtd/ubi/block.c\n+++ b/drivers/mtd/ubi/block.c\n@@ -470,7 +470,7 @@ int ubiblock_remove(struct ubi_volume_info *vi, bool force)\n \t}\n \n \t/* Found a device, let's lock it so we can check if it's busy */\n-\tmutex_lock(&dev->dev_mutex);\n+\tmutex_lock_nested(&dev->dev_mutex, SINGLE_DEPTH_NESTING);\n \tif (dev->refcnt > 0 && !force) {\n \t\tret = -EBUSY;\n \t\tgoto out_unlock_dev;\ndiff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c\nindex 8b91a55ec0d28..c153373c13dab 100644\n--- a/drivers/mtd/ubi/build.c\n+++ b/drivers/mtd/ubi/build.c\n@@ -27,6 +27,7 @@\n #include <linux/log2.h>\n #include <linux/kthread.h>\n #include <linux/kernel.h>\n+#include <linux/of.h>\n #include <linux/slab.h>\n #include <linux/major.h>\n #include \"ubi.h\"\n@@ -1065,6 +1066,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,\n  * ubi_detach_mtd_dev - detach an MTD device.\n  * @ubi_num: UBI device number to detach from\n  * @anyway: detach MTD even if device reference count is not zero\n+ * @have_lock: called by MTD notifier holding mtd_table_mutex\n  *\n  * This function destroys an UBI device number @ubi_num and detaches the\n  * underlying MTD device. Returns zero in case of success and %-EBUSY if the\n@@ -1074,7 +1076,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,\n  * Note, the invocations of this function has to be serialized by the\n  * @ubi_devices_mutex.\n  */\n-int ubi_detach_mtd_dev(int ubi_num, int anyway)\n+int ubi_detach_mtd_dev(int ubi_num, int anyway, bool have_lock)\n {\n \tstruct ubi_device *ubi;\n \n@@ -1111,6 +1113,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)\n \tif (!ubi_dbg_chk_fastmap(ubi))\n \t\tubi_update_fastmap(ubi);\n #endif\n+\n \t/*\n \t * Before freeing anything, we have to stop the background thread to\n \t * prevent it from doing anything on this device while we are freeing.\n@@ -1130,7 +1133,11 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)\n \tvfree(ubi->peb_buf);\n \tvfree(ubi->fm_buf);\n \tubi_msg(ubi, \"mtd%d is detached\", ubi->mtd->index);\n-\tput_mtd_device(ubi->mtd);\n+\tif (have_lock)\n+\t\t__put_mtd_device(ubi->mtd);\n+\telse\n+\t\tput_mtd_device(ubi->mtd);\n+\n \tput_device(&ubi->dev);\n \treturn 0;\n }\n@@ -1207,43 +1214,51 @@ static struct mtd_info * __init open_mtd_device(const char *mtd_dev)\n \treturn mtd;\n }\n \n-static int __init ubi_init(void)\n+static void ubi_notify_add(struct mtd_info *mtd)\n {\n-\tint err, i, k;\n+\tstruct device_node *np = mtd_get_of_node(mtd);\n+\tint err;\n \n-\t/* Ensure that EC and VID headers have correct size */\n-\tBUILD_BUG_ON(sizeof(struct ubi_ec_hdr) != 64);\n-\tBUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64);\n+\tif (!of_device_is_compatible(np, \"linux,ubi\"))\n+\t\treturn;\n \n-\tif (mtd_devs > UBI_MAX_DEVICES) {\n-\t\tpr_err(\"UBI error: too many MTD devices, maximum is %d\\n\",\n-\t\t       UBI_MAX_DEVICES);\n-\t\treturn -EINVAL;\n-\t}\n+\t/*\n+\t * we are already holding &mtd_table_mutex, but still need\n+\t * to bump refcount\n+\t */\n+\terr = __get_mtd_device(mtd);\n+\tif (err)\n+\t\treturn;\n \n-\t/* Create base sysfs directory and sysfs files */\n-\terr = class_register(&ubi_class);\n+\t/* called while holding mtd_table_mutex */\n+\tmutex_lock_nested(&ubi_devices_mutex, SINGLE_DEPTH_NESTING);\n+\terr = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 0, false);\n+\tmutex_unlock(&ubi_devices_mutex);\n \tif (err < 0)\n-\t\treturn err;\n+\t\t__put_mtd_device(mtd);\n+}\n \n-\terr = misc_register(&ubi_ctrl_cdev);\n-\tif (err) {\n-\t\tpr_err(\"UBI error: cannot register device\\n\");\n-\t\tgoto out;\n-\t}\n+static void ubi_notify_remove(struct mtd_info *mtd)\n+{\n+\tint i;\n \n-\tubi_wl_entry_slab = kmem_cache_create(\"ubi_wl_entry_slab\",\n-\t\t\t\t\t      sizeof(struct ubi_wl_entry),\n-\t\t\t\t\t      0, 0, NULL);\n-\tif (!ubi_wl_entry_slab) {\n-\t\terr = -ENOMEM;\n-\t\tgoto out_dev_unreg;\n-\t}\n+\t/* called while holding mtd_table_mutex */\n+\tmutex_lock_nested(&ubi_devices_mutex, SINGLE_DEPTH_NESTING);\n+\tfor (i = 0; i < UBI_MAX_DEVICES; i++)\n+\t\tif (ubi_devices[i] &&\n+\t\t    ubi_devices[i]->mtd->index == mtd->index)\n+\t\t\tubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1, true);\n+\tmutex_unlock(&ubi_devices_mutex);\n+}\n \n-\terr = ubi_debugfs_init();\n-\tif (err)\n-\t\tgoto out_slab;\n+static struct mtd_notifier ubi_mtd_notifier = {\n+\t.add = ubi_notify_add,\n+\t.remove = ubi_notify_remove,\n+};\n \n+static int __init ubi_init_attach(void)\n+{\n+\tint err, i, k;\n \n \t/* Attach MTD devices */\n \tfor (i = 0; i < mtd_devs; i++) {\n@@ -1291,25 +1306,79 @@ static int __init ubi_init(void)\n \t\t}\n \t}\n \n+\treturn 0;\n+\n+out_detach:\n+\tfor (k = 0; k < i; k++)\n+\t\tif (ubi_devices[k]) {\n+\t\t\tmutex_lock(&ubi_devices_mutex);\n+\t\t\tubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1, false);\n+\t\t\tmutex_unlock(&ubi_devices_mutex);\n+\t\t}\n+\treturn err;\n+}\n+#ifndef CONFIG_MTD_UBI_MODULE\n+late_initcall(ubi_init_attach);\n+#endif\n+\n+static int __init ubi_init(void)\n+{\n+\tint err;\n+\n+\t/* Ensure that EC and VID headers have correct size */\n+\tBUILD_BUG_ON(sizeof(struct ubi_ec_hdr) != 64);\n+\tBUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64);\n+\n+\tif (mtd_devs > UBI_MAX_DEVICES) {\n+\t\tpr_err(\"UBI error: too many MTD devices, maximum is %d\\n\",\n+\t\t       UBI_MAX_DEVICES);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* Create base sysfs directory and sysfs files */\n+\terr = class_register(&ubi_class);\n+\tif (err < 0)\n+\t\treturn err;\n+\n+\terr = misc_register(&ubi_ctrl_cdev);\n+\tif (err) {\n+\t\tpr_err(\"UBI error: cannot register device\\n\");\n+\t\tgoto out;\n+\t}\n+\n+\tubi_wl_entry_slab = kmem_cache_create(\"ubi_wl_entry_slab\",\n+\t\t\t\t\t      sizeof(struct ubi_wl_entry),\n+\t\t\t\t\t      0, 0, NULL);\n+\tif (!ubi_wl_entry_slab) {\n+\t\terr = -ENOMEM;\n+\t\tgoto out_dev_unreg;\n+\t}\n+\n+\terr = ubi_debugfs_init();\n+\tif (err)\n+\t\tgoto out_slab;\n+\n \terr = ubiblock_init();\n \tif (err) {\n \t\tpr_err(\"UBI error: block: cannot initialize, error %d\\n\", err);\n \n \t\t/* See comment above re-ubi_is_module(). */\n \t\tif (ubi_is_module())\n-\t\t\tgoto out_detach;\n+\t\t\tgoto out_slab;\n+\t}\n+\n+\tregister_mtd_user(&ubi_mtd_notifier);\n+\n+\tif (ubi_is_module()) {\n+\t\terr = ubi_init_attach();\n+\t\tif (err)\n+\t\t\tgoto out_mtd_notifier;\n \t}\n \n \treturn 0;\n \n-out_detach:\n-\tfor (k = 0; k < i; k++)\n-\t\tif (ubi_devices[k]) {\n-\t\t\tmutex_lock(&ubi_devices_mutex);\n-\t\t\tubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1);\n-\t\t\tmutex_unlock(&ubi_devices_mutex);\n-\t\t}\n-\tubi_debugfs_exit();\n+out_mtd_notifier:\n+\tunregister_mtd_user(&ubi_mtd_notifier);\n out_slab:\n \tkmem_cache_destroy(ubi_wl_entry_slab);\n out_dev_unreg:\n@@ -1319,18 +1388,20 @@ static int __init ubi_init(void)\n \tpr_err(\"UBI error: cannot initialize UBI, error %d\\n\", err);\n \treturn err;\n }\n-late_initcall(ubi_init);\n+device_initcall(ubi_init);\n+\n \n static void __exit ubi_exit(void)\n {\n \tint i;\n \n \tubiblock_exit();\n+\tunregister_mtd_user(&ubi_mtd_notifier);\n \n \tfor (i = 0; i < UBI_MAX_DEVICES; i++)\n \t\tif (ubi_devices[i]) {\n \t\t\tmutex_lock(&ubi_devices_mutex);\n-\t\t\tubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1);\n+\t\t\tubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1, false);\n \t\t\tmutex_unlock(&ubi_devices_mutex);\n \t\t}\n \tubi_debugfs_exit();\ndiff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c\nindex bb55e863dd296..0ba6aa6a2e11d 100644\n--- a/drivers/mtd/ubi/cdev.c\n+++ b/drivers/mtd/ubi/cdev.c\n@@ -1065,7 +1065,7 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd,\n \t\t}\n \n \t\tmutex_lock(&ubi_devices_mutex);\n-\t\terr = ubi_detach_mtd_dev(ubi_num, 0);\n+\t\terr = ubi_detach_mtd_dev(ubi_num, 0, false);\n \t\tmutex_unlock(&ubi_devices_mutex);\n \t\tbreak;\n \t}\ndiff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h\nindex 44c0eeaf1e1b0..54093858f3385 100644\n--- a/drivers/mtd/ubi/ubi.h\n+++ b/drivers/mtd/ubi/ubi.h\n@@ -939,7 +939,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,\n int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,\n \t\t       int vid_hdr_offset, int max_beb_per1024,\n \t\t       bool disable_fm);\n-int ubi_detach_mtd_dev(int ubi_num, int anyway);\n+int ubi_detach_mtd_dev(int ubi_num, int anyway, bool have_lock);\n struct ubi_device *ubi_get_device(int ubi_num);\n void ubi_put_device(struct ubi_device *ubi);\n struct ubi_device *ubi_get_by_major(int major);\n",
    "prefixes": [
        "v4",
        "5/8"
    ]
}