diff mbox series

[1/2] firmware: tegra: bpmp: Fix error paths in debugfs

Message ID 20230301134756.999169-1-cyndis@kapsi.fi
State Accepted
Headers show
Series [1/2] firmware: tegra: bpmp: Fix error paths in debugfs | expand

Commit Message

Mikko Perttunen March 1, 2023, 1:47 p.m. UTC
From: Mikko Perttunen <mperttunen@nvidia.com>

Some error paths in mrq_debug_read and bpmp_debug_show would overwrite
the return error code with a subsequent call to mrq_debug_close.

Change the code to only change the error code if there was no prior
error.

Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
---
 drivers/firmware/tegra/bpmp-debugfs.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Thierry Reding April 3, 2023, 12:34 p.m. UTC | #1
From: Thierry Reding <treding@nvidia.com>

On Wed, 1 Mar 2023 15:47:55 +0200, Mikko Perttunen wrote:
> From: Mikko Perttunen <mperttunen@nvidia.com>
> 
> Some error paths in mrq_debug_read and bpmp_debug_show would overwrite
> the return error code with a subsequent call to mrq_debug_close.
> 
> Change the code to only change the error code if there was no prior
> error.
> 
> [...]

Applied, thanks!

[1/2] firmware: tegra: bpmp: Fix error paths in debugfs
      (no commit info)
[2/2] soc/tegra: bpmp: Actually free memory on error path
      commit: 61228c9b240468dba55ef8a4ac93e777c810c68b

Best regards,
diff mbox series

Patch

diff --git a/drivers/firmware/tegra/bpmp-debugfs.c b/drivers/firmware/tegra/bpmp-debugfs.c
index 3ca2b5d9e66f..6dfe3d34109e 100644
--- a/drivers/firmware/tegra/bpmp-debugfs.c
+++ b/drivers/firmware/tegra/bpmp-debugfs.c
@@ -193,7 +193,7 @@  static int mrq_debug_read(struct tegra_bpmp *bpmp, const char *name,
 		},
 	};
 	u32 fd = 0, len = 0;
-	int remaining, err;
+	int remaining, err, close_err;
 
 	mutex_lock(&bpmp_debug_lock);
 	err = mrq_debug_open(bpmp, name, &fd, &len, 0);
@@ -231,7 +231,9 @@  static int mrq_debug_read(struct tegra_bpmp *bpmp, const char *name,
 	*nbytes = len;
 
 close:
-	err = mrq_debug_close(bpmp, fd);
+	close_err = mrq_debug_close(bpmp, fd);
+	if (!err)
+		err = close_err;
 out:
 	mutex_unlock(&bpmp_debug_lock);
 	return err;
@@ -319,7 +321,7 @@  static int bpmp_debug_show(struct seq_file *m, void *p)
 		},
 	};
 	u32 fd = 0, len = 0;
-	int remaining, err;
+	int remaining, err, close_err;
 
 	filename = get_filename(bpmp, file, fnamebuf, sizeof(fnamebuf));
 	if (!filename)
@@ -353,7 +355,9 @@  static int bpmp_debug_show(struct seq_file *m, void *p)
 	}
 
 close:
-	err = mrq_debug_close(bpmp, fd);
+	close_err = mrq_debug_close(bpmp, fd);
+	if (!err)
+		err = close_err;
 out:
 	mutex_unlock(&bpmp_debug_lock);
 	return err;