uboot-lantiq: update to v2013.10
[openwrt/svn-archive/archive.git] / package / boot / uboot-lantiq / patches / 0003-sf-move-malloc-of-spi_flash-to-spi_flash_probe.patch
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()
5
6 Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
7
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[] = {
13 */
14 };
15
16 -static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
17 +static int spi_flash_validate_params(struct spi_flash *flash,
18 u8 *idcode)
19 {
20 const struct spi_flash_params *params;
21 - struct spi_flash *flash;
22 int i;
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);
29 - return NULL;
30 - }
31 -
32 - flash = malloc(sizeof(*flash));
33 - if (!flash) {
34 - debug("SF: Failed to allocate spi_flash\n");
35 - return NULL;
36 + return -1;
37 }
38 - memset(flash, '\0', sizeof(*flash));
39
40 /* Assign spi data */
41 - flash->spi = spi;
42 flash->name = params->name;
43 - flash->memory_map = spi->memory_map;
44 + flash->memory_map = flash->spi->memory_map;
45
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,
50 &curr_bank, 1)) {
51 debug("SF: fail to read bank addr register\n");
52 - return NULL;
53 + return -1;
54 }
55 flash->bank_curr = curr_bank;
56 } else {
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);
59 #endif
60
61 - return flash;
62 + return 0;
63 }
64
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)
68 {
69 struct spi_slave *spi;
70 - struct spi_flash *flash = NULL;
71 + struct spi_flash *flash;
72 u8 idcode[5];
73 int ret;
74
75 + flash = malloc(sizeof(*flash));
76 + if (!flash) {
77 + debug("SF: Failed to allocate spi_flash\n");
78 + return NULL;
79 + }
80 + memset(flash, 0, sizeof(*flash));
81 +
82 /* Setup spi_slave */
83 spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
84 if (!spi) {
85 debug("SF: Failed to set up slave\n");
86 - return NULL;
87 + goto err_setup;
88 }
89
90 /* Claim spi bus */
91 @@ -320,8 +318,9 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
92 #endif
93
94 /* Validate params from spi_flash_params table */
95 - flash = spi_flash_validate_params(spi, idcode);
96 - if (!flash)
97 + flash->spi = spi;
98 + ret = spi_flash_validate_params(flash, idcode);
99 + if (ret)
100 goto err_read_id;
101
102 #ifdef CONFIG_OF_CONTROL
103 @@ -355,6 +354,9 @@ err_read_id:
104 spi_release_bus(spi);
105 err_claim_bus:
106 spi_free_slave(spi);
107 +err_setup:
108 + free(flash);
109 +
110 return NULL;
111 }
112
113 --
114 1.8.3.2
115