0003-sf-move-malloc-of-spi_flash-to-spi_flash_probe.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. From 36b7400465fe2339f1c78274b3fd258ade3a4c00 Mon Sep 17 00:00:00 2001
  2. From: Daniel Schwierzeck <[email protected]>
  3. Date: Sat, 12 Oct 2013 21:30:07 +0200
  4. Subject: sf: move malloc of spi_flash to spi_flash_probe()
  5. Signed-off-by: Daniel Schwierzeck <[email protected]>
  6. diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
  7. index 04356f1..2bba10c 100644
  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_flash_params_table[] = {
  11. */
  12. };
  13. -static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
  14. +static int spi_flash_validate_params(struct spi_flash *flash,
  15. u8 *idcode)
  16. {
  17. const struct spi_flash_params *params;
  18. - struct spi_flash *flash;
  19. int i;
  20. u16 jedec = idcode[1] << 8 | idcode[2];
  21. u16 ext_jedec = idcode[3] << 8 | idcode[4];
  22. @@ -179,20 +178,12 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
  23. debug("SF: Unsupported flash IDs: ");
  24. debug("manuf %02x, jedec %04x, ext_jedec %04x\n",
  25. idcode[0], jedec, ext_jedec);
  26. - return NULL;
  27. - }
  28. -
  29. - flash = malloc(sizeof(*flash));
  30. - if (!flash) {
  31. - debug("SF: Failed to allocate spi_flash\n");
  32. - return NULL;
  33. + return -1;
  34. }
  35. - memset(flash, '\0', sizeof(*flash));
  36. /* Assign spi data */
  37. - flash->spi = spi;
  38. flash->name = params->name;
  39. - flash->memory_map = spi->memory_map;
  40. + flash->memory_map = flash->spi->memory_map;
  41. /* Assign spi_flash ops */
  42. flash->write = spi_flash_cmd_write_ops;
  43. @@ -239,7 +230,7 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
  44. if (spi_flash_read_common(flash, &flash->bank_read_cmd, 1,
  45. &curr_bank, 1)) {
  46. debug("SF: fail to read bank addr register\n");
  47. - return NULL;
  48. + return -1;
  49. }
  50. flash->bank_curr = curr_bank;
  51. } else {
  52. @@ -254,7 +245,7 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
  53. spi_flash_cmd_write_status(flash, 0);
  54. #endif
  55. - return flash;
  56. + return 0;
  57. }
  58. #ifdef CONFIG_OF_CONTROL
  59. @@ -289,15 +280,22 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
  60. unsigned int max_hz, unsigned int spi_mode)
  61. {
  62. struct spi_slave *spi;
  63. - struct spi_flash *flash = NULL;
  64. + struct spi_flash *flash;
  65. u8 idcode[5];
  66. int ret;
  67. + flash = malloc(sizeof(*flash));
  68. + if (!flash) {
  69. + debug("SF: Failed to allocate spi_flash\n");
  70. + return NULL;
  71. + }
  72. + memset(flash, 0, sizeof(*flash));
  73. +
  74. /* Setup spi_slave */
  75. spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
  76. if (!spi) {
  77. debug("SF: Failed to set up slave\n");
  78. - return NULL;
  79. + goto err_setup;
  80. }
  81. /* Claim spi bus */
  82. @@ -320,8 +318,9 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
  83. #endif
  84. /* Validate params from spi_flash_params table */
  85. - flash = spi_flash_validate_params(spi, idcode);
  86. - if (!flash)
  87. + flash->spi = spi;
  88. + ret = spi_flash_validate_params(flash, idcode);
  89. + if (ret)
  90. goto err_read_id;
  91. #ifdef CONFIG_OF_CONTROL
  92. @@ -355,6 +354,9 @@ err_read_id:
  93. spi_release_bus(spi);
  94. err_claim_bus:
  95. spi_free_slave(spi);
  96. +err_setup:
  97. + free(flash);
  98. +
  99. return NULL;
  100. }
  101. --
  102. 1.8.3.2