From patchwork Fri Oct 18 08:30:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benedikt Spranger X-Patchwork-Id: 1998970 X-Patchwork-Delegate: eugen.hristev@microchip.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=SKRhAEO5; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=Ty7dhM4H; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XVHwK2gyqz1xw2 for ; Fri, 18 Oct 2024 19:30:57 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E3DB489254; Fri, 18 Oct 2024 10:30:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=linutronix.de header.i=@linutronix.de header.b="SKRhAEO5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ty7dhM4H"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C832289139; Fri, 18 Oct 2024 10:30:16 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C2C968917E for ; Fri, 18 Oct 2024 10:30:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=b.spranger@linutronix.de From: Benedikt Spranger DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1729240213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vXlIWlaN6pq3omPm91KlLaODADD8Ht90RZvPTK1/spk=; b=SKRhAEO5QiX9XKAEGovxLvKYt9o8zRzqfeH9nzF5rKcyo+RY3zhgnO3ch1cZlId+BKEGIa TcR8NACBHX1w1vBbS+OFfIaBGR1Xh3TTqJStBhxOzUzIn7MuurZ8IIAPnUiN6IXP2BnkDF CaoMLUYSpFdIWW3NPXdhzsyplWdk4083zw4PJ193M49W8HGSpg/ScL116biUQlsF23rjtS iYH6/JpNbjZhSoJQswDGS3tL/c4ppFmcAfXYtHjJ4cj4hWkgLeOhYHv39if7718aJWP6Gw H+llBUzqcTPdVUxGOG031NoyhRMit/MhUlkkujnncnGrAlrB+ZzdyHHYZXrrPw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1729240213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vXlIWlaN6pq3omPm91KlLaODADD8Ht90RZvPTK1/spk=; b=Ty7dhM4H/c7MirRvnSeImOuaMvEO/834n0yJdAQZG1l7KUTEezeSHRj0C8/7S96ICye0x8 bI9o/0+kI5sXx9Dw== To: u-boot@lists.denx.de Cc: John Ogness Subject: [PATCH 3/5] mtd: nand: raw: Fix potential NULL pointer dereference Date: Fri, 18 Oct 2024 10:30:04 +0200 Message-ID: <20241018083006.10349-5-b.spranger@linutronix.de> In-Reply-To: <20241018083006.10349-1-b.spranger@linutronix.de> References: <20241018083006.10349-1-b.spranger@linutronix.de> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean A NAND manufacture ID may not be found in nand_manuf_ids[] database. In case of an ONFI or JEDEC NAND a crutial NULL pointer check is missing and printing out the manufacture name result in a NULL pointer dereference. Instead of adding additional NULL pointer checks ensure a valid nand_menufacture_desc and remove the checks entirely. Signed-off-by: Benedikt Spranger Reviewed-by: John Ogness --- drivers/mtd/nand/raw/nand_base.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 4401bdcdb90..5dbc47bfe5f 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4241,7 +4241,7 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, * @id: manufacturer ID * * Returns a nand_manufacturer_desc object if the manufacturer is defined - * in the NAND manufacturers database, NULL otherwise. + * in the NAND manufacturers database, "Unknown" entry otherwise. */ static const struct nand_manufacturer *nand_get_manufacturer_desc(u8 id) { @@ -4252,7 +4252,7 @@ static const struct nand_manufacturer *nand_get_manufacturer_desc(u8 id) return &nand_manuf_ids[i]; } - return NULL; + return &nand_manuf_ids[i]; } /* @@ -4425,13 +4425,13 @@ ident_done: else if (chip->jedec_version) pr_info("%s %s\n", manufacturer_desc->name, chip->jedec_params.model); - else if (manufacturer_desc) + else pr_info("%s %s\n", manufacturer_desc->name, type->name); #else if (chip->jedec_version) pr_info("%s %s\n", manufacturer_desc->name, chip->jedec_params.model); - else if (manufacturer_desc) + else pr_info("%s %s\n", manufacturer_desc->name, type->name); #endif