nvmem: layouts: refactor .add_cells() callback arguments
authorRafał Miłecki <rafal@milecki.pl>
Tue, 19 Dec 2023 12:01:03 +0000 (13:01 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Jan 2024 16:01:13 +0000 (17:01 +0100)
Simply pass whole "struct nvmem_layout" instead of single variables.
There is nothing in "struct nvmem_layout" that we have to hide from
layout drivers. They also access it during .probe() and .remove().

Thanks to this change:

1. API gets more consistent
   All layouts drivers callbacks get the same argument

2. Layouts get correct device
   Before this change NVMEM core code was passing NVMEM device instead
   of layout device. That resulted in:
   * Confusing prints
   * Calling devm_*() helpers on wrong device
   * Helpers like of_device_get_match_data() dereferencing NULLs

3. It gets possible to get match data
   First of all nvmem_layout_get_match_data() requires passing "struct
   nvmem_layout" which .add_cells() callback didn't have before this. It
   doesn't matter much as it's rather useless now anyway (and will be
   dropped).
   What's more important however is that of_device_get_match_data() can
   be used now thanks to owning a proper device pointer.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Michael Walle <michael@walle.cc>
Link: https://lore.kernel.org/r/20231219120104.3422-1-zajec5@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvmem/core.c
drivers/nvmem/layouts/onie-tlv.c
drivers/nvmem/layouts/sl28vpd.c
include/linux/nvmem-provider.h

index ba559e81f77fa1fe4a4d9f98d1afad1a3caa720e..441d132ebb61f38c6b0a044f999f8b6fae8e0d70 100644 (file)
@@ -854,7 +854,7 @@ int nvmem_layout_register(struct nvmem_layout *layout)
                return -EINVAL;
 
        /* Populate the cells */
-       ret = layout->add_cells(&layout->nvmem->dev, layout->nvmem);
+       ret = layout->add_cells(layout);
        if (ret)
                return ret;
 
index b24cc5dcc6ee8ffc4d520fd26832fe8368f37c61..9d2ad5f2dc1012cc5930daa26b0889b61d7c1483 100644 (file)
@@ -182,8 +182,10 @@ static bool onie_tlv_crc_is_valid(struct device *dev, size_t table_len, u8 *tabl
        return true;
 }
 
-static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem)
+static int onie_tlv_parse_table(struct nvmem_layout *layout)
 {
+       struct nvmem_device *nvmem = layout->nvmem;
+       struct device *dev = &layout->dev;
        struct onie_tlv_hdr hdr;
        size_t table_len, data_len, hdr_len;
        u8 *table, *data;
index b8ffae646cc26fb0851cf2b14f40e2ed66fd1cf4..53fa50f17dcaf7aa53435dc21ee039c892ab3ca5 100644 (file)
@@ -80,8 +80,10 @@ static int sl28vpd_v1_check_crc(struct device *dev, struct nvmem_device *nvmem)
        return 0;
 }
 
-static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvmem)
+static int sl28vpd_add_cells(struct nvmem_layout *layout)
 {
+       struct nvmem_device *nvmem = layout->nvmem;
+       struct device *dev = &layout->dev;
        const struct nvmem_cell_info *pinfo;
        struct nvmem_cell_info info = {0};
        struct device_node *layout_np;
index 6fe65b35ea972f6430f26b5b7a225b8a98051569..81a67642ac553b412b591abd3ef596fe7841718b 100644 (file)
@@ -173,7 +173,7 @@ struct nvmem_cell_table {
 struct nvmem_layout {
        struct device dev;
        struct nvmem_device *nvmem;
-       int (*add_cells)(struct device *dev, struct nvmem_device *nvmem);
+       int (*add_cells)(struct nvmem_layout *layout);
 };
 
 struct nvmem_layout_driver {