aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorBrian Norris <computersforpeace@gmail.com>2013-12-14 00:19:58 -0500
committerBrian Norris <computersforpeace@gmail.com>2014-01-07 13:07:34 -0500
commit103cdd8520b5ec85ab4345f54db5cc32a517f468 (patch)
tree989ce95429095a3a4ea6452b110a859d88b4b7f9 /drivers/mtd
parenta01eb2043b84bd6d595df58b7eba4f8841050b5e (diff)
mtd: nand-gpio: don't waste memory for OF failure
We shouldn't try to allocate a resource until we're sure the of_property_read_u64() call didn't fail. This is especially important if we use this code for both CONFIG_OF and !CONFIG_OF builds, since of_property_read_u64() will always return -ENOSYS for !CONFIG_OF. Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/nand/gpio.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/mtd/nand/gpio.c b/drivers/mtd/nand/gpio.c
index 8dfdbb63e096..8e6148aa4539 100644
--- a/drivers/mtd/nand/gpio.c
+++ b/drivers/mtd/nand/gpio.c
@@ -132,13 +132,17 @@ static int gpio_nand_get_config_of(const struct device *dev,
132 132
133static struct resource *gpio_nand_get_io_sync_of(struct platform_device *pdev) 133static struct resource *gpio_nand_get_io_sync_of(struct platform_device *pdev)
134{ 134{
135 struct resource *r = devm_kzalloc(&pdev->dev, sizeof(*r), GFP_KERNEL); 135 struct resource *r;
136 u64 addr; 136 u64 addr;
137 137
138 if (!r || of_property_read_u64(pdev->dev.of_node, 138 if (of_property_read_u64(pdev->dev.of_node,
139 "gpio-control-nand,io-sync-reg", &addr)) 139 "gpio-control-nand,io-sync-reg", &addr))
140 return NULL; 140 return NULL;
141 141
142 r = devm_kzalloc(&pdev->dev, sizeof(*r), GFP_KERNEL);
143 if (!r)
144 return NULL;
145
142 r->start = addr; 146 r->start = addr;
143 r->end = r->start + 0x3; 147 r->end = r->start + 0x3;
144 r->flags = IORESOURCE_MEM; 148 r->flags = IORESOURCE_MEM;