kernel: backport NVMEM patches queued for the v6.4
[openwrt/staging/dedeckeh.git] / target / linux / generic / backport-5.10 / 814-v6.4-0004-nvmem-core-request-layout-modules-loading.patch
1 From b1c37bec1ccfe5ccab72bc0ddc0dfa45c43e2de2 Mon Sep 17 00:00:00 2001
2 From: Miquel Raynal <miquel.raynal@bootlin.com>
3 Date: Tue, 4 Apr 2023 18:21:23 +0100
4 Subject: [PATCH] nvmem: core: request layout modules loading
5
6 When a storage device like an eeprom or an mtd device probes, it
7 registers an nvmem device if the nvmem subsystem has been enabled (bool
8 symbol). During nvmem registration, if the device is using layouts to
9 expose dynamic nvmem cells, the core will first try to get a reference
10 over the layout driver callbacks. In practice there is not relationship
11 that can be described between the storage driver and the nvmem
12 layout. So there is no way we can enforce both drivers will be built-in
13 or both will be modules. If the storage device driver is built-in but
14 the layout is built as a module, instead of badly failing with an
15 endless probe deferral loop, lets just make a modprobe call in case the
16 driver was made available in an initramfs with
17 of_device_node_request_module(), and offer a fully functional system to
18 the user.
19
20 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
21 Tested-by: Michael Walle <michael@walle.cc>
22 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
23 Link: https://lore.kernel.org/r/20230404172148.82422-16-srinivas.kandagatla@linaro.org
24 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
25 ---
26 drivers/nvmem/core.c | 8 ++++++++
27 1 file changed, 8 insertions(+)
28
29 --- a/drivers/nvmem/core.c
30 +++ b/drivers/nvmem/core.c
31 @@ -17,6 +17,7 @@
32 #include <linux/nvmem-provider.h>
33 #include <linux/gpio/consumer.h>
34 #include <linux/of.h>
35 +#include <linux/of_device.h>
36 #include <linux/slab.h>
37
38 struct nvmem_device {
39 @@ -761,6 +762,13 @@ static struct nvmem_layout *nvmem_layout
40 if (!layout_np)
41 return NULL;
42
43 + /*
44 + * In case the nvmem device was built-in while the layout was built as a
45 + * module, we shall manually request the layout driver loading otherwise
46 + * we'll never have any match.
47 + */
48 + of_request_module(layout_np);
49 +
50 spin_lock(&nvmem_layout_lock);
51
52 list_for_each_entry(l, &nvmem_layouts, node) {