uboot-mvebu: remove enabled CONFIG_CMD_SETEXPR
[openwrt/openwrt.git] / package / boot / uboot-mvebu / patches / 012-nvme-Do-not-allocate-8kB-buffer-on-stack.patch
1 From d17ab6e1289b1d705c75de8a2351218962fb7352 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali@kernel.org>
3 Date: Thu, 9 Dec 2021 11:06:39 +0100
4 Subject: [PATCH] nvme: Do not allocate 8kB buffer on stack
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Calling 'nvme scan' followed by 'nvme detail' crashes U-Boot on Turris
10 Omnia with the following error:
11
12 undefined instruction
13 pc : [<0a000000>] lr : [<7ff80bfc>]
14 reloc pc : [<8a8c0000>] lr : [<00840bfc>]
15 sp : 7fb2b908 ip : 0000002a fp : 02000000
16 r10: 04000000 r9 : 7fb2fed0 r8 : e1000000
17 r7 : 0c000000 r6 : 03000000 r5 : 06000000 r4 : 01000000
18 r3 : 7fb30928 r2 : 7fb30928 r1 : 00000000 r0 : 00000000
19 Flags: nZCv IRQs off FIQs off Mode SVC_32
20 Code: 0f0fb4f0 0f0fb4f0 0f0fb4f0 0f0fb4f0 (f0f04b0f)
21 Resetting CPU ...
22
23 This happens when nvme_print_info() tries to return to the caller. It
24 looks like this error is caused by trying to allocate 8 KiB of memory
25 on the stack by the two uses of ALLOC_CACHE_ALIGN_BUFFER().
26
27 Use malloc_cache_aligned() to allocate this memory dynamically instead.
28
29 This fixes 'nvme detail' on Turris Omnia.
30
31 Note that similar change was applied to file drivers/nvme/nvme.c in past by
32 commit 2f83481dff9c ("nvme: use page-aligned buffer for identify command").
33
34 Signed-off-by: Pali Rohár <pali@kernel.org>
35 Signed-off-by: Marek Behún <marek.behun@nic.cz>
36 ---
37 drivers/nvme/nvme_show.c | 35 ++++++++++++++++++++++++++---------
38 1 file changed, 26 insertions(+), 9 deletions(-)
39
40 --- a/drivers/nvme/nvme_show.c
41 +++ b/drivers/nvme/nvme_show.c
42 @@ -106,24 +106,41 @@ int nvme_print_info(struct udevice *udev
43 {
44 struct nvme_ns *ns = dev_get_priv(udev);
45 struct nvme_dev *dev = ns->dev;
46 - ALLOC_CACHE_ALIGN_BUFFER(char, buf_ns, sizeof(struct nvme_id_ns));
47 - struct nvme_id_ns *id = (struct nvme_id_ns *)buf_ns;
48 - ALLOC_CACHE_ALIGN_BUFFER(char, buf_ctrl, sizeof(struct nvme_id_ctrl));
49 - struct nvme_id_ctrl *ctrl = (struct nvme_id_ctrl *)buf_ctrl;
50 + struct nvme_id_ctrl *ctrl;
51 + struct nvme_id_ns *id;
52 + int ret = 0;
53
54 - if (nvme_identify(dev, 0, 1, (dma_addr_t)(long)ctrl))
55 - return -EIO;
56 + ctrl = memalign(dev->page_size, sizeof(struct nvme_id_ctrl));
57 + if (!ctrl)
58 + return -ENOMEM;
59 +
60 + if (nvme_identify(dev, 0, 1, (dma_addr_t)(long)ctrl)) {
61 + ret = -EIO;
62 + goto free_ctrl;
63 + }
64
65 print_optional_admin_cmd(le16_to_cpu(ctrl->oacs), ns->devnum);
66 print_optional_nvm_cmd(le16_to_cpu(ctrl->oncs), ns->devnum);
67 print_format_nvme_attributes(ctrl->fna, ns->devnum);
68
69 - if (nvme_identify(dev, ns->ns_id, 0, (dma_addr_t)(long)id))
70 - return -EIO;
71 + id = memalign(dev->page_size, sizeof(struct nvme_id_ns));
72 + if (!id) {
73 + ret = -ENOMEM;
74 + goto free_ctrl;
75 + }
76 +
77 + if (nvme_identify(dev, ns->ns_id, 0, (dma_addr_t)(long)id)) {
78 + ret = -EIO;
79 + goto free_id;
80 + }
81
82 print_formats(id, ns);
83 print_data_protect_cap(id->dpc, ns->devnum);
84 print_metadata_cap(id->mc, ns->devnum);
85
86 - return 0;
87 +free_id:
88 + free(id);
89 +free_ctrl:
90 + free(ctrl);
91 + return ret;
92 }