210-spi-fsl-espi-preallocate-local-buffer.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. From: Gabor Juhos <juhosg@openwrt.org>
  2. Subject: spi-fsl-espi: avoid frequent high order allocations
  3. The driver allocates 64KiB of memory fro a local buffer before
  4. each transfer and releases that afterwards. When the memory is
  5. fragmented this allocation often fails and causes a warning like
  6. this:
  7. kworker/u2:2: page allocation failure: order:4, mode:0x10c0d0
  8. CPU: 0 PID: 7011 Comm: kworker/u2:2 Not tainted 3.10.24 #1
  9. Workqueue: ffe07000.spi mpc8xxx_spi_work
  10. Call Trace:
  11. [c1c6dcf0] [c0006914] show_stack+0x50/0x170 (unreliable)
  12. [c1c6dd30] [c0259858] dump_stack+0x24/0x34
  13. [c1c6dd40] [c00672e8] warn_alloc_failed+0x120/0x13c
  14. [c1c6dd90] [c0069920] __alloc_pages_nodemask+0x574/0x5c8
  15. [c1c6de20] [c0069990] __get_free_pages+0x1c/0x4c
  16. [c1c6de30] [c0185174] fsl_espi_do_one_msg+0x128/0x2a0
  17. [c1c6de90] [c0184290] mpc8xxx_spi_work+0x50/0x7c
  18. [c1c6dea0] [c0037af8] process_one_work+0x208/0x30c
  19. [c1c6dec0] [c00387a0] worker_thread+0x20c/0x308
  20. [c1c6def0] [c003de60] kthread+0xa4/0xa8
  21. [c1c6df40] [c000c4bc] ret_from_kernel_thread+0x5c/0x64
  22. m25p80 spi0.0: error -12 reading SR
  23. end_request: I/O error, dev mtdblock3, sector 680
  24. SQUASHFS error: squashfs_read_data failed to read block 0x54a4a
  25. SQUASHFS error: Unable to read data cache entry [54a4a]
  26. Preallocate the buffer from the probe routine to avoid
  27. this.
  28. Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  29. ---
  30. drivers/spi/spi-fsl-espi.c | 34 ++++++++++++++++------------------
  31. drivers/spi/spi-fsl-lib.h | 1 +
  32. 2 files changed, 17 insertions(+), 18 deletions(-)
  33. --- a/drivers/spi/spi-fsl-espi.c
  34. +++ b/drivers/spi/spi-fsl-espi.c
  35. @@ -329,17 +329,13 @@ static void fsl_espi_do_trans(struct spi
  36. static void fsl_espi_cmd_trans(struct spi_message *m,
  37. struct fsl_espi_transfer *trans, u8 *rx_buff)
  38. {
  39. + struct spi_device *spi = m->spi;
  40. + struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master);
  41. struct spi_transfer *t;
  42. - u8 *local_buf;
  43. + u8 *local_buf = mspi->local_buf;
  44. int i = 0;
  45. struct fsl_espi_transfer *espi_trans = trans;
  46. - local_buf = kzalloc(SPCOM_TRANLEN_MAX, GFP_KERNEL);
  47. - if (!local_buf) {
  48. - espi_trans->status = -ENOMEM;
  49. - return;
  50. - }
  51. -
  52. list_for_each_entry(t, &m->transfers, transfer_list) {
  53. if (t->tx_buf) {
  54. memcpy(local_buf + i, t->tx_buf, t->len);
  55. @@ -352,28 +348,23 @@ static void fsl_espi_cmd_trans(struct sp
  56. fsl_espi_do_trans(m, espi_trans);
  57. espi_trans->actual_length = espi_trans->len;
  58. - kfree(local_buf);
  59. }
  60. static void fsl_espi_rw_trans(struct spi_message *m,
  61. struct fsl_espi_transfer *trans, u8 *rx_buff)
  62. {
  63. + struct spi_device *spi = m->spi;
  64. + struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master);
  65. struct fsl_espi_transfer *espi_trans = trans;
  66. unsigned int n_tx = espi_trans->n_tx;
  67. unsigned int n_rx = espi_trans->n_rx;
  68. struct spi_transfer *t;
  69. - u8 *local_buf;
  70. + u8 *local_buf = mspi->local_buf;
  71. u8 *rx_buf = rx_buff;
  72. unsigned int trans_len;
  73. unsigned int addr;
  74. int i, pos, loop;
  75. - local_buf = kzalloc(SPCOM_TRANLEN_MAX, GFP_KERNEL);
  76. - if (!local_buf) {
  77. - espi_trans->status = -ENOMEM;
  78. - return;
  79. - }
  80. -
  81. for (pos = 0, loop = 0; pos < n_rx; pos += trans_len, loop++) {
  82. trans_len = n_rx - pos;
  83. if (trans_len > SPCOM_TRANLEN_MAX - n_tx)
  84. @@ -407,8 +398,6 @@ static void fsl_espi_rw_trans(struct spi
  85. else
  86. espi_trans->actual_length += espi_trans->len;
  87. }
  88. -
  89. - kfree(local_buf);
  90. }
  91. static void fsl_espi_do_one_msg(struct spi_message *m)
  92. @@ -585,6 +574,7 @@ static irqreturn_t fsl_espi_irq(s32 irq,
  93. static void fsl_espi_remove(struct mpc8xxx_spi *mspi)
  94. {
  95. iounmap(mspi->reg_base);
  96. + kfree(mspi->local_buf);
  97. }
  98. static struct spi_master * fsl_espi_probe(struct device *dev,
  99. @@ -619,10 +609,16 @@ static struct spi_master * fsl_espi_prob
  100. mpc8xxx_spi->spi_do_one_msg = fsl_espi_do_one_msg;
  101. mpc8xxx_spi->spi_remove = fsl_espi_remove;
  102. + mpc8xxx_spi->local_buf = kzalloc(SPCOM_TRANLEN_MAX, GFP_KERNEL);
  103. + if (!mpc8xxx_spi->local_buf) {
  104. + ret = -ENOMEM;
  105. + goto err_probe;
  106. + }
  107. +
  108. mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem));
  109. if (!mpc8xxx_spi->reg_base) {
  110. ret = -ENOMEM;
  111. - goto err_probe;
  112. + goto free_buf;
  113. }
  114. reg_base = mpc8xxx_spi->reg_base;
  115. @@ -689,6 +685,8 @@ unreg_master:
  116. free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
  117. free_irq:
  118. iounmap(mpc8xxx_spi->reg_base);
  119. +free_buf:
  120. + kfree(mpc8xxx_spi->local_buf);
  121. err_probe:
  122. spi_master_put(master);
  123. err:
  124. --- a/drivers/spi/spi-fsl-lib.h
  125. +++ b/drivers/spi/spi-fsl-lib.h
  126. @@ -30,6 +30,7 @@ struct mpc8xxx_spi {
  127. void *rx;
  128. #ifdef CONFIG_SPI_FSL_ESPI
  129. int len;
  130. + u8 *local_buf;
  131. #endif
  132. int subblock;