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 A7F0DC433EF for ; Tue, 5 Oct 2021 13:57:37 +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 11A5A61074 for ; Tue, 5 Oct 2021 13:57:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 11A5A61074 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.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 19323832A1; Tue, 5 Oct 2021 15:56:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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; unprotected) header.d=kernel.org header.i=@kernel.org header.b="YJ9C8GyE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 42B8683278; Tue, 5 Oct 2021 15:56:46 +0200 (CEST) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (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 75CFB82EA5 for ; Tue, 5 Oct 2021 15:56:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 8C7F161A10; Tue, 5 Oct 2021 13:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633442183; bh=7YeiqxDjlm9/NWhQAhQ5zlWpQQptFOGyJebCCHdmmng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YJ9C8GyEmwXHotj1i+fC1PSCcd452GEPydxMLy2v27vXQZ7rrz2LTBRStQqxXMF+h LPW0zIb1B2lj/5pdgun/eBoB0TQkzEHpv9cVEyrHe6SqrlGOoHCd0n5f7qSnBOMpF6 g4ZtmMvCPHkATLGQPjW57mtfG7hhS7uETTOrsAFQbVhdGSUpRaw+MQamw4iZp50JKT wtgUXirxwD0AOQanuSxCR1IrtLQKp4N/UFDs0BxmI9whAjatT6llj5MA8Ak//BPlMG LeT0YwQAD1r3SBsztGq9ndwiVg3LmodTExkDzOhCTd7Qqk8VFEaCiP/hNVis96BcNW pb5YcEfpt06JQ== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Jagan Teki , Tom Rini Cc: u-boot@lists.denx.de, Patrick Delaunay , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Patrice Chotard , Marek Vasut , Pratyush Yadav , =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH u-boot-spi v3 05/10] mtd: spi-flash: Check for zero length in legacy spi_flash_*() Date: Tue, 5 Oct 2021 15:56:01 +0200 Message-Id: <20211005135606.2246-6-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211005135606.2246-1-kabel@kernel.org> References: <20211005135606.2246-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 From: Marek BehĂșn Check for zero length in the legacy spi_flash_read() / spi_flash_write() / spi_flash_erase() functions. On zero length, return 0 immediately, don't call the underlying method. Rationale: - these legacy functions call the _read(), _write() and _erase() methods of struct mtd - the DM callers of these methods already check for zero length - making all callers of these methods check for zero length makes it possible to remove the check from implementations of these _read(), _write() and _erase() methods Signed-off-by: Marek BehĂșn --- include/spi_flash.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/spi_flash.h b/include/spi_flash.h index 3d747c925b..4d4ae89c19 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -165,6 +165,9 @@ static inline int spi_flash_read(struct spi_flash *flash, u32 offset, struct mtd_info *mtd = &flash->mtd; size_t retlen; + if (!len) + return 0; + return mtd->_read(mtd, offset, len, &retlen, buf); } @@ -174,6 +177,9 @@ static inline int spi_flash_write(struct spi_flash *flash, u32 offset, struct mtd_info *mtd = &flash->mtd; size_t retlen; + if (!len) + return 0; + return mtd->_write(mtd, offset, len, &retlen, buf); } @@ -188,6 +194,9 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset, return -EINVAL; } + if (!len) + return 0; + memset(&instr, 0, sizeof(instr)); instr.addr = offset; instr.len = len; -- 2.32.0