diff mbox series

[v3,1/3] cli: panic when failed to allocate memory for the history buffer

Message ID tencent_2AE7952872F803E81AEF7D49589E6CCEFF0A@qq.com
State Accepted
Commit 44951340309d0dca73c05fc61406a1e839d1da93
Delegated to: Tom Rini
Headers show
Series [v3,1/3] cli: panic when failed to allocate memory for the history buffer | expand

Commit Message

Hanyuan Zhao March 5, 2024, 7:37 a.m. UTC
This commit simply modifies the history initialize function,
replacing the return value by panic with reasons. The calling
chains of hist_init don't have steps explicitly throwing or
dealing with the ENOMEM error, and once the init fails, the
whole system is died. Using panic here to provide error
information instead.

Signed-off-by: Hanyuan Zhao <hanyuan-z@qq.com>
---
This is v3 of patch series cli: allow users to disable history
if unused at all. Please ignore the v2 version.
---
Changes v1 -> v3:
  - Separate the first patch and let this patch be the panic one.
---
 common/cli_readline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Tom Rini March 14, 2024, 12:39 a.m. UTC | #1
On Tue, Mar 05, 2024 at 03:37:33PM +0800, Hanyuan Zhao wrote:

> This commit simply modifies the history initialize function,
> replacing the return value by panic with reasons. The calling
> chains of hist_init don't have steps explicitly throwing or
> dealing with the ENOMEM error, and once the init fails, the
> whole system is died. Using panic here to provide error
> information instead.
> 
> Signed-off-by: Hanyuan Zhao <hanyuan-z@qq.com>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/common/cli_readline.c b/common/cli_readline.c
index 2507be2295..99e7efdfe5 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -110,7 +110,7 @@  static int hist_init(void)
 
 	hist = calloc(HIST_MAX, HIST_SIZE + 1);
 	if (!hist)
-		return -ENOMEM;
+		panic("%s: calloc: out of memory!\n", __func__);
 
 	for (i = 0; i < HIST_MAX; i++)
 		hist_list[i] = hist + (i * (HIST_SIZE + 1));