mtd: physmap_of: Release resources on error
PATCH v8 1/10 mtd: physmap_of: Release resources on error
During probe, if there was an error the memory region and the memory map were not properly released.This can lead a system unusable if deferred probe is in use.
Replace mem_request and map with devm_ioremap_resource
Signed-off-by Ricardo Ribalda Delgado <[email protected]>
--- drivers/mtd/maps/physmap_of_core.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-)
drivers/mtd/maps/physmap_of_core.c +5 -22
@@ -31,7 +31,6 @@struct of_flash_list {struct mtd_info *mtd;struct map_info map; -struct resource *res; };struct of_flash {
@@ -56,18 +55,10 @@ static int of_flash_remove(struct platform_device *dev)mtd_concat_destroy (info->cmtd); } -for (i =0 ; i < info->list_size; i++) { +for (i =0 ; i < info->list_size; i++)if (info->list[i].mtd)map_destroy (info->list[i].mtd); -if (info->list[i].map.virt) -iounmap (info->list[i].map.virt); - -if (info->list[i].res) { -release_resource (info->list[i].res); -kfree (info->list[i].res); - } - }return 0 ; }
@@ -215,10 +206,11 @@ static int of_flash_probe(struct platform_device *dev) err = -EBUSY ; res_size =resource_size (&res); - info->list[i].res =request_mem_region (res.start, res_size, -dev_name (&dev->dev)); -if (!info->list[i].res) + info->list[i].map.virt =devm_ioremap_resource (&dev->dev, &res); +if (IS_ERR (info->list[i].map.virt)){ + err =PTR_ERR (info->list[i].map.virt); goto err_out; + } err = -ENXIO ; width =of_get_property (dp,"bank-width" ,NULL );
@@ -246,15 +238,6 @@ static int of_flash_probe(struct platform_device *dev)if (err) goto err_out; - err = -ENOMEM ; - info->list[i].map.virt =ioremap (info->list[i].map.phys, - info->list[i].map.size); -if (!info->list[i].map.virt) { -dev_err (&dev->dev,"Failed to ioremap() flash" -" region\n" ); - goto err_out; - } -simple_map_init (&info->list[i].map);/*
Signature · 1 line
2.19.0
PATCH v8 10/10 mtd: maps: gpio-addr-flash: Add support for device-tree devices
Allow creating gpio-addr-flash via device-tree and not just via platform data.
Mimic what physmap_of_versatile and physmap_of_gemini does to reduce code duplicity.
Signed-off-by Ricardo Ribalda Delgado <[email protected]>
--- drivers/mtd/maps/Kconfig | 8 +++ drivers/mtd/maps/Makefile | 3 +- drivers/mtd/maps/gpio-addr-flash.c | 91 ++++++++++++++++++------------ drivers/mtd/maps/gpio-addr-flash.h | 31 ++++++++++ drivers/mtd/maps/physmap_of_core.c | 5 ++ drivers/mtd/maps/physmap_of_gpio.c | 24 ++++++++ 6 files changed, 125 insertions(+), 37 deletions(-) create mode 100644 drivers/mtd/maps/gpio-addr-flash.h create mode 100644 drivers/mtd/maps/physmap_of_gpio.c
drivers/mtd/maps/Kconfig +8 -0
@@ -94,6 +94,14 @@ config MTD_PHYSMAP_OF_GEMINI platforms, some detection and setting up parallel mode on the external interface. +config MTD_PHYSMAP_OF_GPIO + bool "GPIO-assisted OF-based physical memory map handling" + depends on MTD_PHYSMAP_OF + depends on MTD_GPIO_ADDR + help + This provides some extra DT physmap parsing for flashes that are + partially physically addressed and assisted by GPIOs. + config MTD_PMC_MSP_EVM tristate "CFI Flash device mapped on PMC-Sierra MSP" depends on PMC_MSP && MTD_CFI
drivers/mtd/maps/Makefile +2 -1
@@ -21,6 +21,7 @@ obj-$(CONFIG_MTD_PHYSMAP) += physmap.o physmap_of-objs-y += physmap_of_core.o physmap_of-objs-$(CONFIG_MTD_PHYSMAP_OF_VERSATILE) += physmap_of_versatile.o physmap_of-objs-$(CONFIG_MTD_PHYSMAP_OF_GEMINI) += physmap_of_gemini.o +physmap_of-objs-$(CONFIG_MTD_PHYSMAP_OF_GPIO) += physmap_of_gpio.o physmap_of-objs := $(physmap_of-objs-y) obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of.o obj-$(CONFIG_MTD_PISMO) += pismo.o
@@ -44,6 +45,6 @@ obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o obj-$(CONFIG_MTD_VMU) += vmu-flash.o -obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o +obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o obj-$(CONFIG_MTD_LATCH_ADDR) += latch-addr-flash.o obj-$(CONFIG_MTD_LANTIQ) += lantiq-flash.o
drivers/mtd/maps/gpio-addr-flash.c +55 -36
143 lines not on this page · raw message
drivers/mtd/maps/gpio-addr-flash.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/of.h> +#include <linux/mtd/map.h> + +/** +* struct async_state - keep GPIO flash state +* @gpios: Struct containing the array of GPIO descriptors +* @gpio_values: cached GPIO values +* @win_order: dedicated memory size (if no GPIOs) +*/ +struct async_state { +struct gpio_descs *gpios; +unsigned int gpio_values; +unsigned int win_order; +}; + +int gpio_flash_probe_common (struct device *dev, +struct async_state *state, +struct map_info *map); + +#ifdef CONFIG_MTD_PHYSMAP_OF_GPIO +int of_flash_probe_gpio (struct platform_device *pdev,struct device_node *np, +struct map_info *map); +#else +static inline +int of_flash_probe_gpio (struct platform_device *pdev,struct device_node *np, +struct map_info *map) +{ +return 0 ; +} +#endif
drivers/mtd/maps/physmap_of_core.c +5 -0
@@ -27,6 +27,7 @@#include <linux/slab.h> #include "physmap_of_gemini.h" #include "physmap_of_versatile.h" +#include "gpio-addr-flash.h" struct of_flash_list {struct mtd_info *mtd;
@@ -240,6 +241,10 @@ static int of_flash_probe(struct platform_device *dev)simple_map_init (&info->list[i].map); + err =of_flash_probe_gpio (dev, dp, &info->list[i].map); +if (err) + goto err_out; +/* * On some platforms (e.g. MPC5200) a direct 1:1 mapping * may cause problems with JFFS2 usage, as the local bus (LPB)
drivers/mtd/maps/physmap_of_gpio.c new file +24 -0
@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 Qtechnology A/S +* +* Ricardo Ribalda <[email protected]> +* +*/ +#include <linux/platform_device.h> +#include "gpio-addr-flash.h" + +int of_flash_probe_gpio (struct platform_device *pdev,struct device_node *np, +struct map_info *map) +{ +struct async_state *state; + +if (!of_device_is_compatible (np,"mtd,gpio-addr-flash" )) +return 0 ; + + state =devm_kzalloc (&pdev->dev,sizeof (*state),GFP_KERNEL ); +if (!state) +return -ENOMEM ; + +return gpio_flash_probe_common (&pdev->dev, state, map); +}
Signature · 1 line
2.19.0