[RFC] nvmem: u-boot-env: improve error checking

Message ID CH0PR20MB381875927236C07B9CF9A8099C792@CH0PR20MB3818.namprd20.prod.outlook.com
State New
Headers
Series [RFC] nvmem: u-boot-env: improve error checking |

Commit Message

Nick Spooner Jan. 26, 2024, 11:10 p.m. UTC
  Coverity scan reported CID 1575482: error handling issues; this patch
addresses this by adding error handling to u_boot_env_add_cells.

I added the RFC tag to this patch since I'm not confident about the
logic here. The check is reused from nvmem_add_cells in core.c, which
doesn't include an of_node_put on a device_node, whereas
nvmem_add_cells_from_dt does. Without much certainty, I went with the
less complex option and added it here. Any advice or suggested fixes to
this patch are welcome!

Signed-off-by: Nick Spooner <nicholas.spooner@seagate.com>
---
 drivers/nvmem/u-boot-env.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--
2.34.1
  

Comments

Dan Carpenter Jan. 29, 2024, 9 a.m. UTC | #1
Your patch is white space damaged and doesn't apply.  Read the first
paragraph of Documentation/process/email-clients.rst

On Fri, Jan 26, 2024 at 11:10:06PM +0000, Nick Spooner wrote:
> Coverity scan reported CID 1575482: error handling issues; this patch
> addresses this by adding error handling to u_boot_env_add_cells.
> 
> I added the RFC tag to this patch since I'm not confident about the
> logic here.

Just put this kind of comments under the --- cut off line.  We're used
to reviewing patches like this so it's not a big deal.

> The check is reused from nvmem_add_cells in core.c, which
> doesn't include an of_node_put on a device_node, whereas
> nvmem_add_cells_from_dt does. Without much certainty, I went with the
> less complex option and added it here. Any advice or suggested fixes to
> this patch are welcome!
> 

nvmem_add_cells_from_dt() is cleaning up from:
	addr = of_get_property(child, "reg", &len);
so that's why it does:
	of_node_put(child);

It's not necessary in u_boot_env_add_cells().

regards,
dan carpenter
  

Patch

diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c
index befbab156cda..c15de5f7fd99 100644
--- a/drivers/nvmem/u-boot-env.c
+++ b/drivers/nvmem/u-boot-env.c
@@ -95,6 +95,7 @@  static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf,
        struct device *dev = priv->dev;
        char *data = buf + data_offset;
        char *var, *value, *eq;
+       int rval;

        for (var = data;
             var < data + data_len && *var;
@@ -119,7 +120,9 @@  static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf,
                        info.read_post_process = u_boot_env_read_post_process_ethaddr;
                }

-               nvmem_add_one_cell(nvmem, &info);
+               rval = nvmem_add_one_cell(nvmem, &info);
+               if (rval)
+                       return rval;
        }

        return 0;