From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CD1BD223DDF for ; Thu, 24 Apr 2025 23:39:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745537981; cv=none; b=P15Tn74dN38lGVdUQ9M7N4BtcqBV0jy573fV2UXAw5clhS2txPcHbwr57dF6eD4FqTSuE1bm42/O4kj/+gZNhtzTC+2JMy6xNKEZDrYK351xbzIjpnCwyXH1NGXiuKEZYza3upBjeWK2Q4Nn10uCCLNo3UnZKxQKjy/rHSnkVPY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745537981; c=relaxed/simple; bh=Ed4KLFH9HuHYkKJUWPeVRZ3OYFaVcVj2uHUgklVRMTc=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hn1WgaUM/6d7Dj+KXQixtSeO7+4wJunOlUAiLmKkc1FScqo1HEnDNgp3l148ZoEDkRVD4kM53FWr3H86ZQi32/cyoidP4IICSBY4CDl/oBp0IcfaXVOHdAJDbCSNZhk5y/uZ6F5vCNrcgxd3ZA2My1aqP/7A5+Xaln8mZhjwteA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CB4D9339; Thu, 24 Apr 2025 16:39:33 -0700 (PDT) Received: from minigeek.lan (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AD4C23F59E; Thu, 24 Apr 2025 16:39:37 -0700 (PDT) Date: Fri, 25 Apr 2025 00:38:36 +0100 From: Andre Przywara To: Chenyuan Yang Cc: wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, arnd@arndb.de, hdegoede@redhat.com, mripard@kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] drivers: soc: sunxi: Fix possible null pointer dereference Message-ID: <20250425003836.74f068da@minigeek.lan> In-Reply-To: <20250412165700.2298733-1-chenyuan0y@gmail.com> References: <20250412165700.2298733-1-chenyuan0y@gmail.com> Organization: Arm Ltd. X-Mailer: Claws Mail 4.2.0 (GTK 3.24.31; x86_64-slackware-linux-gnu) Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 12 Apr 2025 11:57:00 -0500 Chenyuan Yang wrote: > of_get_address() may return NULL which is later dereferenced. > Fix this bug by adding NULL check > > This is similar to the commit c534b63bede6 > ("drm: vc4: Fix possible null pointer dereference"). > > Signed-off-by: Chenyuan Yang > Fixes: 4af34b572a85 ("drivers: soc: sunxi: Introduce SoC driver to map SRAMs") That fix looks alright, indeed of_get_address() returns NULL if the slightest bit in the property is not as expected, and we should check for that. I am just wondering if we should issue a firmware warning in this case, instead of just silently skipping an entry. Cheers, Andre > --- > drivers/soc/sunxi/sunxi_sram.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/soc/sunxi/sunxi_sram.c b/drivers/soc/sunxi/sunxi_sram.c > index 2781a091a6a6..1853dcc806ea 100644 > --- a/drivers/soc/sunxi/sunxi_sram.c > +++ b/drivers/soc/sunxi/sunxi_sram.c > @@ -122,6 +122,8 @@ static int sunxi_sram_show(struct seq_file *s, void *data) > continue; > > sram_addr_p = of_get_address(sram_node, 0, NULL, NULL); > + if (!sram_addr_p) > + continue; > > seq_printf(s, "sram@%08x\n", > be32_to_cpu(*sram_addr_p)); > @@ -134,6 +136,8 @@ static int sunxi_sram_show(struct seq_file *s, void *data) > > section_addr_p = of_get_address(section_node, 0, > NULL, NULL); > + if (!section_addr_p) > + continue; > > seq_printf(s, "\tsection@%04x\t(%s)\n", > be32_to_cpu(*section_addr_p),