From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF9531AAA00; Fri, 20 Dec 2024 23:06:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734735989; cv=none; b=AEEhS997a/E77qiLD4RxVb7iX70rD009DOEiC1QndK4tleHmYBiaDGj8LLb9mO8BCmvAuni+KmNFGGk7heWDNa/Yx6gnZ2qF/d1YXj4Rn5K7sMFCNlZ3+rpXutqSFFey59rLjZruDKHGZmAEZBG9KGtXGe4RR12ACpsJ2BrPMOs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734735989; c=relaxed/simple; bh=rDnT4CiiEQHDei+WTY8t89wAldSK7/wzy9hzuNQ2FY0=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=mR9kqnewnuKbl4Z6HKX782zc6ZZY4ffOkl8y89IwF3ijfVzjD0RbX27USRLC159FaDuSuyd7NUSOJE8/OXSOBBawVmJms95i9/qtPJtetAe58F47wxu7KZXAN7QgK8e4bcHWohEozn+w06AOc3PBkG39JKGUGyQJBhltZ0C3u5I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=ko0NoC85; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="ko0NoC85" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51D4DC4CECD; Fri, 20 Dec 2024 23:06:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1734735987; bh=rDnT4CiiEQHDei+WTY8t89wAldSK7/wzy9hzuNQ2FY0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ko0NoC85TGcP1IppTBQ7r5GFZyBBTG2SpQ0tFrc/AJkG+/T9Itx2K+hPhmLUjOFT3 W/JopMsDfKdWQ+Sgte/CaZu5u4oCC9X7AhqHTGt1/QNG5SKrdk/OmLPnondMcorXOq YK2sRjfqtNIqcRTWYGNAXSYWTaR7HQTBx80wOGXo= Date: Fri, 20 Dec 2024 15:06:23 -0800 From: Andrew Morton To: Guo Weikang Cc: Mike Rapoport , Dennis Zhou , Tejun Heo , Christoph Lameter , Thomas Bogendoerfer , Sam Creasey , Geert Uytterhoeven , Huacai Chen , Will Deacon , Catalin Marinas , Oreoluwa Babatunde , rafael.j.wysocki@intel.com, Palmer Dabbelt , Hanjun Guo , Easwar Hariharan , Johannes Berg , Ingo Molnar , Dave Hansen , Christian Brauner , KP Singh , Richard Henderson , Matt Turner , Russell King , WANG Xuerui , Michael Ellerman , Jonas Bonn , Stefan Kristiansson , Stafford Horne , Helge Deller , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Geoff Levand , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Andreas Larsson , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Len Brown , Juergen Gross , Boris Ostrovsky , Chris Zankel , Max Filippov , Tero Kristo , Michael Turquette , Stephen Boyd , Rob Herring , Saravana Kannan , Pavel Machek , Yury Norov , Rasmus Villemoes , Marco Elver , Al Viro , Arnd Bergmann , linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, kasan-dev@googlegroups.com, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-acpi@vger.kernel.org, xen-devel@lists.xenproject.org, linux-omap@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-mm@kvack.org, linux-pm@vger.kernel.org Subject: Re: [PATCH] mm/memblock: Add memblock_alloc_or_panic interface Message-Id: <20241220150623.278e8fa9f073b66dc81edfe6@linux-foundation.org> In-Reply-To: <20241220092638.2611414-1-guoweikang.kernel@gmail.com> References: <20241220092638.2611414-1-guoweikang.kernel@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 20 Dec 2024 17:26:38 +0800 Guo Weikang wrote: > Before SLUB initialization, various subsystems used memblock_alloc to > allocate memory. In most cases, when memory allocation fails, an immediate > panic is required. To simplify this behavior and reduce repetitive checks, > introduce `memblock_alloc_or_panic`. This function ensures that memory > allocation failures result in a panic automatically, improving code > readability and consistency across subsystems that require this behavior. > Seems nice. > ... > > --- a/include/linux/memblock.h > +++ b/include/linux/memblock.h > @@ -417,6 +417,19 @@ static __always_inline void *memblock_alloc(phys_addr_t size, phys_addr_t align) > MEMBLOCK_ALLOC_ACCESSIBLE, NUMA_NO_NODE); > } > > +static __always_inline void *memblock_alloc_or_panic(phys_addr_t size, phys_addr_t align) We lost the printing of the function name, but it's easy to retain with something like #define memblock_alloc_or_panic(size, align) \ __memblock_alloc_or_panic(size, align, __func__) > +{ > + void *addr = memblock_alloc(size, align); > + > + if (unlikely(!addr)) > +#ifdef CONFIG_PHYS_ADDR_T_64BIT > + panic("%s: Failed to allocate %llu bytes\n", __func__, size); Won't this always print "memblock_alloc_or_panic: Failed ..."? Not very useful. > +#else > + panic("%s: Failed to allocate %u bytes\n", __func__, size); > +#endif We can avoid the ifdef with printk's "%pap"? > + return addr; > +}