Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1190083lqb; Thu, 30 May 2024 03:06:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXm1aawvktxmLsouhZZOAOyDr9y8Zg8sgkfMNzmn8bKbDtXdz8NYNzn6s8GJesuQ6hGRd76zaCQOc82AifhTVcHVY23QW2OTK6mlpLknw== X-Google-Smtp-Source: AGHT+IG+JEnl91KKR6GodtdC0nKah00BnFABCOUrvJnmSoZFCt0xH0g9dHrECIiEZgoWje47s8nY X-Received: by 2002:a17:906:cb90:b0:a5c:dce0:9f4e with SMTP id a640c23a62f3a-a65f0bd7b2bmr116623366b.28.1717063570749; Thu, 30 May 2024 03:06:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717063570; cv=pass; d=google.com; s=arc-20160816; b=RRSPcgsS5ZtfJskCLEDqoo88DMg84sre2+CUWbuz+eEMORv6iMa/t43IChyiUDhDl0 g9PrEddbEISx1AFOLw8IxlhKyJ6Jekai0fNts/kKFvDaSexe69ZCKj5D9+qZegrx99yM srwzuHcyQhS1nPjsmMoiNet66vWSG8qWuhBhZcT1wtCogzSNgO49PfhMjj8quBynsEWc fTyWY+19MqTMWED/XXYQGNFkShcRLxr3HF3JXF+0st6rLNSbXfx6Ic2atzL/c0VxMMcr LABLXqCSKhtvtnOpHOAfL4IE+Bkq73eiy6j5u5uqmbN1Krd80ovGinrxsoYro8Pgf5XU P+pQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=w7dav7ELoVCScmXgufRYWTpcvsx2au52cYBPxSHDc/k=; fh=zbb8GDqhBAqmE+binjI/HiZPmIqz0488uEwTQqH15do=; b=rWCt4ikVaC7bKzyf8JuW4rrqzj8lXlxE5YmYGqXIDCmiIopACB8hMh/LEyIfsgXnpN vxks+dSaKqLHkxWWr2rEateivTNCuw5BMPCJQX8tvRIaGsej7xnNVyrOz7x+0vF6n5L4 pRRT2jstV+RFMl39C1HK67H8Q1eP+x7MrkHd9AQOPTJPOAUTqiQ6j4OseZB9xP8c85nv 0v8ImlMgjYWs26oDEPp+R57TeTj54DARF+9gKL8m7QAcRusQTBG9lPW+QJJiBu9s/8Tc Nlv9wL0KrKWCtxGIfH4ZZmc/jDWoTzSBaEzWX2WNJAVQvCF5mZKKmiYzQAXcQztF81MX 5bIw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@t-8ch.de header.s=mail header.b=lbWREGlk; arc=pass (i=1 spf=pass spfdomain=t-8ch.de dkim=pass dkdomain=t-8ch.de dmarc=pass fromdomain=t-8ch.de); spf=pass (google.com: domain of linux-kernel+bounces-195228-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195228-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=t-8ch.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a64251a2567si212786266b.411.2024.05.30.03.06.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 03:06:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195228-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@t-8ch.de header.s=mail header.b=lbWREGlk; arc=pass (i=1 spf=pass spfdomain=t-8ch.de dkim=pass dkdomain=t-8ch.de dmarc=pass fromdomain=t-8ch.de); spf=pass (google.com: domain of linux-kernel+bounces-195228-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195228-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=t-8ch.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7A3DA1F22D7B for ; Thu, 30 May 2024 10:06:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E5A331761A7; Thu, 30 May 2024 10:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=t-8ch.de header.i=@t-8ch.de header.b="lbWREGlk" Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 2F65D1761B4; Thu, 30 May 2024 10:06:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717063566; cv=none; b=JGs9AU+t8jLlNeoPIQ7V3hgkOsMRDcCHnq/wthBHOxgsrQIr08BV5y2dZ4PUFNZ6d5K/NnKVFgwpIpyqmM0hjcwCZXg1mginyV1iSsZJ5k97PhYDH9f5/Kxj+OBCaHYjOq7oAHQW2Nk8I1RNu793/Ydgcsq03jtqDiBjO6QZExU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717063566; c=relaxed/simple; bh=P8D54ok9cu6zOkpePcZy8AUJjwmh3AO9JwlkXPHfqEM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m/O9EWYx52v1dRztpekamVpgs1DFQ3Y+7GfXqmcVd/0+sVaVpMZB7jFT4PgCioLrtisnHEximC6Kqp1C+oYya0xzuXlvj9L6DxYga1T8v1TLfTo8mPryMaCbML1mGky5g+QZMci0w5fgtI55m1V9K5V/v65KX8EBEC7uLUwJ+iI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=t-8ch.de; spf=pass smtp.mailfrom=t-8ch.de; dkim=pass (1024-bit key) header.d=t-8ch.de header.i=@t-8ch.de header.b=lbWREGlk; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=t-8ch.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=t-8ch.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=t-8ch.de; s=mail; t=1717063562; bh=P8D54ok9cu6zOkpePcZy8AUJjwmh3AO9JwlkXPHfqEM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lbWREGlk5GiSkfmpcriEcHBf6Tn3CssE33q54ngE6AIhtMmYix7k4RywNLNddmt1C 66ltCd61fcVdH6FnTimj99g6BVeUFP+B4CC0AB6Tdnfivk7CALIprN/JQx/JqMu4Fp VfptFL9AJhKSJF3tmOzqxxDlB5SI1V2ZNNb565vA= Date: Thu, 30 May 2024 12:06:01 +0200 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Jiaxun Yang Cc: Huacai Chen , Binbin Zhou , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v3 1/4] LoongArch: Fix built-in DTB detection Message-ID: References: <20240522-loongarch-booting-fixes-v3-0-25e77a8fc86e@flygoat.com> <20240522-loongarch-booting-fixes-v3-1-25e77a8fc86e@flygoat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240522-loongarch-booting-fixes-v3-1-25e77a8fc86e@flygoat.com> On 2024-05-22 23:02:17+0000, Jiaxun Yang wrote: > fdt_check_header(__dtb_start) will always success because kernel > provided a dummy dtb, and by coincidence __dtb_start clashed with > entry of this dummy dtb. The consequence is fdt passed from > firmware will never be taken. > > Fix by trying to utilise __dtb_start only when CONFIG_BUILTIN_DTB > is enabled. > > Cc: stable@vger.kernel.org > Fixes: 7b937cc243e5 ("of: Create of_root if no dtb provided by firmware") > Signed-off-by: Jiaxun Yang > --- > v3: Better reasoning in commit message, thanks Binbin and Huacai! > --- > arch/loongarch/kernel/setup.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c > index 60e0fe97f61a..ea6d5db6c878 100644 > --- a/arch/loongarch/kernel/setup.c > +++ b/arch/loongarch/kernel/setup.c > @@ -275,16 +275,18 @@ static void __init arch_reserve_crashkernel(void) > static void __init fdt_setup(void) > { > #ifdef CONFIG_OF_EARLY_FLATTREE > - void *fdt_pointer; > + void *fdt_pointer = NULL; > > /* ACPI-based systems do not require parsing fdt */ > if (acpi_os_get_root_pointer()) > return; > > +#ifdef CONFIG_BUILTIN_DTB > /* Prefer to use built-in dtb, checking its legality first. */ > if (!fdt_check_header(__dtb_start)) > fdt_pointer = __dtb_start; > - else > +#endif > + if (!fdt_pointer) > fdt_pointer = efi_fdt_pointer(); /* Fallback to firmware dtb */ Prefer to use non-ifdef logic: if (IS_ENABLED(CONFIG_BUILTIN_DTB) && !fdt_check_header(__dtb_start)) fdt_pointer = __dtb_start; This is shorter, easier to read and will prevent bitrot. The code will be typechecked but then optimized away, so no runtime overhead exists. > > if (!fdt_pointer || fdt_check_header(fdt_pointer)) > > -- > 2.43.0 >