Merge branch 'contrib/github_pr_18898' into 'master'

fix(spi_master): avoid NULL memcpy when DMA buffer setup fails (GitHub PR)

Closes IDFGH-18048

See merge request espressif/esp-idf!51277
This commit is contained in:
Wan Lei
2026-08-03 11:43:18 +08:00
3 changed files with 4 additions and 4 deletions

View File

@@ -1165,7 +1165,7 @@ static SPI_MASTER_ISR_ATTR void uninstall_priv_desc(spi_trans_priv_t* trans_buf)
// copy data from temporary DMA-capable buffer back to trans_desc buffer and free the temporary one.
void *orig_rx_buffer = (trans_desc->flags & SPI_TRANS_USE_RXDATA) ? trans_desc->rx_data : trans_desc->rx_buffer;
if (trans_buf->buffer_to_rcv != orig_rx_buffer) {
if (trans_buf->buffer_to_rcv && trans_buf->buffer_to_rcv != orig_rx_buffer) {
memcpy(orig_rx_buffer, trans_buf->buffer_to_rcv, (trans_desc->rxlength + 7) / 8);
free(trans_buf->buffer_to_rcv);
}

View File

@@ -413,7 +413,7 @@ static void SPI_SLAVE_ISR_ATTR spi_slave_uninstall_priv_trans(spi_host_device_t
if (trans->tx_buffer && (trans->tx_buffer != priv_trans->tx_buffer)) {
free(priv_trans->tx_buffer);
}
if (trans->rx_buffer && (trans->rx_buffer != priv_trans->rx_buffer)) {
if (priv_trans->rx_buffer && (trans->rx_buffer != priv_trans->rx_buffer)) {
size_t compatible_len = trans->rx_length ? trans->rx_length : trans->length;
memcpy(trans->rx_buffer, priv_trans->rx_buffer, (MIN(compatible_len, trans->trans_len) + 7) / 8);
free(priv_trans->rx_buffer);

View File

@@ -698,7 +698,7 @@ static SPI_SLAVE_ISR_ATTR void s_spi_slave_hd_append_legacy_isr(void *arg)
static void s_spi_slave_hd_destroy_priv_trans(spi_host_device_t host, spi_slave_hd_trans_priv_t *priv_trans, spi_slave_chan_t chan)
{
spi_slave_hd_data_t *orig_trans = priv_trans->trans;
if (priv_trans->aligned_buffer != orig_trans->data) {
if (priv_trans->aligned_buffer && priv_trans->aligned_buffer != orig_trans->data) {
if (chan == SPI_SLAVE_CHAN_RX) {
memcpy(orig_trans->data, priv_trans->aligned_buffer, orig_trans->trans_len);
}
@@ -792,7 +792,7 @@ esp_err_t s_spi_slave_hd_append_rxdma(spi_slave_hd_slot_t *host, uint8_t *data,
return ESP_ERR_INVALID_STATE;
}
spicommon_dma_desc_setup_link(hal->rx_cur_desc->desc, data, len, false);
spicommon_dma_desc_setup_link(hal->rx_cur_desc->desc, data, len, true);
hal->rx_cur_desc->arg = arg;
if (!hal->rx_used_desc_cnt) {