All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: Michael Lawnick <ml.lawnick-Mmb7MZpHnFY@public.gmane.org>
Cc: Linux I2C <linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [Patch v3] i2c: Multiplexed I2C bus core support
Date: Tue, 20 Jul 2010 10:53:51 +0200	[thread overview]
Message-ID: <20100720105351.58541932@hyperion.delvare> (raw)
In-Reply-To: <4C4545C7.4070508-Mmb7MZpHnFY@public.gmane.org>

On Tue, 20 Jul 2010 08:44:23 +0200, Michael Lawnick wrote:
> Jean Delvare said the following:
> >> @@ -656,9 +709,9 @@ i2c_sysfs_new_device(struct device *dev, struct
> >> device_attribute *attr,
> >>  		return -EINVAL;
> >> 
> >>  	/* Keep track of the added device */
> >> -	i2c_lock_adapter(adap);
> >> +	rt_mutex_lock(&adap->bus_lock);
> >>  	list_add_tail(&client->detected, &adap->userspace_clients);
> >> -	i2c_unlock_adapter(adap);
> >> +	rt_mutex_unlock(&adap->bus_lock);
> >>  	dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device",
> >>  		 info.type, info.addr);
> >> 
> > 
> > I expected us to just use i2c_lock/unlock_adapter() everywhere for
> > simplicity. Now I have to agree that using the segment's mutex works
> > too, as the operation is both local to the mutex and unrelated to
> > the other use cases of i2c_lock/unlock_adapter(). But it becomes a
> > little tricky, so it should be all documented clearly (which I will
> > do, don't worry.)
> > 
> >> @@ -697,7 +750,7 @@ i2c_sysfs_delete_device(struct device *dev, struct
> >> device_attribute *attr,
> >> 
> >>  	/* Make sure the device was added through sysfs */
> >>  	res = -ENOENT;
> >> -	i2c_lock_adapter(adap);
> >> +	rt_mutex_lock(&adap->bus_lock);
> >>  	list_for_each_entry_safe(client, next, &adap->userspace_clients,
> >>  				 detected) {
> >>  		if (client->addr == addr) {
> >> @@ -710,7 +763,7 @@ i2c_sysfs_delete_device(struct device *dev, struct
> >> device_attribute *attr,
> >>  			break;
> >>  		}
> >>  	}
> >> -	i2c_unlock_adapter(adap);
> >> +	rt_mutex_unlock(&adap->bus_lock);
> >> 
> >>  	if (res < 0)
> >>  		dev_err(dev, "%s: Can't find device in list\n",
> 
> In i2c_sysfs_delete_device you need a local lock, otherwise you'll get
> a deadlock on removing sub-clients/tree. This in turn brings the local
> lock to i2c_sysfs_new_device().

This is only relevant if the device instantiated / removed from
user-space is an I2C mux chip, right?

Please remember that i2c_lock_adapter() and rt_mutex_lock() might do
exactly the same, if applied to the root segment of an I2C tree. So if
i2c_lock_adapter() would deadlock, I fear that a simple rt_mutex_lock()
might deadlock too. So in the end we might have to introduce another
mutex dedicated to protecting the adapter->userspace_clients list.
Maybe we should have done this from the beginning...

> Thank you for your review.
> ToDo after release: Inventing mux-adapter-name definition in mux-client
> code instead of mux-code. You were right in your last review, this is
> terribly necessary.

OK.

-- 
Jean Delvare

  parent reply	other threads:[~2010-07-20  8:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-09  9:07 [Patch v3] i2c: Multiplexed I2C bus core support Michael Lawnick
     [not found] ` <4C36E6E2.1070307-Mmb7MZpHnFY@public.gmane.org>
2010-07-19 15:25   ` Jean Delvare
     [not found]     ` <20100719172548.2d88ed73-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-07-20  6:44       ` Michael Lawnick
     [not found]         ` <4C4545C7.4070508-Mmb7MZpHnFY@public.gmane.org>
2010-07-20  8:53           ` Jean Delvare [this message]
     [not found]             ` <20100720105351.58541932-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-07-22 13:08               ` Michael Lawnick
2010-07-20 19:27   ` Jean Delvare
     [not found]     ` <20100720212729.4d81048b-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-07-22  6:42       ` Rodolfo Giometti
     [not found]         ` <20100722064243.GB9753-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org>
2010-08-10 12:33           ` Jean Delvare
     [not found]             ` <20100810143335.406dd2c5-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-08-10 17:05               ` Rodolfo Giometti
     [not found]                 ` <20100810170525.GA17506-h5F9bMWSfx92wUeKyQHPq0EOCMrvLtNR@public.gmane.org>
2010-08-23 11:00                   ` Michael Lawnick
2013-02-13 15:36   ` Gerlando Falauto
     [not found]     ` <511BB2F8.9020300-SkAbAL50j+5BDgjK7y7TUQ@public.gmane.org>
2013-02-18 10:19       ` Michael Lawnick
     [not found]         ` <51220036.4030508-Mmb7MZpHnFY@public.gmane.org>
2013-02-18 10:38           ` Gerlando Falauto
     [not found]             ` <512204BC.7060603-SkAbAL50j+5BDgjK7y7TUQ@public.gmane.org>
2013-02-18 14:01               ` Michael Lawnick

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100720105351.58541932@hyperion.delvare \
    --to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=ml.lawnick-Mmb7MZpHnFY@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.