lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250428045754.glgyfhp2zn3l7wkj@troy-wujie14-pro>
Date: Mon, 28 Apr 2025 12:57:54 +0800
From: Troy Mitchell <troymitchell988@...il.com>
To: Peng Fan <peng.fan@....com>, Troy Mitchell <troymitchell988@...il.com>,
	Oleksij Rempel <o.rempel@...gutronix.de>,
	Pengutronix Kernel Team <kernel@...gutronix.de>,
	Andi Shyti <andi.shyti@...nel.org>, Shawn Guo <shawnguo@...nel.org>,
	Sascha Hauer <s.hauer@...gutronix.de>,
	Fabio Estevam <festevam@...il.com>
Cc: "linux-i2c@...r.kernel.org" <linux-i2c@...r.kernel.org>,
	"imx@...ts.linux.dev" <imx@...ts.linux.dev>,
	"linux-arm-kernel@...ts.infradead.org" <linux-arm-kernel@...ts.infradead.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	Yongchao Jia <jyc0019@...il.com>, Frank Li <frank.li@....com>
Subject: Re: [PATCH v2 1/2] i2c: imx: use guard to take spinlock

On Mon, Apr 28, 2025 at 12:55:48AM +0000, Peng Fan wrote:
> > Subject: [PATCH v2 1/2] i2c: imx: use guard to take spinlock
> > 
> > Use guard to automatically release the lock after going out of scope
> > instead of calling it manually.
> > 
> > i2c_imx_slave_handle() can safely be entered with the lock held.
> > 
> > Refactored the i2c_imx_isr function so that i2c_imx_master_isr does
> > not participate in the guard scope
> > 
> > So Using guard(spinlock_irqsave) simplifies the control flow by
> > ensuring consistent and automatic unlock, which improves readability
> > without affecting correctness.
> > 
> > Co-developed-by: Yongchao Jia <jyc0019@...il.com>
> > Signed-off-by: Yongchao Jia <jyc0019@...il.com>
> > Reviewed-by: Frank Li <Frank.Li@....com>
> > Signed-off-by: Troy Mitchell <troymitchell988@...il.com>
> > ---
> >  drivers/i2c/busses/i2c-imx.c | 39 ++++++++++++++++++---------------------
> >  1 file changed, 18 insertions(+), 21 deletions(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> > index 9e5d454d8318..a98bf01c5dde 100644
> > --- a/drivers/i2c/busses/i2c-imx.c
> > +++ b/drivers/i2c/busses/i2c-imx.c
...
> > @@ -1125,32 +1126,28 @@ static irqreturn_t i2c_imx_isr(int irq, void
> > *dev_id)  {
> >  	struct imx_i2c_struct *i2c_imx = dev_id;
> >  	unsigned int ctl, status;
> > -	unsigned long flags;
> > 
> > -	spin_lock_irqsave(&i2c_imx->slave_lock, flags);
> > -	status = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
> > -	ctl = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
> > +	{
> > +		guard(spinlock_irqsave)(&i2c_imx->slave_lock);
> 
> Use 
> scoped_guard(spinlock_irqsave, & i2c_imx->slave_lock) {
>  ...
> }
>
Ok, I'll use it in the next version,
and if no one has other suggestions, I'll send v3 ASAP.
> 
> Regards,
> Peng

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ