From cbc29f107e51b1cc7d1e7b0bbe0691a1224205f1 Mon Sep 17 00:00:00 2001 From: Alexander Gordeev Date: Wed, 25 Jan 2023 19:16:10 +0100 Subject: [PATCH] s390/mem_detect: do not update output parameters on failure Function __get_mem_detect_block() resets start and end output parameters in case of invalid mem_detect array index is provided. That violates the rule of sparing the output on fail path and leads e.g to a below anomaly: for_each_mem_detect_block(i, &start, &end) continue; One would expect start and end contain addresses of the last memory block (if available), but in fact the two will be reset to zeroes. That is not how an iterator is expected to work. Reviewed-by: Vasily Gorbik Signed-off-by: Alexander Gordeev Signed-off-by: Heiko Carstens --- arch/s390/include/asm/mem_detect.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/s390/include/asm/mem_detect.h b/arch/s390/include/asm/mem_detect.h index a7c922a69050..058ac2647eb7 100644 --- a/arch/s390/include/asm/mem_detect.h +++ b/arch/s390/include/asm/mem_detect.h @@ -40,11 +40,8 @@ void add_mem_detect_block(u64 start, u64 end); static inline int __get_mem_detect_block(u32 n, unsigned long *start, unsigned long *end) { - if (n >= mem_detect.count) { - *start = 0; - *end = 0; + if (n >= mem_detect.count) return -1; - } if (n < MEM_INLINED_ENTRIES) { *start = (unsigned long)mem_detect.entries[n].start;