Skip to contentSkip to conversation

platform/chrome: cros_ec_uart: fix race condition

PATCH Applied Tzung-Bi Shih 4 participants 7 messages Dec 29, 2022 – Jan 3, 2023

Subsystems (3)
lore
Share & tools
lore

Tzung-Bi Shih

author maintainer
#0 lore raw

PATCH 1/1 platform/chrome: cros_ec_uart: fix race condition

From: Robert Zieba <[email protected]>

serdev_device_set_client_ops() is called before ec_dev is fully initialized. This can result in cros_ec_uart_rx_bytes() being called while ec_dev is still not initialized, resulting in a kernel panic.

Call serdev_device_set_client_ops() after ec_dev is initialized.

Fixes 04a8bdd135cc ("platform/chrome: cros_ec_uart: Add transport layer")
[tzungbi: modified commit message and fixed context conflict.]

---
This is from https://crrev.com/c/3490635. I just found the patch when reviewing some downstream patches.

 drivers/platform/chrome/cros_ec_uart.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_uart.c +2 -1
index 0cef2888dffd..6916069f1599 100644
@@ -270,7 +270,6 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
 	}
 
 	serdev_device_set_drvdata(serdev, ec_dev);
-	serdev_device_set_client_ops(serdev, &cros_ec_uart_client_ops);
 	init_waitqueue_head(&ec_uart->response.wait_queue);
 
 	ec_uart->serdev = serdev;
@@ -300,6 +299,8 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
 			   sizeof(struct ec_response_get_protocol_info);
 	ec_dev->dout_size = sizeof(struct ec_host_request);
 
+	serdev_device_set_client_ops(serdev, &cros_ec_uart_client_ops);
+
 	return cros_ec_register(ec_dev);
 }
 
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
#1 lore raw
Quoted 13 lines
drivers/platform/chrome/cros_ec_uart.c +0 -1
index 0cef2888dffd..6916069f1599 100644
@@ -270,7 +270,6 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
        }
 
        serdev_device_set_drvdata(serdev, ec_dev);
-       serdev_device_set_client_ops(serdev, &cros_ec_uart_client_ops);
        init_waitqueue_head(&ec_uart->response.wait_queue);
 
        ec_uart->serdev = serdev;

drivers/platform/chrome/cros_ec_uart.c static int cros_ec_uart_probe(struct serdev_device *serdev) · line 305

Quoted 7 lines
drivers/platform/chrome/cros_ec_uart.c +2 -0
@@ -300,6 +299,8 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
                           sizeof(struct ec_response_get_protocol_info);
        ec_dev->dout_size = sizeof(struct ec_host_request);
 
+       serdev_device_set_client_ops(serdev, &cros_ec_uart_client_ops);
+
        return cros_ec_register(ec_dev);
 }

Thanks for catching this. As a sanity check, I compiled and loaded the driver on my local setup with these changes. LGTM.

#2 lore raw

Hi Mark,

Quoted 17 lines · Mark Hasemeyer
Quoted 17 lines
drivers/platform/chrome/cros_ec_uart.c +0 -1
index 0cef2888dffd..6916069f1599 100644
@@ -270,7 +270,6 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
        }
 
        serdev_device_set_drvdata(serdev, ec_dev);
-       serdev_device_set_client_ops(serdev, &cros_ec_uart_client_ops);
        init_waitqueue_head(&ec_uart->response.wait_queue);
 
        ec_uart->serdev = serdev;
@@ -300,6 +299,8 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
                           sizeof(struct ec_response_get_protocol_info);
        ec_dev->dout_size = sizeof(struct ec_host_request);
 
Quoted 6 lines

drivers/platform/chrome/cros_ec_uart.c static int cros_ec_uart_probe(struct serdev_device *serdev) · line 305

Quoted 4 lines
drivers/platform/chrome/cros_ec_uart.c +2 -0
+       serdev_device_set_client_ops(serdev, &cros_ec_uart_client_ops);
+
        return cros_ec_register(ec_dev);
 }

Thanks for catching this. As a sanity check, I compiled and loaded the driver on my local setup with these changes. LGTM.

Please consider replying with a Reviewed-by: and/or Tested-by: tag.

Thanks,
Guenter

Tested-by
#3 lore raw
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/platform/chrome/cros_ec_uart.c +0 -1
index 0cef2888dffd..6916069f1599 100644
@@ -270,7 +270,6 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
        }
 
        serdev_device_set_drvdata(serdev, ec_dev);
-       serdev_device_set_client_ops(serdev, &cros_ec_uart_client_ops);
        init_waitqueue_head(&ec_uart->response.wait_queue);
 
        ec_uart->serdev = serdev;
@@ -300,6 +299,8 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
                           sizeof(struct ec_response_get_protocol_info);
        ec_dev->dout_size = sizeof(struct ec_host_request);
 
Quoted 9 lines
Quoted 6 lines

drivers/platform/chrome/cros_ec_uart.c static int cros_ec_uart_probe(struct serdev_device *serdev) · line 305

Quoted 4 lines
drivers/platform/chrome/cros_ec_uart.c +2 -0
+       serdev_device_set_client_ops(serdev, &cros_ec_uart_client_ops);
+
        return cros_ec_register(ec_dev);
 }

Thanks for catching this. As a sanity check, I compiled and loaded the driver on my local setup with these changes. LGTM.

Please consider replying with a Reviewed-by: and/or Tested-by: tag.

FWIW -

Reviewed-by on v1 1/1
#4 lore raw
In reply to Tzung-Bi Shih
Quoted 7 lines · Tzung-Bi Shih

From: Robert Zieba <[email protected]>

serdev_device_set_client_ops() is called before ec_dev is fully initialized. This can result in cros_ec_uart_rx_bytes() being called while ec_dev is still not initialized, resulting in a kernel panic.

Quoted 6 lines

Call serdev_device_set_client_ops() after ec_dev is initialized.

Fixes 04a8bdd135cc ("platform/chrome: cros_ec_uart: Add transport layer")
[tzungbi: modified commit message and fixed context conflict.]
Quoted 31 lines

---
This is from https://crrev.com/c/3490635. I just found the patch when reviewing some downstream patches.

 drivers/platform/chrome/cros_ec_uart.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_uart.c +2 -2
index 0cef2888dffd..6916069f1599 100644
@@ -270,7 +270,6 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
        }
 
        serdev_device_set_drvdata(serdev, ec_dev);
-       serdev_device_set_client_ops(serdev, &cros_ec_uart_client_ops);
        init_waitqueue_head(&ec_uart->response.wait_queue);
 
        ec_uart->serdev = serdev;
@@ -300,6 +299,8 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
                           sizeof(struct ec_response_get_protocol_info);
        ec_dev->dout_size = sizeof(struct ec_host_request);
 
+       serdev_device_set_client_ops(serdev, &cros_ec_uart_client_ops);
+
        return cros_ec_register(ec_dev);
 }
 
--

2.39.0.314.g84b9a713c41-goog

#5 lore raw
In reply to Tzung-Bi Shih
This patch was applied to chrome-platform/linux.git (for-kernelci) by Tzung-Bi Shih <[email protected]>:

Hello:

This patch was applied to chrome-platform/linux.git (for-kernelci) by Tzung-Bi Shih <[email protected]>:

Quoted 9 lines · On Thu, 29 Dec 2022 17:47:38 +0800 you wrote:

From: Robert Zieba <[email protected]>

serdev_device_set_client_ops() is called before ec_dev is fully initialized. This can result in cros_ec_uart_rx_bytes() being called while ec_dev is still not initialized, resulting in a kernel panic.

Call serdev_device_set_client_ops() after ec_dev is initialized.

[...]

Here is the summary with links:
- platform/chrome: cros_ec_uart: fix race condition

    https://git.kernel.org/chrome-platform/c/56d4b33d45e3

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#6 lore raw
In reply to Tzung-Bi Shih
This patch was applied to chrome-platform/linux.git (for-next) by Tzung-Bi Shih <[email protected]>:

Hello:

This patch was applied to chrome-platform/linux.git (for-next) by Tzung-Bi Shih <[email protected]>:

Quoted 9 lines · On Thu, 29 Dec 2022 17:47:38 +0800 you wrote:

From: Robert Zieba <[email protected]>

serdev_device_set_client_ops() is called before ec_dev is fully initialized. This can result in cros_ec_uart_rx_bytes() being called while ec_dev is still not initialized, resulting in a kernel panic.

Call serdev_device_set_client_ops() after ec_dev is initialized.

[...]

Here is the summary with links:
- platform/chrome: cros_ec_uart: fix race condition

    https://git.kernel.org/chrome-platform/c/56d4b33d45e3

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html