Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83F02C433F5 for ; Tue, 14 Sep 2021 17:46:39 +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 D0D7760F4A for ; Tue, 14 Sep 2021 17:46:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D0D7760F4A Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com 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 7A12582999; Tue, 14 Sep 2021 19:46:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com 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=ti.com header.i=@ti.com header.b="oDc8gsMG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1B5A1828EB; Tue, 14 Sep 2021 19:46:33 +0200 (CEST) Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8D98082A15 for ; Tue, 14 Sep 2021 19:46:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=p.yadav@ti.com Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 18EHkQNO063593; Tue, 14 Sep 2021 12:46:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1631641586; bh=Bwbdwps5LREBthNJC145yMOb70unLFXn4dGA3ao5Ro0=; h=Date:From:To:CC:Subject:References:In-Reply-To; b=oDc8gsMGQSMCJyP79zPyyt9FwEV3P/qESEXV1PyU61EtOfI9o3mtnnIAIPFj1nP30 3E9Xdshgkpb6+mMse/Tl7LK+r3lihRWzGqxHR6QIee8GXReYKZx+Yghd6PRMCMncQ5 PoeN9vYe72vHVyt+xy0/tHwPm9SxmH32f3wPvrVw= Received: from DFLE114.ent.ti.com (dfle114.ent.ti.com [10.64.6.35]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 18EHkPEl072921 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Sep 2021 12:46:25 -0500 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Tue, 14 Sep 2021 12:46:25 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14 via Frontend Transport; Tue, 14 Sep 2021 12:46:25 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 18EHkOms056980; Tue, 14 Sep 2021 12:46:25 -0500 Date: Tue, 14 Sep 2021 23:16:24 +0530 From: Pratyush Yadav To: Marek Vasut CC: , Jagan Teki , Vignesh R Subject: Re: [PATCH] mtd: cqspi: Fix division by zero Message-ID: <20210914174622.mk4ytk5nitfcfzgz@ti.com> References: <20210914032148.273490-1-marex@denx.de> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20210914032148.273490-1-marex@denx.de> User-Agent: NeoMutt/20171215 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 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 On 14/09/21 05:21AM, Marek Vasut wrote: > Both dummy.nbytes and dummy.buswidth may be zero. By not checking > the later, it is possible to trigger division by zero and a crash. > This does happen with tiny SPI NOR framework in SPL. Fix this by > adding the check and returning zero dummy bytes in such a case. > > Fixes: 38b0852b0ea ("spi: cadence-qspi: Add support for octal DTR flashes") > Signed-off-by: Marek Vasut > Cc: Jagan Teki > Cc: Vignesh R > Cc: Pratyush Yadav > --- > drivers/spi/cadence_qspi_apb.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/spi/cadence_qspi_apb.c b/drivers/spi/cadence_qspi_apb.c > index c36a652211a..429ee335db6 100644 > --- a/drivers/spi/cadence_qspi_apb.c > +++ b/drivers/spi/cadence_qspi_apb.c > @@ -219,6 +219,9 @@ static unsigned int cadence_qspi_calc_dummy(const struct spi_mem_op *op, > { > unsigned int dummy_clk; > > + if (!op->dummy.nbytes || !op->dummy.buswidth) > + return 0; Thanks. A similar fix was sent for Linux as well [0]. I don't think you should check for dummy buswidth here since nbytes == 0 should be enough of an indicator that the dummy phase does not exist. Any op with dummy.nbytes > 1 and dummy.buswidth == 0 is a malformed op that should ideally never happen, or if it does, then it should be dealt by the SPI MEM core. With this fixed, Reviewed-by: Pratyush Yadav [0] https://patchwork.kernel.org/project/spi-devel-general/patch/92eea403-9b21-2488-9cc1-664bee760c5e@nskint.co.jp/ > + > dummy_clk = op->dummy.nbytes * (8 / op->dummy.buswidth); > if (dtr) > dummy_clk /= 2; > -- > 2.33.0 > -- Regards, Pratyush Yadav Texas Instruments Inc.