Skip to contentSkip to conversation

firmware: samsung: fix stale response flag in acpm_prepare_xfer()

PATCH In review Titouan Ameline de Cadeville 3 participants 4 messages Apr 26 – Apr 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware: samsung: fix stale response flag in acpm_prepare_xfer()

acpm_prepare_xfer() only ever set rx_data->response to true, never false. A reused sequence number slot could therefore inherit a stale true from a previous transfer that expected a response, causing acpm_get_rx() to enter the response-copy path for a fire-and-forget transfer whose rxd is NULL.

Unconditionally assign the correct boolean value so the slot is fully reset on every reuse.

Fixes a88927b534ba ("firmware: add Exynos ACPM protocol driver")
---
 drivers/firmware/samsung/exynos-acpm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/firmware/samsung/exynos-acpm.c +1 -2
index 16c46ed60837..2fee6bb60efc 100644
@@ -380,8 +380,7 @@ static void acpm_prepare_xfer(struct acpm_chan *achan,
 	/* Clear data for upcoming responses */
 	rx_data = &achan->rx_data[achan->seqnum - 1];
 	memset(rx_data->cmd, 0, sizeof(*rx_data->cmd) * rx_data->n_cmd);
-	if (xfer->rxd)
-		rx_data->response = true;
+	rx_data->response = !!xfer->rxd;
 
 	/* Flag the index based on seqnum. (seqnum: 1~63, bitmap: 0~62) */
 	set_bit(achan->seqnum - 1, achan->bitmap_seqnum);
Signature · 1 line
2.44.2
maintainer
#1 lore raw

Hi,

Thanks for the patch!

Quoted 9 lines · Titouan Ameline de Cadeville

acpm_prepare_xfer() only ever set rx_data->response to true, never false. A reused sequence number slot could therefore inherit a stale true from a previous transfer that expected a response, causing acpm_get_rx() to enter the response-copy path for a fire-and-forget transfer whose rxd is NULL.

Unconditionally assign the correct boolean value so the slot is fully reset on every reuse.

How did you find this?

Sashiko identified this too when reviewing the ACPM thermal patches. I sent some fixes last week, where this bug is squashed as well:

https://lore.kernel.org/linux-samsung-soc/[email protected]/T/#m1c32aa4c84ea7e3909bc8fe7599585b71e95d8b5

Thanks!
ta

Quoted 20 lines
Fixes a88927b534ba ("firmware: add Exynos ACPM protocol driver")
---
 drivers/firmware/samsung/exynos-acpm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/firmware/samsung/exynos-acpm.c +1 -2
index 16c46ed60837..2fee6bb60efc 100644
@@ -380,8 +380,7 @@ static void acpm_prepare_xfer(struct acpm_chan *achan,
 	/* Clear data for upcoming responses */
 	rx_data = &achan->rx_data[achan->seqnum - 1];
 	memset(rx_data->cmd, 0, sizeof(*rx_data->cmd) * rx_data->n_cmd);
-	if (xfer->rxd)
-		rx_data->response = true;
+	rx_data->response = !!xfer->rxd;
 
 	/* Flag the index based on seqnum. (seqnum: 1~63, bitmap: 0~62) */
 	set_bit(achan->seqnum - 1, achan->bitmap_seqnum);
#2 lore raw

I was reading through the driver code and noticed that acpm_prepare_xfer() only enters the

if (xfer->rxd) branch to set response = true
with no corresponding else to reset it to false.

Since seqnum slots are recycled, I traced what happens when a slot previously used by a response-expecting transfer gets reused by a fire-and-forget one

-> the stale true remains and the wrong branch is taken in acpm_get_rx().

Quoted 48 lines · Tudor Ambarus

Hi,

Thanks for the patch!

Quoted 9 lines · Titouan Ameline de Cadeville

acpm_prepare_xfer() only ever set rx_data->response to true, never false. A reused sequence number slot could therefore inherit a stale true from a previous transfer that expected a response, causing acpm_get_rx() to enter the response-copy path for a fire-and-forget transfer whose rxd is NULL.

Unconditionally assign the correct boolean value so the slot is fully reset on every reuse.

How did you find this?

Sashiko identified this too when reviewing the ACPM thermal patches. I sent some fixes last week, where this bug is squashed as well:

https://lore.kernel.org/linux-samsung-soc/[email protected]/T/#m1c32aa4c84ea7e3909bc8fe7599585b71e95d8b5

Thanks!
ta

Quoted 20 lines
Fixes a88927b534ba ("firmware: add Exynos ACPM protocol driver")
---
 drivers/firmware/samsung/exynos-acpm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/firmware/samsung/exynos-acpm.c +1 -2
index 16c46ed60837..2fee6bb60efc 100644
@@ -380,8 +380,7 @@ static void acpm_prepare_xfer(struct acpm_chan *achan,
      /* Clear data for upcoming responses */
      rx_data = &achan->rx_data[achan->seqnum - 1];
      memset(rx_data->cmd, 0, sizeof(*rx_data->cmd) * rx_data->n_cmd);
-     if (xfer->rxd)
-             rx_data->response = true;
+     rx_data->response = !!xfer->rxd;
 
      /* Flag the index based on seqnum. (seqnum: 1~63, bitmap: 0~62) */
      set_bit(achan->seqnum - 1, achan->bitmap_seqnum);
#3 lore raw
Quoted 6 lines · Titouan Ameline

I was reading through the driver code and noticed that acpm_prepare_xfer() only enters the

if (xfer->rxd) branch to set response = true
with no corresponding else to reset it to false.

Quoted 8 lines

Since seqnum slots are recycled, I traced what happens when a slot previously used by a response-expecting transfer gets reused by a fire-and-forget one

-> the stale true remains and the wrong branch is taken in acpm_get_rx().

Quoted 1 line · Tudor Ambarus

This seams to duplicate Tudor's earlier patches and his solution looks more complete, so I will take his work with Reported-by credits.

Best regards,
Krzysztof