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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2556DC77B7C for ; Thu, 4 May 2023 22:52:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 541E585CF4; Fri, 5 May 2023 00:51:28 +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="QmbvE3gq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0F22485B31; Fri, 5 May 2023 00:51:23 +0200 (CEST) Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) (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 15004859FF for ; Fri, 5 May 2023 00:51:19 +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-io1-xd2f.google.com with SMTP id ca18e2360f4ac-763c343b716so24113539f.1 for ; Thu, 04 May 2023 15:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1683240677; x=1685832677; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wdl2PHIn/Ow4uVqalNRwFV8r6Md4YI7QqR4HjhPUke8=; b=QmbvE3gqa9pXkI6nBX3797/mOnjj2Ae/i6ecyUvWvCciPz6pmjR7GLiCsK/dGIdOgu GSsvbW0HJlsOqwSOWJji+51pyjvZCWI7ruCdTOTiRJ1eZRTVHkqCFHjCinb28Mij+a7M wMd5S66tqNi/RPglCyOcT21ft6yOJlPlffMaM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683240677; x=1685832677; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wdl2PHIn/Ow4uVqalNRwFV8r6Md4YI7QqR4HjhPUke8=; b=GdUKHMLbRnCXYP9rJx4+8kkcRRE36jnmBT6xSjpFojxeRYMpsab800LhR1p80r+rcp jfjqdA1q9EuLMTq6qsCYxjwxHeYiJB5EQN4JeLeMXbMtZu3e3Doh9Bliio/yWnE9B6UB AGZQ2o9J9B/wYN4bXEZOeF/Po4rP8CU0Gu9ZT4CT6AD900+yMbMAHCiwrDzBs3292/+6 peQG/qgENOePjV2jTHXgiDB2Gkbez7122LusS/VlXcvWUsQGKHxnu58ovBbsWuwsknQm /6PB+KyMGooINbHXvfTzzgIm/8xp5n59x6o7DMSyYxzuO68NSq6fFRKUwJmcNBQ/5nMB E5lw== X-Gm-Message-State: AC+VfDy5xAVEyt9cmuY6gmE0hIL+K7g1aeBmT4Hw3ybKGKFpYku1r7sf Q0XNkgZDtO8K6+awts9bkgYZVXbjo7TINOWUoI4= X-Google-Smtp-Source: ACHHUZ6lonXvUzvGG1WxF8fNOVQrEuVpiqgiOKdjOa5IRLRoMVk8r0gMPtQ4YTwDbdzVMj1lpY5Xpw== X-Received: by 2002:a92:dac3:0:b0:32b:2146:f0a4 with SMTP id o3-20020a92dac3000000b0032b2146f0a4mr282224ilq.20.1683240677689; Thu, 04 May 2023 15:51:17 -0700 (PDT) Received: from kea.bld.corp.google.com ([2620:15c:183:200:b5a:9fa0:3da:54ec]) by smtp.gmail.com with ESMTPSA id a26-20020a02735a000000b00414559b3ae8sm166458jae.103.2023.05.04.15.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 15:51:17 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Mike Frysinger Subject: [PATCH v3 03/17] sf: Guard against zero erasesize Date: Thu, 4 May 2023 16:50:47 -0600 Message-ID: <20230504225101.2366414-4-sjg@chromium.org> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog In-Reply-To: <20230504225101.2366414-1-sjg@chromium.org> References: <20230504225101.2366414-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 With tiny SPI flash the erasesize is 0 which can cause a divide-by-zero error. Check for this and return a proper error instead. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- Changes in v3: - Fix 'returns' typo drivers/mtd/spi/sf_probe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index e192f97efdc..de6516f1065 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -189,7 +189,8 @@ static int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len) struct mtd_info *mtd = &flash->mtd; struct erase_info instr; - if (offset % mtd->erasesize || len % mtd->erasesize) { + if (!mtd->erasesize || + (offset % mtd->erasesize || len % mtd->erasesize)) { debug("SF: Erase offset/length not multiple of erase size\n"); return -EINVAL; } -- 2.40.1.521.gf1e218fcd8-goog