From d6b4359e50bb1dc567f6596c67b25a3c7a8ff130 Mon Sep 17 00:00:00 2001 From: Alexander Dahl Date: Fri, 22 Sep 2023 11:08:56 +0200 Subject: mtd: nand: raw: atmel: Add error handling when rb-gpios missing Adapt behaviour to Linux kernel driver. The return value of gpio_request_by_name_nodev() was not checked before, and thus in case 'rb-gpios' was missing in DT, rb.type was set to ATMEL_NAND_GPIO_RB nevertheless, leading to output like this for example (on sam9x60-curiosity with the line removed from dts): NAND: Could not find valid ONFI parameter page; aborting device found, Manufacturer ID: 0xc2, Chip ID: 0xdc Macronix NAND 512MiB 3,3V 8-bit 512 MiB, SLC, erase size: 256 KiB, page size: 4096, OOB size: 64 atmel-nand-controller nand-controller: NAND scan failed: -22 Failed to probe nand driver (err = -22) Failed to initialize NAND controller. (error -22) 0 MiB Note: not having that gpio assigned in dts is possible, the driver does not override nand_chip->dev_ready() then and a generic solution is used. Fixes: 6a8dfd57220d ("nand: atmel: Add DM based NAND driver") Signed-off-by: Alexander Dahl Reviewed-by: Eugen Hristev Acked-by: Michael Trimarchi --- drivers/mtd/nand/raw/atmel/nand-controller.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c index 9873d112544..950e626f918 100644 --- a/drivers/mtd/nand/raw/atmel/nand-controller.c +++ b/drivers/mtd/nand/raw/atmel/nand-controller.c @@ -1601,10 +1601,13 @@ static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, nand->cs[i].rb.type = ATMEL_NAND_NATIVE_RB; nand->cs[i].rb.id = val; } else { - gpio_request_by_name_nodev(np, "rb-gpios", 0, - &nand->cs[i].rb.gpio, - GPIOD_IS_IN); - nand->cs[i].rb.type = ATMEL_NAND_GPIO_RB; + ret = gpio_request_by_name_nodev(np, "rb-gpios", 0, + &nand->cs[i].rb.gpio, + GPIOD_IS_IN); + if (ret && ret != -ENOENT) + dev_err(nc->dev, "Failed to get R/B gpio (err = %d)\n", ret); + if (!ret) + nand->cs[i].rb.type = ATMEL_NAND_GPIO_RB; } gpio_request_by_name_nodev(np, "cs-gpios", 0, -- cgit v1.2.3 From 7b4ffe8c32db284e25d3a2636904def8e093da9e Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Sun, 24 Sep 2023 11:58:54 +0200 Subject: clk: at91: Fix initializing arrays Arrays are not cleared entirely because ARRAY_SIZE returns the number of elements in an array, not the size in bytes. This commit fixes the calls to memset by providing the array size in bytes instead of the number of elements in the array. Signed-off-by: Francois Berder --- drivers/clk/at91/sam9x60.c | 4 ++-- drivers/clk/at91/sama7g5.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/clk/at91/sam9x60.c b/drivers/clk/at91/sam9x60.c index e2f72446d50..d858c860f69 100644 --- a/drivers/clk/at91/sam9x60.c +++ b/drivers/clk/at91/sam9x60.c @@ -429,8 +429,8 @@ static int sam9x60_clk_probe(struct udevice *dev) if (!base) return -EINVAL; - memset(muxallocs, 0, ARRAY_SIZE(muxallocs)); - memset(clkmuxallocs, 0, ARRAY_SIZE(clkmuxallocs)); + memset(muxallocs, 0, sizeof(muxallocs)); + memset(clkmuxallocs, 0, sizeof(clkmuxallocs)); ret = clk_get_by_index(dev, 0, &clk); if (ret) diff --git a/drivers/clk/at91/sama7g5.c b/drivers/clk/at91/sama7g5.c index 3abd2208030..3e62fb1f58d 100644 --- a/drivers/clk/at91/sama7g5.c +++ b/drivers/clk/at91/sama7g5.c @@ -1115,8 +1115,8 @@ static int sama7g5_clk_probe(struct udevice *dev) if (IS_ERR(base)) return PTR_ERR(base); - memset(muxallocs, 0, ARRAY_SIZE(muxallocs)); - memset(clkmuxallocs, 0, ARRAY_SIZE(clkmuxallocs)); + memset(muxallocs, 0, sizeof(muxallocs)); + memset(clkmuxallocs, 0, sizeof(clkmuxallocs)); ret = clk_get_by_index(dev, 0, &clk); if (ret) -- cgit v1.2.3