Merge pull request #580 from wigyori/cc-libpcap
[15.05/openwrt.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 --- 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
11          */
12  };
13  
14 -static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
15 +static int spi_flash_validate_params(struct spi_flash *flash,
16                 u8 *idcode)
17  {
18         const struct spi_flash_params *params;
19 -       struct spi_flash *flash;
20         int i;
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);
27 -               return NULL;
28 -       }
29 -
30 -       flash = malloc(sizeof(*flash));
31 -       if (!flash) {
32 -               debug("SF: Failed to allocate spi_flash\n");
33 -               return NULL;
34 +               return -1;
35         }
36 -       memset(flash, '\0', sizeof(*flash));
37  
38         /* Assign spi data */
39 -       flash->spi = spi;
40         flash->name = params->name;
41 -       flash->memory_map = spi->memory_map;
42 +       flash->memory_map = flash->spi->memory_map;
43  
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,
48                                           &curr_bank, 1)) {
49                         debug("SF: fail to read bank addr register\n");
50 -                       return NULL;
51 +                       return -1;
52                 }
53                 flash->bank_curr = curr_bank;
54         } else {
55 @@ -254,7 +245,7 @@ static struct spi_flash *spi_flash_valid
56                 spi_flash_cmd_write_status(flash, 0);
57  #endif
58  
59 -       return flash;
60 +       return 0;
61  }
62  
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)
66  {
67         struct spi_slave *spi;
68 -       struct spi_flash *flash = NULL;
69 +       struct spi_flash *flash;
70         u8 idcode[5];
71         int ret;
72  
73 +       flash = malloc(sizeof(*flash));
74 +       if (!flash) {
75 +               debug("SF: Failed to allocate spi_flash\n");
76 +               return NULL;
77 +       }
78 +       memset(flash, 0, sizeof(*flash));
79 +
80         /* Setup spi_slave */
81         spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
82         if (!spi) {
83                 debug("SF: Failed to set up slave\n");
84 -               return NULL;
85 +               goto err_setup;
86         }
87  
88         /* Claim spi bus */
89 @@ -320,8 +318,9 @@ struct spi_flash *spi_flash_probe(unsign
90  #endif
91  
92         /* Validate params from spi_flash_params table */
93 -       flash = spi_flash_validate_params(spi, idcode);
94 -       if (!flash)
95 +       flash->spi = spi;
96 +       ret = spi_flash_validate_params(flash, idcode);
97 +       if (ret)
98                 goto err_read_id;
99  
100  #ifdef CONFIG_OF_CONTROL
101 @@ -355,6 +354,9 @@ err_read_id:
102         spi_release_bus(spi);
103  err_claim_bus:
104         spi_free_slave(spi);
105 +err_setup:
106 +       free(flash);
107 +
108         return NULL;
109  }
110