From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wolfram Sang Subject: Re: [PATCH v7 18/24] i2c-mux: relax locking of the top i2c adapter during mux-locked muxing Date: Tue, 3 May 2016 23:38:45 +0200 Message-ID: <20160503213844.GB2018@tetsubishi> References: <1461165484-2314-1-git-send-email-peda@axentia.se> <1461165484-2314-19-git-send-email-peda@axentia.se> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <1461165484-2314-19-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org> Sender: linux-iio-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Peter Rosin Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Jonathan Corbet , Peter Korsgaard , Guenter Roeck , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald , Antti Palosaari , Mauro Carvalho Chehab , Rob Herring , Frank Rowand , Grant Likely , Andrew Morton , "David S. Miller" , Greg Kroah-Hartman , Kalle Valo , Jiri Slaby , Daniel Baluta , Lucas De Marchi , Adriana Reus , Matt Ranostay , Krzysztof Kozlowski List-Id: linux-i2c@vger.kernel.org > +static int i2c_mux_trylock_bus(struct i2c_adapter *adapter, int flags) > +{ > + struct i2c_mux_priv *priv = adapter->algo_data; > + struct i2c_adapter *parent = priv->muxc->parent; > + > + if (!rt_mutex_trylock(&parent->mux_lock)) > + return 0; > + if (!(flags & I2C_LOCK_ADAPTER)) > + return 1; > + if (parent->trylock_bus(parent, flags)) > + return 1; > + rt_mutex_unlock(&parent->mux_lock); > + return 0; > +} This function needs a few short comments why we can leave in this or that state. Not everyone knows the exit values of trylock by heart and then it can look a little confusing. > static int i2c_parent_trylock_bus(struct i2c_adapter *adapter, int flags) > @@ -111,7 +189,12 @@ static int i2c_parent_trylock_bus(struct i2c_adapter *adapter, int flags) > struct i2c_mux_priv *priv = adapter->algo_data; > struct i2c_adapter *parent = priv->muxc->parent; > > - return parent->trylock_bus(parent, flags); > + if (!rt_mutex_trylock(&parent->mux_lock)) > + return 0; > + if (parent->trylock_bus(parent, flags)) > + return 1; > + rt_mutex_unlock(&parent->mux_lock); > + return 0; > } Same comment as i2c_mux_trylock_bus. > struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent, > struct device *dev, int max_adapters, > @@ -140,6 +250,8 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent, > > muxc->parent = parent; > muxc->dev = dev; > + if (flags & I2C_MUX_LOCKED) > + muxc->mux_locked = 1; s/1/true/;