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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250907142034.5b000107@jic23-huawei>
Date: Sun, 7 Sep 2025 14:20:34 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: David Lechner <dlechner@...libre.com>
Cc: Sean Nyekjaer <sean@...nix.com>, Jean-Baptiste Maneyrol
 <jean-baptiste.maneyrol@....com>, rafael@...nel.org, Nuno Sá
 <nuno.sa@...log.com>, Andy Shevchenko <andy@...nel.org>,
 linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
 linux-pm@...r.kernel.org, Jean-Baptiste Maneyrol
 <jmaneyrol@...ensense.com>, Jonathan Cameron <Jonathan.Cameron@...wei.com>
Subject: Re: [PATCH v3 5/5] iio: imu: inv_icm42600: use guard() to release
 mutexes


> ...
> 
> > @@ -299,7 +298,7 @@ static int inv_icm42600_buffer_postenable(struct iio_dev *indio_dev)
> >  	struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
> >  	int ret;
> >  
> > -	mutex_lock(&st->lock);
> > +	guard(mutex)(&st->lock);
> >  
> >  	/* exit if FIFO is already on */
> >  	if (st->fifo.on) {
> > @@ -311,30 +310,29 @@ static int inv_icm42600_buffer_postenable(struct iio_dev *indio_dev)
> >  	ret = regmap_set_bits(st->map, INV_ICM42600_REG_INT_SOURCE0,
> >  			      INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN);
> >  	if (ret)
> > -		goto out_unlock;
> > +		return ret;
> >  
> >  	/* flush FIFO data */
> >  	ret = regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET,
> >  			   INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH);
> >  	if (ret)
> > -		goto out_unlock;
> > +		return ret;
> >  
> >  	/* set FIFO in streaming mode */
> >  	ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG,
> >  			   INV_ICM42600_FIFO_CONFIG_STREAM);
> >  	if (ret)
> > -		goto out_unlock;
> > +		return ret;
> >  
> >  	/* workaround: first read of FIFO count after reset is always 0 */
> >  	ret = regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT, st->buffer, 2);
> >  	if (ret)
> > -		goto out_unlock;
> > +		return ret;
> >  
> >  out_on:
> >  	/* increase FIFO on counter */
> >  	st->fifo.on++;  
> 
> I would be tempted to get rid of out_on as well even if we have to repeat
> `st->fifo.on++;` in two places.

There is strong guidance in cleanup.h on basically never mixing gotos
and cleanup (including guard).  It is probably fine here but some compilers
(gcc) are very bad at detecting uninitialized conditions that can happen with
gotos.  More generally Linus has expressed that if you need to mix the two
cleanup.h magic is not appropriate. Following David's suggestion the problem
is solved through duplication of that increment.

> 
> > -out_unlock:
> > -	mutex_unlock(&st->lock);
> > +
> >  	return ret;  
> 
> Can just return 0 here and simplify if (st->fifo.on).



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ