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 diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
9 index 04356f1..2bba10c 100644
10 --- a/drivers/mtd/spi/sf_probe.c
11 +++ b/drivers/mtd/spi/sf_probe.c
12 @@ -153,11 +153,10 @@ static const struct spi_flash_params spi_flash_params_table[] = {
16 -static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
17 +static int spi_flash_validate_params(struct spi_flash *flash,
20 const struct spi_flash_params *params;
21 - struct spi_flash *flash;
23 u16 jedec = idcode[1] << 8 | idcode[2];
24 u16 ext_jedec = idcode[3] << 8 | idcode[4];
25 @@ -179,20 +178,12 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
26 debug("SF: Unsupported flash IDs: ");
27 debug("manuf %02x, jedec %04x, ext_jedec %04x\n",
28 idcode[0], jedec, ext_jedec);
32 - flash = malloc(sizeof(*flash));
34 - debug("SF: Failed to allocate spi_flash\n");
38 - memset(flash, '\0', sizeof(*flash));
42 flash->name = params->name;
43 - flash->memory_map = spi->memory_map;
44 + flash->memory_map = flash->spi->memory_map;
46 /* Assign spi_flash ops */
47 flash->write = spi_flash_cmd_write_ops;
48 @@ -239,7 +230,7 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
49 if (spi_flash_read_common(flash, &flash->bank_read_cmd, 1,
51 debug("SF: fail to read bank addr register\n");
55 flash->bank_curr = curr_bank;
57 @@ -254,7 +245,7 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
58 spi_flash_cmd_write_status(flash, 0);
65 #ifdef CONFIG_OF_CONTROL
66 @@ -289,15 +280,22 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
67 unsigned int max_hz, unsigned int spi_mode)
69 struct spi_slave *spi;
70 - struct spi_flash *flash = NULL;
71 + struct spi_flash *flash;
75 + flash = malloc(sizeof(*flash));
77 + debug("SF: Failed to allocate spi_flash\n");
80 + memset(flash, 0, sizeof(*flash));
83 spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
85 debug("SF: Failed to set up slave\n");
91 @@ -320,8 +318,9 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
94 /* Validate params from spi_flash_params table */
95 - flash = spi_flash_validate_params(spi, idcode);
98 + ret = spi_flash_validate_params(flash, idcode);
102 #ifdef CONFIG_OF_CONTROL
103 @@ -355,6 +354,9 @@ err_read_id:
104 spi_release_bus(spi);