linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] platform: x86: intel_scu_ipc: Replace mdelay with usleep_range in intel_scu_ipc_i2c_cntrl
@ 2018-04-10 12:57 Jia-Ju Bai
  2018-04-10 15:25 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2018-04-10 12:57 UTC (permalink / raw)
  To: dvhart, andy; +Cc: platform-driver-x86, linux-kernel, Jia-Ju Bai

intel_scu_ipc_i2c_cntrl() calls mutex_lock(), which indicates
this function is not called in atomic context.

Despite never getting called from atomic context, 
intel_scu_ipc_i2c_cntrl() calls mdelay to busily wait.
This is not necessary and can be replaced with usleep_range to
avoid busy waiting.

This is found by a static analysis tool named DCNS written by myself.
And I also manually check it.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/platform/x86/intel_scu_ipc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c
index 2c85f75..75c8fef 100644
--- a/drivers/platform/x86/intel_scu_ipc.c
+++ b/drivers/platform/x86/intel_scu_ipc.c
@@ -584,11 +584,11 @@ int intel_scu_ipc_i2c_cntrl(u32 addr, u32 *data)
 	if (cmd == IPC_I2C_READ) {
 		writel(addr, scu->i2c_base + IPC_I2C_CNTRL_ADDR);
 		/* Write not getting updated without delay */
-		mdelay(1);
+		usleep_range(1000, 2000);
 		*data = readl(scu->i2c_base + I2C_DATA_ADDR);
 	} else if (cmd == IPC_I2C_WRITE) {
 		writel(*data, scu->i2c_base + I2C_DATA_ADDR);
-		mdelay(1);
+		usleep_range(1000, 2000);
 		writel(addr, scu->i2c_base + IPC_I2C_CNTRL_ADDR);
 	} else {
 		dev_err(scu->dev,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] platform: x86: intel_scu_ipc: Replace mdelay with usleep_range in intel_scu_ipc_i2c_cntrl
  2018-04-10 12:57 [PATCH] platform: x86: intel_scu_ipc: Replace mdelay with usleep_range in intel_scu_ipc_i2c_cntrl Jia-Ju Bai
@ 2018-04-10 15:25 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2018-04-10 15:25 UTC (permalink / raw)
  To: Jia-Ju Bai
  Cc: Darren Hart, Andy Shevchenko, Platform Driver, Linux Kernel Mailing List

On Tue, Apr 10, 2018 at 3:57 PM, Jia-Ju Bai <baijiaju1990@gmail.com> wrote:
> intel_scu_ipc_i2c_cntrl() calls mutex_lock(), which indicates
> this function is not called in atomic context.
>
> Despite never getting called from atomic context,
> intel_scu_ipc_i2c_cntrl() calls mdelay to busily wait.
> This is not necessary and can be replaced with usleep_range to
> avoid busy waiting.
>
> This is found by a static analysis tool named DCNS written by myself.
> And I also manually check it.

I'm not sure we even need that delay at all.
Anyway, pushed to my review and testing queue, thanks!

>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  drivers/platform/x86/intel_scu_ipc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c
> index 2c85f75..75c8fef 100644
> --- a/drivers/platform/x86/intel_scu_ipc.c
> +++ b/drivers/platform/x86/intel_scu_ipc.c
> @@ -584,11 +584,11 @@ int intel_scu_ipc_i2c_cntrl(u32 addr, u32 *data)
>         if (cmd == IPC_I2C_READ) {
>                 writel(addr, scu->i2c_base + IPC_I2C_CNTRL_ADDR);
>                 /* Write not getting updated without delay */
> -               mdelay(1);
> +               usleep_range(1000, 2000);
>                 *data = readl(scu->i2c_base + I2C_DATA_ADDR);
>         } else if (cmd == IPC_I2C_WRITE) {
>                 writel(*data, scu->i2c_base + I2C_DATA_ADDR);
> -               mdelay(1);
> +               usleep_range(1000, 2000);
>                 writel(addr, scu->i2c_base + IPC_I2C_CNTRL_ADDR);
>         } else {
>                 dev_err(scu->dev,
> --
> 1.9.1
>



-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-10 15:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-10 12:57 [PATCH] platform: x86: intel_scu_ipc: Replace mdelay with usleep_range in intel_scu_ipc_i2c_cntrl Jia-Ju Bai
2018-04-10 15:25 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).