From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6A35C433F5 for ; Sat, 23 Oct 2021 23:28:31 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 48B3A60F22 for ; Sat, 23 Oct 2021 23:28:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 48B3A60F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CF2B183587; Sun, 24 Oct 2021 01:27:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dzhgHsnF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 59939833D8; Sun, 24 Oct 2021 01:27:06 +0200 (CEST) Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 49BEA831B2 for ; Sun, 24 Oct 2021 01:26:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oo1-xc31.google.com with SMTP id 64-20020a4a0d43000000b002b866fa13eeso658694oob.2 for ; Sat, 23 Oct 2021 16:26:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sqpWcLq+bM5KuMc1fV9eMYrJvtJ6gPu7JK+2fPpxhh0=; b=dzhgHsnFZ4lOihxD4lBoWsC+xwH7OGAQ3CfBf/uOMiBwCpq8IAfY5vshG6All4taUL de5xLj2y6zis6qhDGaEt+75pWyl32Q6UQbLR7qxsTBl5LfMedaMLOO2l5J+u2hnXtU3K SgIh3IaHpNe0/AlZlws/0UIvRmDrKCc7rO8dM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sqpWcLq+bM5KuMc1fV9eMYrJvtJ6gPu7JK+2fPpxhh0=; b=7JeXyU6rTamhBGH6c3vwu0sMInKc/DL9nYSjlXGuAwZD/SpEXXplQSgFWwKaqm3cLW /3LfuMsZOhW3s/+/Q2+77wJsjxOgNJo/SdeWbyqGW/xfiXd3hyrn/C7PtjT4k9zpDA4+ IVtb2vLVdl5XTyXp6aVlHhONGB2WCJ8W4mBb0vkFMfSOwc82eqBUU+hYv3tMGDErU2Zg 0nEdo1IWj7lm4yi1Xm0IJYXWgKda5pMlUG7+NV3lp/R79vaTB+u3oIz3zV6+yzMuyKl8 DT4sCBd6n2OzxlJgLbe4AW/XVe+xa1mzwk5Vj6gefblQGj/fSF6z00RgrDT98Xb+KqLR +6cg== X-Gm-Message-State: AOAM5319o9wHol9Akz8hSmBkoKJT7FWdDxWhF+SBMekPjVI1kfyleFCg 9noaMXnoAjydFZNizB0LELphGZ8CpEA= X-Google-Smtp-Source: ABdhPJzGW9CohiR5HzD1sw0MA8c8ehBuPKdxdKTSOX+i5I9cohWWVJHV91EHfCOWd5kGjehrqyOhSg== X-Received: by 2002:a4a:a68b:: with SMTP id f11mr6323646oom.16.1635031612587; Sat, 23 Oct 2021 16:26:52 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id l24sm2253885oop.4.2021.10.23.16.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Oct 2021 16:26:52 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Michal Simek , Heinrich Schuchardt , Tom Rini , Ilias Apalodimas , Daniel Schwierzeck , Steffen Jaeckel , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Lukas Auer , Dennis Gilmore , Simon Glass Subject: [PATCH v2 08/41] disk: part_dos: Fix a NULL pointer error Date: Sat, 23 Oct 2021 17:26:02 -0600 Message-Id: <20211023232635.9195-7-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog In-Reply-To: <20211023232635.9195-1-sjg@chromium.org> References: <20211023232635.9195-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean When ext is NULL we cannot dereference it. Update the code flow to avoid this, so that layout_mbr_partitions() can be used with partition tables that do not include an extended partition. Signed-off-by: Simon Glass --- (no changes since v1) disk/part_dos.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/disk/part_dos.c b/disk/part_dos.c index 9e29aa6583a..94fae7166d7 100644 --- a/disk/part_dos.c +++ b/disk/part_dos.c @@ -459,10 +459,12 @@ int layout_mbr_partitions(struct disk_partition *p, int count, ext = &p[i]; } - if (i >= 4 && !ext) { - printf("%s: extended partition is needed for more than 4 partitions\n", - __func__); - return -1; + if (count < 4) + return 0; + + if (!ext) { + log_err("extended partition is needed for more than 4 partitions\n"); + return -EINVAL; } /* calculate extended volumes start and size if needed */ -- 2.33.0.1079.g6e70778dc9-goog