[PATCH 1/2] tty: serial: imx: Only configure the wake register when device is set as wakeup source

Sherry Sun posted 2 patches 4 months, 2 weeks ago
There is a newer version of this series
[PATCH 1/2] tty: serial: imx: Only configure the wake register when device is set as wakeup source
Posted by Sherry Sun 4 months, 2 weeks ago
Currently, imx uart defaults to enabling the wake related registers for
all uart devices. However, it is unnecessary for those devices not
configured as wakeup source, so add device_may_wakeup() check before
configuring the uart wake related registers.

Fixes: db1a9b55004c ("tty: serial: imx: Allow UART to be a source for wakeup")
Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
---
 drivers/tty/serial/imx.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 500dfc009d03..4ddfc89816bf 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -2697,7 +2697,22 @@ static void imx_uart_save_context(struct imx_port *sport)
 /* called with irq off */
 static void imx_uart_enable_wakeup(struct imx_port *sport, bool on)
 {
+	struct tty_port *port = &sport->port.state->port;
+	struct tty_struct *tty;
+	struct device *tty_dev;
 	u32 ucr3;
+	bool may_wake;
+
+	tty = tty_port_tty_get(port);
+	if (tty) {
+		tty_dev = tty->dev;
+		may_wake = tty_dev && device_may_wakeup(tty_dev);
+		tty_kref_put(tty);
+	}
+
+	/* only configure the wake register when device set as wakeup source */
+	if (!may_wake)
+		return;
 
 	uart_port_lock_irq(&sport->port);
 
-- 
2.34.1
Re: [PATCH 1/2] tty: serial: imx: Only configure the wake register when device is set as wakeup source
Posted by kernel test robot 4 months, 2 weeks ago
Hi Sherry,

kernel test robot noticed the following build warnings:

[auto build test WARNING on shawnguo/for-next]
[also build test WARNING on tty/tty-testing tty/tty-next tty/tty-linus usb/usb-testing usb/usb-next usb/usb-linus linus/master v6.17-rc7 next-20250922]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sherry-Sun/tty-serial-imx-Only-configure-the-wake-register-when-device-is-set-as-wakeup-source/20250923-111951
base:   https://git.kernel.org/pub/scm/linux/kernel/git/shawnguo/linux.git for-next
patch link:    https://lore.kernel.org/r/20250923031613.2448073-2-sherry.sun%40nxp.com
patch subject: [PATCH 1/2] tty: serial: imx: Only configure the wake register when device is set as wakeup source
config: arm-randconfig-004-20250923 (https://download.01.org/0day-ci/archive/20250924/202509240009.Q4htWwxE-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project cafc064fc7a96b3979a023ddae1da2b499d6c954)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250924/202509240009.Q4htWwxE-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202509240009.Q4htWwxE-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/tty/serial/imx.c:2707:6: warning: variable 'may_wake' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    2707 |         if (tty) {
         |             ^~~
   drivers/tty/serial/imx.c:2714:7: note: uninitialized use occurs here
    2714 |         if (!may_wake)
         |              ^~~~~~~~
   drivers/tty/serial/imx.c:2707:2: note: remove the 'if' if its condition is always true
    2707 |         if (tty) {
         |         ^~~~~~~~
   drivers/tty/serial/imx.c:2704:15: note: initialize the variable 'may_wake' to silence this warning
    2704 |         bool may_wake;
         |                      ^
         |                       = 0
   1 warning generated.


vim +2707 drivers/tty/serial/imx.c

  2696	
  2697	/* called with irq off */
  2698	static void imx_uart_enable_wakeup(struct imx_port *sport, bool on)
  2699	{
  2700		struct tty_port *port = &sport->port.state->port;
  2701		struct tty_struct *tty;
  2702		struct device *tty_dev;
  2703		u32 ucr3;
  2704		bool may_wake;
  2705	
  2706		tty = tty_port_tty_get(port);
> 2707		if (tty) {
  2708			tty_dev = tty->dev;
  2709			may_wake = tty_dev && device_may_wakeup(tty_dev);
  2710			tty_kref_put(tty);
  2711		}
  2712	
  2713		/* only configure the wake register when device set as wakeup source */
  2714		if (!may_wake)
  2715			return;
  2716	
  2717		uart_port_lock_irq(&sport->port);
  2718	
  2719		ucr3 = imx_uart_readl(sport, UCR3);
  2720		if (on) {
  2721			imx_uart_writel(sport, USR1_AWAKE, USR1);
  2722			ucr3 |= UCR3_AWAKEN;
  2723		} else {
  2724			ucr3 &= ~UCR3_AWAKEN;
  2725		}
  2726		imx_uart_writel(sport, ucr3, UCR3);
  2727	
  2728		if (sport->have_rtscts) {
  2729			u32 ucr1 = imx_uart_readl(sport, UCR1);
  2730			if (on) {
  2731				imx_uart_writel(sport, USR1_RTSD, USR1);
  2732				ucr1 |= UCR1_RTSDEN;
  2733			} else {
  2734				ucr1 &= ~UCR1_RTSDEN;
  2735			}
  2736			imx_uart_writel(sport, ucr1, UCR1);
  2737		}
  2738	
  2739		uart_port_unlock_irq(&sport->port);
  2740	}
  2741	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH 1/2] tty: serial: imx: Only configure the wake register when device is set as wakeup source
Posted by Peng Fan 4 months, 2 weeks ago
On Tue, Sep 23, 2025 at 11:16:12AM +0800, Sherry Sun wrote:
>Currently, imx uart defaults to enabling the wake related registers for
>all uart devices. However, it is unnecessary for those devices not
>configured as wakeup source, so add device_may_wakeup() check before
>configuring the uart wake related registers.

I would rewrite as this:
Currently, the i.MX UART driver enables wake-related registers for all UART
devices by default. However, this is unnecessary for devices that are not
configured as wakeup sources. To address this, add a device_may_wakeup()
check before configuring the UART wake-related registers.

>
>Fixes: db1a9b55004c ("tty: serial: imx: Allow UART to be a source for wakeup")
>Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
>---
> drivers/tty/serial/imx.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
>diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
>index 500dfc009d03..4ddfc89816bf 100644
>--- a/drivers/tty/serial/imx.c
>+++ b/drivers/tty/serial/imx.c
>@@ -2697,7 +2697,22 @@ static void imx_uart_save_context(struct imx_port *sport)
> /* called with irq off */
> static void imx_uart_enable_wakeup(struct imx_port *sport, bool on)
> {
>+	struct tty_port *port = &sport->port.state->port;
>+	struct tty_struct *tty;
>+	struct device *tty_dev;
> 	u32 ucr3;
>+	bool may_wake;

'bool may_wake = false;' otherwise there might be report on using an
uninitalized value by coverity or other tools.

>+
>+	tty = tty_port_tty_get(port);
>+	if (tty) {
>+		tty_dev = tty->dev;
>+		may_wake = tty_dev && device_may_wakeup(tty_dev);
>+		tty_kref_put(tty);
>+	}
>+
>+	/* only configure the wake register when device set as wakeup source */
>+	if (!may_wake)
>+		return;

Regards,
Peng