jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / flash / nand / core.c
index d1a776313e379ad33a6992ea3f698e1309649822..37e1d12e0314f07df487907c4524ca0cb16c6b23 100644 (file)
@@ -1,24 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *   Copyright (C) 2007 by Dominic Rath <Dominic.Rath@gmx.de>              *
  *   Copyright (C) 2002 Thomas Gleixner <tglx@linutronix.de>               *
  *   Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net>             *
  *                                                                         *
  *   Partially based on drivers/mtd/nand_ids.c from Linux.                 *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -182,7 +169,7 @@ static struct nand_device *get_nand_device_by_name(const char *name)
        unsigned found = 0;
 
        struct nand_device *nand;
-       for (nand = nand_devices; NULL != nand; nand = nand->next) {
+       for (nand = nand_devices; nand; nand = nand->next) {
                if (strcmp(nand->name, name) == 0)
                        return nand;
                if (!flash_driver_name_matches(nand->controller->name, name))
@@ -219,7 +206,7 @@ COMMAND_HELPER(nand_command_get_device, unsigned name_index,
        COMMAND_PARSE_NUMBER(uint, str, num);
        *nand = get_nand_device_by_num(num);
        if (!*nand) {
-               command_print(CMD_CTX, "NAND flash device '%s' not found", str);
+               command_print(CMD, "NAND flash device '%s' not found", str);
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
        return ERROR_OK;
@@ -265,6 +252,7 @@ int nand_read_status(struct nand_device *nand, uint8_t *status)
                return ERROR_NAND_DEVICE_NOT_PROBED;
 
        /* Send read status command */
+       /* FIXME: errors returned from nand->controller are mostly ignored! */
        nand->controller->command(nand, NAND_CMD_STATUS);
 
        alive_sleep(1);
@@ -303,7 +291,8 @@ static int nand_poll_ready(struct nand_device *nand, int timeout)
 int nand_probe(struct nand_device *nand)
 {
        uint8_t manufacturer_id, device_id;
-       uint8_t id_buff[6];
+       uint8_t id_buff[6] = { 0 };     /* zero buff to silence false warning
+                                        * from clang static analyzer */
        int retval;
        int i;
 
@@ -394,19 +383,34 @@ int nand_probe(struct nand_device *nand)
        if (nand->device->page_size == 0 ||
                        nand->device->erase_size == 0) {
                if (nand->bus_width == 8) {
-                       nand->controller->read_data(nand, id_buff + 3);
-                       nand->controller->read_data(nand, id_buff + 4);
-                       nand->controller->read_data(nand, id_buff + 5);
+                       retval = nand->controller->read_data(nand, id_buff + 3);
+                       if (retval != ERROR_OK)
+                               return retval;
+
+                       retval = nand->controller->read_data(nand, id_buff + 4);
+                       if (retval != ERROR_OK)
+                               return retval;
+
+                       retval = nand->controller->read_data(nand, id_buff + 5);
+                       if (retval != ERROR_OK)
+                               return retval;
+
                } else {
                        uint16_t data_buf;
 
-                       nand->controller->read_data(nand, &data_buf);
+                       retval = nand->controller->read_data(nand, &data_buf);
+                       if (retval != ERROR_OK)
+                               return retval;
                        id_buff[3] = data_buf;
 
-                       nand->controller->read_data(nand, &data_buf);
+                       retval = nand->controller->read_data(nand, &data_buf);
+                       if (retval != ERROR_OK)
+                               return retval;
                        id_buff[4] = data_buf;
 
-                       nand->controller->read_data(nand, &data_buf);
+                       retval = nand->controller->read_data(nand, &data_buf);
+                       if (retval != ERROR_OK)
+                               return retval;
                        id_buff[5] = data_buf >> 8;
                }
        }
@@ -667,7 +671,7 @@ int nand_write_page(struct nand_device *nand, uint32_t page,
        if (nand->blocks[block].is_erased == 1)
                nand->blocks[block].is_erased = 0;
 
-       if (nand->use_raw || nand->controller->write_page == NULL)
+       if (nand->use_raw || !nand->controller->write_page)
                return nand_write_page_raw(nand, page, data, data_size, oob, oob_size);
        else
                return nand->controller->write_page(nand, page, data, data_size, oob, oob_size);
@@ -680,7 +684,7 @@ int nand_read_page(struct nand_device *nand, uint32_t page,
        if (!nand->device)
                return ERROR_NAND_DEVICE_NOT_PROBED;
 
-       if (nand->use_raw || nand->controller->read_page == NULL)
+       if (nand->use_raw || !nand->controller->read_page)
                return nand_read_page_raw(nand, page, data, data_size, oob, oob_size);
        else
                return nand->controller->read_page(nand, page, data, data_size, oob, oob_size);
@@ -735,7 +739,7 @@ int nand_page_command(struct nand_device *nand, uint32_t page,
                        nand->controller->address(nand, (page >> 16) & 0xff);
 
                /* large page devices need a start command if reading */
-               if (NAND_CMD_READ0 == cmd)
+               if (cmd == NAND_CMD_READ0)
                        nand->controller->command(nand, NAND_CMD_READSTART);
        }
 
@@ -754,10 +758,10 @@ int nand_read_data_page(struct nand_device *nand, uint8_t *data, uint32_t size)
 {
        int retval = ERROR_NAND_NO_BUFFER;
 
-       if (nand->controller->read_block_data != NULL)
+       if (nand->controller->read_block_data)
                retval = (nand->controller->read_block_data)(nand, data, size);
 
-       if (ERROR_NAND_NO_BUFFER == retval) {
+       if (retval == ERROR_NAND_NO_BUFFER) {
                uint32_t i;
                int incr = (nand->device->options & NAND_BUSWIDTH_16) ? 2 : 1;
 
@@ -778,7 +782,7 @@ int nand_read_page_raw(struct nand_device *nand, uint32_t page,
        int retval;
 
        retval = nand_page_command(nand, page, NAND_CMD_READ0, !data);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        if (data)
@@ -794,10 +798,10 @@ int nand_write_data_page(struct nand_device *nand, uint8_t *data, uint32_t size)
 {
        int retval = ERROR_NAND_NO_BUFFER;
 
-       if (nand->controller->write_block_data != NULL)
+       if (nand->controller->write_block_data)
                retval = (nand->controller->write_block_data)(nand, data, size);
 
-       if (ERROR_NAND_NO_BUFFER == retval) {
+       if (retval == ERROR_NAND_NO_BUFFER) {
                bool is16bit = nand->device->options & NAND_BUSWIDTH_16;
                uint32_t incr = is16bit ? 2 : 1;
                uint16_t write_data;
@@ -810,7 +814,7 @@ int nand_write_data_page(struct nand_device *nand, uint8_t *data, uint32_t size)
                                write_data = *data;
 
                        retval = nand->controller->write_data(nand, write_data);
-                       if (ERROR_OK != retval)
+                       if (retval != ERROR_OK)
                                break;
 
                        data += incr;
@@ -834,7 +838,7 @@ int nand_write_finish(struct nand_device *nand)
                return ERROR_NAND_OPERATION_TIMEOUT;
 
        retval = nand_read_status(nand, &status);
-       if (ERROR_OK != retval) {
+       if (retval != ERROR_OK) {
                LOG_ERROR("couldn't read status");
                return ERROR_NAND_OPERATION_FAILED;
        }
@@ -855,12 +859,12 @@ int nand_write_page_raw(struct nand_device *nand, uint32_t page,
        int retval;
 
        retval = nand_page_command(nand, page, NAND_CMD_SEQIN, !data);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        if (data) {
                retval = nand_write_data_page(nand, data, data_size);
-               if (ERROR_OK != retval) {
+               if (retval != ERROR_OK) {
                        LOG_ERROR("Unable to write data to NAND device");
                        return retval;
                }
@@ -868,7 +872,7 @@ int nand_write_page_raw(struct nand_device *nand, uint32_t page,
 
        if (oob) {
                retval = nand_write_data_page(nand, oob, oob_size);
-               if (ERROR_OK != retval) {
+               if (retval != ERROR_OK) {
                        LOG_ERROR("Unable to write OOB data to NAND device");
                        return retval;
                }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)