From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Anderson Date: Sat, 10 Oct 2020 15:43:29 -0400 Subject: [PATCH v2 04/22] log: Add new category names to log_cat_name In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> Message-ID: <20201010194347.90096-5-seanga2@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Without every category between LOGC_NONE and LOGC_COUNT present in log_cat_name, log_get_cat_by_name will dereference NULL pointers if it doesn't find a name early enough. Fixes: c3aed5db59 ("sandbox: spi: Add more logging") Fixes: a5c13b68e7 ("sandbox: log: Add a category for sandbox") Fixes: 9f407d4ef0 ("Add core support for a bloblist to convey data from SPL") Fixes: cce61fc428 ("dm: devres: Convert to use logging") Fixes: 7ca2850cbc ("dm: core: Add basic ACPI support") Signed-off-by: Sean Anderson --- Changes in v2: - Add compiletime assert on size of log_cat_name common/log.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/log.c b/common/log.c index bda5139b69..11f488d71d 100644 --- a/common/log.c +++ b/common/log.c @@ -13,7 +13,7 @@ DECLARE_GLOBAL_DATA_PTR; -static const char *const log_cat_name[LOGC_COUNT - LOGC_NONE] = { +static const char *const log_cat_name[] = { "none", "arch", "board", @@ -21,6 +21,11 @@ static const char *const log_cat_name[LOGC_COUNT - LOGC_NONE] = { "driver-model", "device-tree", "efi", + "alloc", + "sandbox", + "bloblist", + "devres", + "acpi", }; static const char *const log_level_name[LOGL_COUNT] = { @@ -40,6 +45,9 @@ const char *log_get_cat_name(enum log_category_t cat) { const char *name; + compiletime_assert(ARRAY_SIZE(log_cat_name) == LOGC_COUNT - LOGC_NONE, + "missing logging category name"); + if (cat < 0 || cat >= LOGC_COUNT) return ""; if (cat >= LOGC_NONE) -- 2.28.0