From patchwork Tue Nov 27 20:09:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Goldschmidt X-Patchwork-Id: 1003993 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="dvg/R71U"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 434FJ804r3z9s0n for ; Wed, 28 Nov 2018 07:09:59 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id A576FC2215A; Tue, 27 Nov 2018 20:09:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id B776AC21EAE; Tue, 27 Nov 2018 20:09:51 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 89C51C21EAE; Tue, 27 Nov 2018 20:09:50 +0000 (UTC) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by lists.denx.de (Postfix) with ESMTPS id 364DFC21DD7 for ; Tue, 27 Nov 2018 20:09:50 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id 96so24049087wrb.2 for ; Tue, 27 Nov 2018 12:09:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=UBdnrovuuWf4Nb+zhYGR2e5OFqaekkm2zrczwZPDzn4=; b=dvg/R71UoLD16So4lQGKVn1fsK5h3axgozZNVPriuHMjd5LVtPp47dSK0Me+plR4u0 H2LbfZlGJPtHljR1GXlL4TFeh2kQzZ6aO8jBhm2EJFl5kd4K2S75uPpeNKrjTx6a+dnK rFsJvVGbBUEdtjiGu5/+2GiZC4bTgDL8PsRUVnQZ0L45UNCPT5cDUSKzveq2UXnHPHId cFC2HiClOq0u6C+huhCqVkTkiWQBhfb6vQiV1XVDZJb6qNymA6Ln2pzNlA7LM1/7vWcA cg7QdkCRCl4Do4qZFpHlZc3zQeNrvjYbPgwe54jwdpZitU2MabpbIAWf5W/Y5ZOwyhWP XtPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=UBdnrovuuWf4Nb+zhYGR2e5OFqaekkm2zrczwZPDzn4=; b=XrqU7qGUrSrFCujvTbnzaDB9dEg66aSv2ieS6MWgog8Ylhr/Bw/SUoLnIEJORCToRd okv1oNq85JXOOJS8bDl72p+H3rsHqid8GBDqMuheMz9UQjH845kJPiJdan/FsAmodBeM lgvdvZD8pEK2e5/N7c4BIetmyQKgnTZWUmLJfqyLvw2fi3avH5v3Wb1GikhbUz03XCpB 5K8A+KBFJAPB5Jw4msyfEjtQLJ4VceOyayao0U+fO4TyVSwd/psEUEm+u5BPRvBJe8jY AWv0qCGQGDAA/FCKnruvGlKWBfpRjCKNt+wQysQqmkPEDB3qOodD46vo/AJliXoxglEw p8yQ== X-Gm-Message-State: AA+aEWbi0zMfgoRqI6XJP0NbwExKRjBCFE0wBUzW6/GgydQkZWzLimiP IK/xHVQqiils8nOjlx3lSR4= X-Google-Smtp-Source: AFSGD/Vq6wY/mGEipEmVeFiraE8AhFJkZNbYM+HjAuVzT4WnWv9ersEJmAAaukiKVNi9d5pZQs7NNw== X-Received: by 2002:a5d:56d2:: with SMTP id m18mr30924496wrw.113.1543349389750; Tue, 27 Nov 2018 12:09:49 -0800 (PST) Received: from ubuntu.home ([2a02:8071:6a3:700:2cd5:fca:15fc:93d5]) by smtp.gmail.com with ESMTPSA id a1sm5921503wrw.76.2018.11.27.12.09.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 12:09:48 -0800 (PST) From: Simon Goldschmidt To: Jagan Teki Date: Tue, 27 Nov 2018 21:09:43 +0100 Message-Id: <20181127200943.955-1-simon.k.r.goldschmidt@gmail.com> X-Mailer: git-send-email 2.17.1 Cc: Tom Rini , u-boot@lists.denx.de Subject: [U-Boot] [PATCH] sf: prevent clean_bar overwriting error codes X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" In spi_flash.c, if CONFIG_SPI_FLASH_BAR is enabled, the function 'clean_bar' makes sure that the Bank Address Register is reset at the end of functions using it. However, if this is enabled, those functions may return zero (success) when they should return an error. This is because after e.g. 'spi_flash_read_common' fails, the return value in 'ret' is overwritten with the return value of 'clean_bar'. Fix this by changing 'clean_bar' to take the outer error code into account and returning its own return value only if the outer error code is 0. Signed-off-by: Simon Goldschmidt Reviewed-by: Simon Glass --- drivers/mtd/spi/spi_flash.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 0c2392f28a..b13b9f19b7 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -132,17 +132,26 @@ int spi_flash_cmd_get_sw_write_prot(struct spi_flash *flash) * * Otherwise, the BA24 bit may be left set and then after reset, the * ROM would read/write/erase SPL from 16 MiB * bank_sel address. + * + * Since this function is always called, it handles outer error codes + * to take care calling functions don't return 0 just because setting + * BAR succeeded. */ -static int clean_bar(struct spi_flash *flash) +static int clean_bar(struct spi_flash *flash, int outer_err) { + int ret; u8 cmd, bank_sel = 0; if (flash->bank_curr == 0) - return 0; + return outer_err; cmd = flash->bank_write_cmd; flash->bank_curr = 0; - return spi_flash_write_common(flash, &cmd, 1, &bank_sel, 1); + ret = spi_flash_write_common(flash, &cmd, 1, &bank_sel, 1); + if (outer_err) + return outer_err; + + return ret; } static int write_bar(struct spi_flash *flash, u32 offset) @@ -372,7 +381,7 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len) } #ifdef CONFIG_SPI_FLASH_BAR - ret = clean_bar(flash); + ret = clean_bar(flash, ret); #endif return ret; @@ -434,7 +443,7 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset, } #ifdef CONFIG_SPI_FLASH_BAR - ret = clean_bar(flash); + ret = clean_bar(flash, ret); #endif return ret; @@ -540,7 +549,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, } #ifdef CONFIG_SPI_FLASH_BAR - ret = clean_bar(flash); + ret = clean_bar(flash, ret); #endif return log_ret(ret);