1 From 36b7400465fe2339f1c78274b3fd258ade3a4c00 Mon Sep 17 00:00:00 2001
2 From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
3 Date: Sat, 12 Oct 2013 21:30:07 +0200
4 Subject: sf: move malloc of spi_flash to spi_flash_probe()
6 Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
8 --- a/drivers/mtd/spi/sf_probe.c
9 +++ b/drivers/mtd/spi/sf_probe.c
10 @@ -153,11 +153,10 @@ static const struct spi_flash_params spi
14 -static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
15 +static int spi_flash_validate_params(struct spi_flash *flash,
18 const struct spi_flash_params *params;
19 - struct spi_flash *flash;
21 u16 jedec = idcode[1] << 8 | idcode[2];
22 u16 ext_jedec = idcode[3] << 8 | idcode[4];
23 @@ -179,20 +178,12 @@ static struct spi_flash *spi_flash_valid
24 debug("SF: Unsupported flash IDs: ");
25 debug("manuf %02x, jedec %04x, ext_jedec %04x\n",
26 idcode[0], jedec, ext_jedec);
30 - flash = malloc(sizeof(*flash));
32 - debug("SF: Failed to allocate spi_flash\n");
36 - memset(flash, '\0', sizeof(*flash));
40 flash->name = params->name;
41 - flash->memory_map = spi->memory_map;
42 + flash->memory_map = flash->spi->memory_map;
44 /* Assign spi_flash ops */
45 flash->write = spi_flash_cmd_write_ops;
46 @@ -239,7 +230,7 @@ static struct spi_flash *spi_flash_valid
47 if (spi_flash_read_common(flash, &flash->bank_read_cmd, 1,
49 debug("SF: fail to read bank addr register\n");
53 flash->bank_curr = curr_bank;
55 @@ -254,7 +245,7 @@ static struct spi_flash *spi_flash_valid
56 spi_flash_cmd_write_status(flash, 0);
63 #ifdef CONFIG_OF_CONTROL
64 @@ -289,15 +280,22 @@ struct spi_flash *spi_flash_probe(unsign
65 unsigned int max_hz, unsigned int spi_mode)
67 struct spi_slave *spi;
68 - struct spi_flash *flash = NULL;
69 + struct spi_flash *flash;
73 + flash = malloc(sizeof(*flash));
75 + debug("SF: Failed to allocate spi_flash\n");
78 + memset(flash, 0, sizeof(*flash));
81 spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
83 debug("SF: Failed to set up slave\n");
89 @@ -320,8 +318,9 @@ struct spi_flash *spi_flash_probe(unsign
92 /* Validate params from spi_flash_params table */
93 - flash = spi_flash_validate_params(spi, idcode);
96 + ret = spi_flash_validate_params(flash, idcode);
100 #ifdef CONFIG_OF_CONTROL
101 @@ -355,6 +354,9 @@ err_read_id:
102 spi_release_bus(spi);