2022-02-16 08:22:00

by Tzung-Bi Shih

[permalink] [raw]
Subject: [PATCH v5 0/5] platform/chrome: cros_ec: miscellaneous cleanups

The 1st patch fixes unhandled undos in error handling path.

The rest of patches cleans drivers/platform/chrome/cros_ec.c.

Changes from v4:
(https://patchwork.kernel.org/project/chrome-platform/cover/[email protected]/)
- Rollback the 3rd patch to older version.

Changes from v3:
(https://patchwork.kernel.org/project/chrome-platform/cover/[email protected]/)
- Drop "platform/chrome: cros_ec: don't initialize `err` in cros_ec_register()".
- Rename the 3rd patch's title.

Changes from v2:
(https://patchwork.kernel.org/project/chrome-platform/cover/[email protected]/)
- Fix review comments in 1st and 2nd patch.

Changes from v1:
(https://lore.kernel.org/lkml/[email protected]/T/#u)
- Use imperative mood in commit messages.
- Use IS_ERR_OR_NULL() in 1st patch.

Tzung-Bi Shih (5):
platform/chrome: cros_ec: fix error handling in cros_ec_register()
platform/chrome: cros_ec: remove unused variable `was_wake_device`
platform/chrome: cros_ec: determine `wake_enabled` in
cros_ec_suspend()
platform/chrome: cros_ec: sort header inclusion alphabetically
platform/chrome: cros_ec: append newline to all logs

drivers/platform/chrome/cros_ec.c | 36 ++++++++++++---------
include/linux/platform_data/cros_ec_proto.h | 3 --
2 files changed, 20 insertions(+), 19 deletions(-)

--
2.35.1.265.g69c8d7142f-goog


2022-02-16 08:22:01

by Tzung-Bi Shih

[permalink] [raw]
Subject: [PATCH v5 1/5] platform/chrome: cros_ec: fix error handling in cros_ec_register()

Fix cros_ec_register() to unregister platform devices if
blocking_notifier_chain_register() fails.

Also use the single exit path to handle the platform device
unregistration.

Fixes: 42cd0ab476e2 ("platform/chrome: cros_ec: Query EC protocol version if EC transitions between RO/RW")
Reviewed-by: Prashant Malani <[email protected]>
Signed-off-by: Tzung-Bi Shih <[email protected]>
---
Changes from v4:
(https://patchwork.kernel.org/project/chrome-platform/patch/[email protected]/)
- Add R-b tag.

Changes from v3:
(https://patchwork.kernel.org/project/chrome-platform/patch/[email protected]/)
- Simplify by initializing the variables at the beginning.

Changes from v2:
(https://patchwork.kernel.org/project/chrome-platform/patch/[email protected]/)
- Fix grammar error in commit message.
- Change the code that don't rely on zeroed memory.
- Remove unnecessary `if` checks before calling platform_device_unregister().

Changes from v1:
(https://lore.kernel.org/lkml/[email protected]/T/#u)
- Use imperative mood in commit message.
- Use IS_ERR_OR_NULL() in 1st patch.

drivers/platform/chrome/cros_ec.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c
index fc5aa1525d13..ff2a24b0c611 100644
--- a/drivers/platform/chrome/cros_ec.c
+++ b/drivers/platform/chrome/cros_ec.c
@@ -189,6 +189,8 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
ec_dev->max_request = sizeof(struct ec_params_hello);
ec_dev->max_response = sizeof(struct ec_response_get_protocol_info);
ec_dev->max_passthru = 0;
+ ec_dev->ec = NULL;
+ ec_dev->pd = NULL;

ec_dev->din = devm_kzalloc(dev, ec_dev->din_size, GFP_KERNEL);
if (!ec_dev->din)
@@ -245,18 +247,16 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
if (IS_ERR(ec_dev->pd)) {
dev_err(ec_dev->dev,
"Failed to create CrOS PD platform device\n");
- platform_device_unregister(ec_dev->ec);
- return PTR_ERR(ec_dev->pd);
+ err = PTR_ERR(ec_dev->pd);
+ goto exit;
}
}

if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
err = devm_of_platform_populate(dev);
if (err) {
- platform_device_unregister(ec_dev->pd);
- platform_device_unregister(ec_dev->ec);
dev_err(dev, "Failed to register sub-devices\n");
- return err;
+ goto exit;
}
}

@@ -278,7 +278,7 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
err = blocking_notifier_chain_register(&ec_dev->event_notifier,
&ec_dev->notifier_ready);
if (err)
- return err;
+ goto exit;
}

dev_info(dev, "Chrome EC device registered\n");
@@ -291,6 +291,10 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
cros_ec_irq_thread(0, ec_dev);

return 0;
+exit:
+ platform_device_unregister(ec_dev->ec);
+ platform_device_unregister(ec_dev->pd);
+ return err;
}
EXPORT_SYMBOL(cros_ec_register);

--
2.35.1.265.g69c8d7142f-goog

2022-02-16 08:22:04

by Tzung-Bi Shih

[permalink] [raw]
Subject: [PATCH v5 3/5] platform/chrome: cros_ec: determine `wake_enabled` in cros_ec_suspend()

`wake_enabled` indicates cros_ec_resume() needs to call
disable_irq_wake() to undo enable_irq_wake() in cros_ec_suspend().

Determine `wake_enabled` in cros_ec_suspend() instead of
reset-after-used in cros_ec_resume().

Signed-off-by: Tzung-Bi Shih <[email protected]>
---
Changes from v4:
(https://patchwork.kernel.org/project/chrome-platform/patch/[email protected]/)
- Undo changes from v3; rollback to v2.

Changes from v3:
(https://patchwork.kernel.org/project/chrome-platform/patch/[email protected]/)
- Change the patch title.
- Simplify by initializing wake_enabled in cros_ec_register().

No changes from v2.

Changes from v1:
(https://lore.kernel.org/lkml/[email protected]/T/#u)
- Use imperative mood in commit message.

drivers/platform/chrome/cros_ec.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c
index 25cd8df6e7b0..a013fbceeb03 100644
--- a/drivers/platform/chrome/cros_ec.c
+++ b/drivers/platform/chrome/cros_ec.c
@@ -342,6 +342,8 @@ int cros_ec_suspend(struct cros_ec_device *ec_dev)

if (device_may_wakeup(dev))
ec_dev->wake_enabled = !enable_irq_wake(ec_dev->irq);
+ else
+ ec_dev->wake_enabled = false;

disable_irq(ec_dev->irq);
ec_dev->suspended = true;
@@ -383,10 +385,9 @@ int cros_ec_resume(struct cros_ec_device *ec_dev)
dev_dbg(ec_dev->dev, "Error %d sending resume event to ec",
ret);

- if (ec_dev->wake_enabled) {
+ if (ec_dev->wake_enabled)
disable_irq_wake(ec_dev->irq);
- ec_dev->wake_enabled = 0;
- }
+
/*
* Let the mfd devices know about events that occur during
* suspend. This way the clients know what to do with them.
--
2.35.1.265.g69c8d7142f-goog

2022-02-16 08:22:09

by Tzung-Bi Shih

[permalink] [raw]
Subject: [PATCH v5 5/5] platform/chrome: cros_ec: append newline to all logs

To be consistent, append newline ("\n") to all logs.

Reviewed-by: Guenter Roeck <[email protected]>
Reviewed-by: Prashant Malani <[email protected]>
Signed-off-by: Tzung-Bi Shih <[email protected]>
---
No changes from v4.

Changes from v3:
(https://patchwork.kernel.org/project/chrome-platform/patch/[email protected]/)
- Add R-b tags.

No changes from v2.

Changes from v1:
(https://lore.kernel.org/lkml/[email protected]/T/#u)
- Use imperative mood in commit message.

drivers/platform/chrome/cros_ec.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c
index 1e1a24a80d9f..1395c764d938 100644
--- a/drivers/platform/chrome/cros_ec.c
+++ b/drivers/platform/chrome/cros_ec.c
@@ -215,7 +215,7 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
"chromeos-ec", ec_dev);
if (err) {
- dev_err(dev, "Failed to request IRQ %d: %d",
+ dev_err(dev, "Failed to request IRQ %d: %d\n",
ec_dev->irq, err);
return err;
}
@@ -266,7 +266,7 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
*/
err = cros_ec_sleep_event(ec_dev, 0);
if (err < 0)
- dev_dbg(ec_dev->dev, "Error %d clearing sleep event to ec",
+ dev_dbg(ec_dev->dev, "Error %d clearing sleep event to ec\n",
err);

if (ec_dev->mkbp_event_supported) {
@@ -337,7 +337,7 @@ int cros_ec_suspend(struct cros_ec_device *ec_dev)

ret = cros_ec_sleep_event(ec_dev, sleep_event);
if (ret < 0)
- dev_dbg(ec_dev->dev, "Error %d sending suspend event to ec",
+ dev_dbg(ec_dev->dev, "Error %d sending suspend event to ec\n",
ret);

if (device_may_wakeup(dev))
@@ -382,7 +382,7 @@ int cros_ec_resume(struct cros_ec_device *ec_dev)

ret = cros_ec_sleep_event(ec_dev, sleep_event);
if (ret < 0)
- dev_dbg(ec_dev->dev, "Error %d sending resume event to ec",
+ dev_dbg(ec_dev->dev, "Error %d sending resume event to ec\n",
ret);

if (ec_dev->wake_enabled)
--
2.35.1.265.g69c8d7142f-goog

2022-02-16 08:22:10

by Tzung-Bi Shih

[permalink] [raw]
Subject: [PATCH v5 2/5] platform/chrome: cros_ec: remove unused variable `was_wake_device`

Reviewed-by: Prashant Malani <[email protected]>
Signed-off-by: Tzung-Bi Shih <[email protected]>
---
No changes from v3 and v4.

Changes from v2:
(https://patchwork.kernel.org/project/chrome-platform/patch/[email protected]/)
- Add pmalani's R-b tag.
- Remove redundant commit message.

Changes from v1:
(https://lore.kernel.org/lkml/[email protected]/T/#u)
- Use imperative mood in commit message.

drivers/platform/chrome/cros_ec.c | 1 -
include/linux/platform_data/cros_ec_proto.h | 3 ---
2 files changed, 4 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c
index ff2a24b0c611..25cd8df6e7b0 100644
--- a/drivers/platform/chrome/cros_ec.c
+++ b/drivers/platform/chrome/cros_ec.c
@@ -344,7 +344,6 @@ int cros_ec_suspend(struct cros_ec_device *ec_dev)
ec_dev->wake_enabled = !enable_irq_wake(ec_dev->irq);

disable_irq(ec_dev->irq);
- ec_dev->was_wake_device = ec_dev->wake_enabled;
ec_dev->suspended = true;

return 0;
diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h
index df3c78c92ca2..c65971ec90ea 100644
--- a/include/linux/platform_data/cros_ec_proto.h
+++ b/include/linux/platform_data/cros_ec_proto.h
@@ -76,8 +76,6 @@ struct cros_ec_command {
* struct cros_ec_device - Information about a ChromeOS EC device.
* @phys_name: Name of physical comms layer (e.g. 'i2c-4').
* @dev: Device pointer for physical comms device
- * @was_wake_device: True if this device was set to wake the system from
- * sleep at the last suspend.
* @cros_class: The class structure for this device.
* @cmd_readmem: Direct read of the EC memory-mapped region, if supported.
* @offset: Is within EC_LPC_ADDR_MEMMAP region.
@@ -137,7 +135,6 @@ struct cros_ec_device {
/* These are used by other drivers that want to talk to the EC */
const char *phys_name;
struct device *dev;
- bool was_wake_device;
struct class *cros_class;
int (*cmd_readmem)(struct cros_ec_device *ec, unsigned int offset,
unsigned int bytes, void *dest);
--
2.35.1.265.g69c8d7142f-goog

2022-02-16 08:22:12

by Tzung-Bi Shih

[permalink] [raw]
Subject: [PATCH v5 4/5] platform/chrome: cros_ec: sort header inclusion alphabetically

Sort header inclusion alphabetically.

Reviewed-by: Guenter Roeck <[email protected]>
Reviewed-by: Prashant Malani <[email protected]>
Signed-off-by: Tzung-Bi Shih <[email protected]>
---
No changes from v4.

Changes from v3:
(https://patchwork.kernel.org/project/chrome-platform/patch/[email protected]/)
- Add R-b tags.

No changes from v2.

Changes from v1:
(https://lore.kernel.org/lkml/[email protected]/T/#u)
- Use imperative mood in commit message.

drivers/platform/chrome/cros_ec.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c
index a013fbceeb03..1e1a24a80d9f 100644
--- a/drivers/platform/chrome/cros_ec.c
+++ b/drivers/platform/chrome/cros_ec.c
@@ -9,12 +9,12 @@
* battery charging and regulator control, firmware update.
*/

-#include <linux/of_platform.h>
#include <linux/interrupt.h>
-#include <linux/slab.h>
#include <linux/module.h>
+#include <linux/of_platform.h>
#include <linux/platform_data/cros_ec_commands.h>
#include <linux/platform_data/cros_ec_proto.h>
+#include <linux/slab.h>
#include <linux/suspend.h>

#include "cros_ec.h"
--
2.35.1.265.g69c8d7142f-goog

2022-02-17 09:07:36

by Prashant Malani

[permalink] [raw]
Subject: Re: [PATCH v5 3/5] platform/chrome: cros_ec: determine `wake_enabled` in cros_ec_suspend()

On Feb 16 16:03, Tzung-Bi Shih wrote:
> `wake_enabled` indicates cros_ec_resume() needs to call
> disable_irq_wake() to undo enable_irq_wake() in cros_ec_suspend().
>
> Determine `wake_enabled` in cros_ec_suspend() instead of
> reset-after-used in cros_ec_resume().
>
> Signed-off-by: Tzung-Bi Shih <[email protected]>

I don't see what is the issue with reset-after-use here, as long as the
variable is initialized correctly. This patch strikes me as larger than
it really needs to me. Anyway, FWIW:

Reviewed-by: Prashant Malani <[email protected]>

> ---
> Changes from v4:
> (https://patchwork.kernel.org/project/chrome-platform/patch/[email protected]/)
> - Undo changes from v3; rollback to v2.
>
> Changes from v3:
> (https://patchwork.kernel.org/project/chrome-platform/patch/[email protected]/)
> - Change the patch title.
> - Simplify by initializing wake_enabled in cros_ec_register().
>
> No changes from v2.
>
> Changes from v1:
> (https://lore.kernel.org/lkml/[email protected]/T/#u)
> - Use imperative mood in commit message.
>
> drivers/platform/chrome/cros_ec.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c
> index 25cd8df6e7b0..a013fbceeb03 100644
> --- a/drivers/platform/chrome/cros_ec.c
> +++ b/drivers/platform/chrome/cros_ec.c
> @@ -342,6 +342,8 @@ int cros_ec_suspend(struct cros_ec_device *ec_dev)
>
> if (device_may_wakeup(dev))
> ec_dev->wake_enabled = !enable_irq_wake(ec_dev->irq);
> + else
> + ec_dev->wake_enabled = false;
>
> disable_irq(ec_dev->irq);
> ec_dev->suspended = true;
> @@ -383,10 +385,9 @@ int cros_ec_resume(struct cros_ec_device *ec_dev)
> dev_dbg(ec_dev->dev, "Error %d sending resume event to ec",
> ret);
>
> - if (ec_dev->wake_enabled) {
> + if (ec_dev->wake_enabled)
> disable_irq_wake(ec_dev->irq);
> - ec_dev->wake_enabled = 0;
> - }
> +
> /*
> * Let the mfd devices know about events that occur during
> * suspend. This way the clients know what to do with them.
> --
> 2.35.1.265.g69c8d7142f-goog
>

Subject: Re: [PATCH v5 0/5] platform/chrome: cros_ec: miscellaneous cleanups

Hello:

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

On Wed, 16 Feb 2022 16:03:01 +0800 you wrote:
> The 1st patch fixes unhandled undos in error handling path.
>
> The rest of patches cleans drivers/platform/chrome/cros_ec.c.
>
> Changes from v4:
> (https://patchwork.kernel.org/project/chrome-platform/cover/[email protected]/)
> - Rollback the 3rd patch to older version.
>
> [...]

Here is the summary with links:
- [v5,1/5] platform/chrome: cros_ec: fix error handling in cros_ec_register()
https://git.kernel.org/chrome-platform/c/2cd01bd6b117
- [v5,2/5] platform/chrome: cros_ec: remove unused variable `was_wake_device`
https://git.kernel.org/chrome-platform/c/f47a6113f4e8
- [v5,3/5] platform/chrome: cros_ec: determine `wake_enabled` in cros_ec_suspend()
https://git.kernel.org/chrome-platform/c/9fbe967d4e6e
- [v5,4/5] platform/chrome: cros_ec: sort header inclusion alphabetically
https://git.kernel.org/chrome-platform/c/5781a33098c6
- [v5,5/5] platform/chrome: cros_ec: append newline to all logs
https://git.kernel.org/chrome-platform/c/8d4668064cce

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html


Subject: Re: [PATCH v5 0/5] platform/chrome: cros_ec: miscellaneous cleanups

Hello:

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

On Wed, 16 Feb 2022 16:03:01 +0800 you wrote:
> The 1st patch fixes unhandled undos in error handling path.
>
> The rest of patches cleans drivers/platform/chrome/cros_ec.c.
>
> Changes from v4:
> (https://patchwork.kernel.org/project/chrome-platform/cover/[email protected]/)
> - Rollback the 3rd patch to older version.
>
> [...]

Here is the summary with links:
- [v5,1/5] platform/chrome: cros_ec: fix error handling in cros_ec_register()
https://git.kernel.org/chrome-platform/c/2cd01bd6b117
- [v5,2/5] platform/chrome: cros_ec: remove unused variable `was_wake_device`
https://git.kernel.org/chrome-platform/c/f47a6113f4e8
- [v5,3/5] platform/chrome: cros_ec: determine `wake_enabled` in cros_ec_suspend()
https://git.kernel.org/chrome-platform/c/9fbe967d4e6e
- [v5,4/5] platform/chrome: cros_ec: sort header inclusion alphabetically
https://git.kernel.org/chrome-platform/c/5781a33098c6
- [v5,5/5] platform/chrome: cros_ec: append newline to all logs
https://git.kernel.org/chrome-platform/c/8d4668064cce

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html