Skip to content

Commit c67a0e4

Browse files
nathanlynchmpe
authored andcommitted
powerpc/rtas: clean up rtas_error_log_max initialization
The code in rtas_get_error_log_max() doesn't cause problems in practice, but there are no measures to ensure that the lazy initialization of the static rtas_error_log_max variable is atomic, and it's not worth adding them. Initialize the static rtas_error_log_max variable at boot when we're single-threaded instead of lazily on first use. Use the more appropriate of_property_read_u32() API instead of rtas_token() to consult the "rtas-error-log-max" property, which is not the name of an RTAS function. Convert use of printk() to pr_warn() and distinguish the possible error cases. Signed-off-by: Nathan Lynch <[email protected]> Reviewed-by: Andrew Donnellan <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9aafbfa commit c67a0e4

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

arch/powerpc/kernel/rtas.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,28 +353,40 @@ int rtas_service_present(const char *service)
353353
EXPORT_SYMBOL(rtas_service_present);
354354

355355
#ifdef CONFIG_RTAS_ERROR_LOGGING
356+
357+
static u32 rtas_error_log_max __ro_after_init = RTAS_ERROR_LOG_MAX;
358+
356359
/*
357360
* Return the firmware-specified size of the error log buffer
358361
* for all rtas calls that require an error buffer argument.
359362
* This includes 'check-exception' and 'rtas-last-error'.
360363
*/
361364
int rtas_get_error_log_max(void)
362365
{
363-
static int rtas_error_log_max;
364-
if (rtas_error_log_max)
365-
return rtas_error_log_max;
366-
367-
rtas_error_log_max = rtas_token ("rtas-error-log-max");
368-
if ((rtas_error_log_max == RTAS_UNKNOWN_SERVICE) ||
369-
(rtas_error_log_max > RTAS_ERROR_LOG_MAX)) {
370-
printk (KERN_WARNING "RTAS: bad log buffer size %d\n",
371-
rtas_error_log_max);
372-
rtas_error_log_max = RTAS_ERROR_LOG_MAX;
373-
}
374366
return rtas_error_log_max;
375367
}
376368
EXPORT_SYMBOL(rtas_get_error_log_max);
377369

370+
static void __init init_error_log_max(void)
371+
{
372+
static const char propname[] __initconst = "rtas-error-log-max";
373+
u32 max;
374+
375+
if (of_property_read_u32(rtas.dev, propname, &max)) {
376+
pr_warn("%s not found, using default of %u\n",
377+
propname, RTAS_ERROR_LOG_MAX);
378+
max = RTAS_ERROR_LOG_MAX;
379+
}
380+
381+
if (max > RTAS_ERROR_LOG_MAX) {
382+
pr_warn("%s = %u, clamping max error log size to %u\n",
383+
propname, max, RTAS_ERROR_LOG_MAX);
384+
max = RTAS_ERROR_LOG_MAX;
385+
}
386+
387+
rtas_error_log_max = max;
388+
}
389+
378390

379391
static char rtas_err_buf[RTAS_ERROR_LOG_MAX];
380392
static int rtas_last_error_token;
@@ -432,6 +444,7 @@ static char *__fetch_rtas_last_error(char *altbuf)
432444
#else /* CONFIG_RTAS_ERROR_LOGGING */
433445
#define __fetch_rtas_last_error(x) NULL
434446
#define get_errorlog_buffer() NULL
447+
static void __init init_error_log_max(void) {}
435448
#endif
436449

437450

@@ -1340,6 +1353,8 @@ void __init rtas_initialize(void)
13401353
no_entry = of_property_read_u32(rtas.dev, "linux,rtas-entry", &entry);
13411354
rtas.entry = no_entry ? rtas.base : entry;
13421355

1356+
init_error_log_max();
1357+
13431358
/*
13441359
* Discover these now to avoid device tree lookups in the
13451360
* panic path.

0 commit comments

Comments
 (0)