base-files: fix uid/gid auto-enumeration to avoid 16-bit limit
[openwrt/openwrt.git] / target / linux / generic / backport-6.6 / 819-v6.8-0008-nvmem-layouts-refactor-.add_cells-callback-arguments.patch
1 From 401df0d4f4098ecc9c5278da2f50756d62e5b37d Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Tue, 19 Dec 2023 13:01:03 +0100
4 Subject: [PATCH] nvmem: layouts: refactor .add_cells() callback arguments
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Simply pass whole "struct nvmem_layout" instead of single variables.
10 There is nothing in "struct nvmem_layout" that we have to hide from
11 layout drivers. They also access it during .probe() and .remove().
12
13 Thanks to this change:
14
15 1. API gets more consistent
16 All layouts drivers callbacks get the same argument
17
18 2. Layouts get correct device
19 Before this change NVMEM core code was passing NVMEM device instead
20 of layout device. That resulted in:
21 * Confusing prints
22 * Calling devm_*() helpers on wrong device
23 * Helpers like of_device_get_match_data() dereferencing NULLs
24
25 3. It gets possible to get match data
26 First of all nvmem_layout_get_match_data() requires passing "struct
27 nvmem_layout" which .add_cells() callback didn't have before this. It
28 doesn't matter much as it's rather useless now anyway (and will be
29 dropped).
30 What's more important however is that of_device_get_match_data() can
31 be used now thanks to owning a proper device pointer.
32
33 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
34 Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
35 Reviewed-by: Michael Walle <michael@walle.cc>
36 Link: https://lore.kernel.org/r/20231219120104.3422-1-zajec5@gmail.com
37 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
38 ---
39 drivers/nvmem/core.c | 2 +-
40 drivers/nvmem/layouts/onie-tlv.c | 4 +++-
41 drivers/nvmem/layouts/sl28vpd.c | 4 +++-
42 include/linux/nvmem-provider.h | 2 +-
43 4 files changed, 8 insertions(+), 4 deletions(-)
44
45 --- a/drivers/nvmem/core.c
46 +++ b/drivers/nvmem/core.c
47 @@ -854,7 +854,7 @@ int nvmem_layout_register(struct nvmem_l
48 return -EINVAL;
49
50 /* Populate the cells */
51 - ret = layout->add_cells(&layout->nvmem->dev, layout->nvmem);
52 + ret = layout->add_cells(layout);
53 if (ret)
54 return ret;
55
56 --- a/drivers/nvmem/layouts/onie-tlv.c
57 +++ b/drivers/nvmem/layouts/onie-tlv.c
58 @@ -182,8 +182,10 @@ static bool onie_tlv_crc_is_valid(struct
59 return true;
60 }
61
62 -static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem)
63 +static int onie_tlv_parse_table(struct nvmem_layout *layout)
64 {
65 + struct nvmem_device *nvmem = layout->nvmem;
66 + struct device *dev = &layout->dev;
67 struct onie_tlv_hdr hdr;
68 size_t table_len, data_len, hdr_len;
69 u8 *table, *data;
70 --- a/drivers/nvmem/layouts/sl28vpd.c
71 +++ b/drivers/nvmem/layouts/sl28vpd.c
72 @@ -80,8 +80,10 @@ static int sl28vpd_v1_check_crc(struct d
73 return 0;
74 }
75
76 -static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvmem)
77 +static int sl28vpd_add_cells(struct nvmem_layout *layout)
78 {
79 + struct nvmem_device *nvmem = layout->nvmem;
80 + struct device *dev = &layout->dev;
81 const struct nvmem_cell_info *pinfo;
82 struct nvmem_cell_info info = {0};
83 struct device_node *layout_np;
84 --- a/include/linux/nvmem-provider.h
85 +++ b/include/linux/nvmem-provider.h
86 @@ -173,7 +173,7 @@ struct nvmem_cell_table {
87 struct nvmem_layout {
88 struct device dev;
89 struct nvmem_device *nvmem;
90 - int (*add_cells)(struct device *dev, struct nvmem_device *nvmem);
91 + int (*add_cells)(struct nvmem_layout *layout);
92 };
93
94 struct nvmem_layout_driver {