diff mbox series

[1/5] platform/chrome: cros_ec_lpc: Move mec_init/destroy to device probe/remove

Message ID 20221028141411.1.I0728421299079b104710c202d5d7095b2674fd8c@changeid (mailing list archive)
State Accepted
Headers show
Series [1/5] platform/chrome: cros_ec_lpc: Move mec_init/destroy to device probe/remove | expand

Commit Message

Brian Norris Oct. 28, 2022, 9:14 p.m. UTC
Disregarding the weird global state hiding in this cros_ec_lpc_mec_*()
stuff, it belongs in device probe/remove. We shouldn't assume we can
access hardware resources when the device isn't attached to the driver.

Signed-off-by: Brian Norris <briannorris@chromium.org>
---

 drivers/platform/chrome/cros_ec_lpc.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Tzung-Bi Shih Oct. 31, 2022, 4:55 a.m. UTC | #1
On Fri, Oct 28, 2022 at 02:14:45PM -0700, Brian Norris wrote:
> Disregarding the weird global state hiding in this cros_ec_lpc_mec_*()
> stuff, it belongs in device probe/remove. We shouldn't assume we can
> access hardware resources when the device isn't attached to the driver.

It's also weird that cros_ec_lpc_mec_destroy() destroies a statically
allocated mutex[1].  How about let's remove it?

[1]: https://elixir.bootlin.com/linux/v6.0/source/drivers/platform/chrome/cros_ec_lpc_mec.c#L152

> @@ -586,9 +591,6 @@ static int __init cros_ec_lpc_init(void)
>  		return -ENODEV;
>  	}
>  
> -	cros_ec_lpc_mec_init(EC_HOST_CMD_REGION0,
> -			     EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE);
> -
>  	/* Register the driver */
>  	ret = platform_driver_register(&cros_ec_lpc_driver);
>  	if (ret) {

There are 2 more cros_ec_lpc_mec_destroy()s need to be removed [2][3] though.

[2]: https://elixir.bootlin.com/linux/v6.0/source/drivers/platform/chrome/cros_ec_lpc.c#L596
[3]: https://elixir.bootlin.com/linux/v6.0/source/drivers/platform/chrome/cros_ec_lpc.c#L606
Tzung-Bi Shih Oct. 31, 2022, 5:14 a.m. UTC | #2
On Mon, Oct 31, 2022 at 12:55:57PM +0800, Tzung-Bi Shih wrote:
> On Fri, Oct 28, 2022 at 02:14:45PM -0700, Brian Norris wrote:
> > Disregarding the weird global state hiding in this cros_ec_lpc_mec_*()
> > stuff, it belongs in device probe/remove. We shouldn't assume we can
> > access hardware resources when the device isn't attached to the driver.
> 
> It's also weird that cros_ec_lpc_mec_destroy() destroies a statically
> allocated mutex[1].  How about let's remove it?

If it makes sense:
https://patchwork.kernel.org/project/chrome-platform/patch/20221031050657.3899359-1-tzungbi@kernel.org/
Brian Norris Oct. 31, 2022, 4:42 p.m. UTC | #3
On Mon, Oct 31, 2022 at 12:55:57PM +0800, Tzung-Bi Shih wrote:
> There are 2 more cros_ec_lpc_mec_destroy()s need to be removed [2][3] though.
> 
> [2]: https://elixir.bootlin.com/linux/v6.0/source/drivers/platform/chrome/cros_ec_lpc.c#L596
> [3]: https://elixir.bootlin.com/linux/v6.0/source/drivers/platform/chrome/cros_ec_lpc.c#L606

Your links / line numbers don't make sense, but I see your point. That
was a bad oversight on my part, sorry.

I see you're probably dropping the destroy() function, so I guess I'll
send v2 without this problem.

Brian
patchwork-bot+chrome-platform@kernel.org Nov. 2, 2022, 4:30 a.m. UTC | #4
Hello:

This series was applied to chrome-platform/linux.git (for-kernelci)
by Tzung-Bi Shih <tzungbi@kernel.org>:

On Fri, 28 Oct 2022 14:14:45 -0700 you wrote:
> Disregarding the weird global state hiding in this cros_ec_lpc_mec_*()
> stuff, it belongs in device probe/remove. We shouldn't assume we can
> access hardware resources when the device isn't attached to the driver.
> 
> Signed-off-by: Brian Norris <briannorris@chromium.org>
> ---
> 
> [...]

Here is the summary with links:
  - [1/5] platform/chrome: cros_ec_lpc: Move mec_init/destroy to device probe/remove
    (no matching commit)
  - [2/5] platform/chrome: cros_ec_lpc: Mark PROBE_PREFER_ASYNCHRONOUS
    https://git.kernel.org/chrome-platform/c/bd88b965ae8c
  - [3/5] platform/chrome: cros_ec_debugfs: Set PROBE_PREFER_ASYNCHRONOUS
    https://git.kernel.org/chrome-platform/c/692a68ad7f3c
  - [4/5] platform/chrome: cros_ec_lightbar: Set PROBE_PREFER_ASYNCHRONOUS
    https://git.kernel.org/chrome-platform/c/873ab3e886b5
  - [5/5] platform/chrome: cros_ec_spi: Set PROBE_PREFER_ASYNCHRONOUS
    https://git.kernel.org/chrome-platform/c/015e4b05c377

You are awesome, thank you!
patchwork-bot+chrome-platform@kernel.org Nov. 2, 2022, 12:30 p.m. UTC | #5
Hello:

This series was applied to chrome-platform/linux.git (for-next)
by Tzung-Bi Shih <tzungbi@kernel.org>:

On Fri, 28 Oct 2022 14:14:45 -0700 you wrote:
> Disregarding the weird global state hiding in this cros_ec_lpc_mec_*()
> stuff, it belongs in device probe/remove. We shouldn't assume we can
> access hardware resources when the device isn't attached to the driver.
> 
> Signed-off-by: Brian Norris <briannorris@chromium.org>
> ---
> 
> [...]

Here is the summary with links:
  - [1/5] platform/chrome: cros_ec_lpc: Move mec_init/destroy to device probe/remove
    (no matching commit)
  - [2/5] platform/chrome: cros_ec_lpc: Mark PROBE_PREFER_ASYNCHRONOUS
    https://git.kernel.org/chrome-platform/c/bd88b965ae8c
  - [3/5] platform/chrome: cros_ec_debugfs: Set PROBE_PREFER_ASYNCHRONOUS
    https://git.kernel.org/chrome-platform/c/692a68ad7f3c
  - [4/5] platform/chrome: cros_ec_lightbar: Set PROBE_PREFER_ASYNCHRONOUS
    https://git.kernel.org/chrome-platform/c/873ab3e886b5
  - [5/5] platform/chrome: cros_ec_spi: Set PROBE_PREFER_ASYNCHRONOUS
    https://git.kernel.org/chrome-platform/c/015e4b05c377

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c
index 7677ab3c0ead..0b6c7c912ec7 100644
--- a/drivers/platform/chrome/cros_ec_lpc.c
+++ b/drivers/platform/chrome/cros_ec_lpc.c
@@ -354,6 +354,9 @@  static int cros_ec_lpc_probe(struct platform_device *pdev)
 		return -EBUSY;
 	}
 
+	cros_ec_lpc_mec_init(EC_HOST_CMD_REGION0,
+			     EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE);
+
 	/*
 	 * Read the mapped ID twice, the first one is assuming the
 	 * EC is a Microchip Embedded Controller (MEC) variant, if the
@@ -456,6 +459,8 @@  static int cros_ec_lpc_remove(struct platform_device *pdev)
 
 	cros_ec_unregister(ec_dev);
 
+	cros_ec_lpc_mec_destroy();
+
 	return 0;
 }
 
@@ -586,9 +591,6 @@  static int __init cros_ec_lpc_init(void)
 		return -ENODEV;
 	}
 
-	cros_ec_lpc_mec_init(EC_HOST_CMD_REGION0,
-			     EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE);
-
 	/* Register the driver */
 	ret = platform_driver_register(&cros_ec_lpc_driver);
 	if (ret) {
@@ -615,7 +617,6 @@  static void __exit cros_ec_lpc_exit(void)
 	if (!cros_ec_lpc_acpi_device_found)
 		platform_device_unregister(&cros_ec_lpc_device);
 	platform_driver_unregister(&cros_ec_lpc_driver);
-	cros_ec_lpc_mec_destroy();
 }
 
 module_init(cros_ec_lpc_init);