From: Michael Lawnick <ml.lawnick-Mmb7MZpHnFY@public.gmane.org>
To: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
Cc: Linux I2C <linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH v3] i2c-core: Fix for lockdep validator
Date: Mon, 10 Sep 2012 14:55:02 +0200 [thread overview]
Message-ID: <504DE326.8080706@gmx.de> (raw)
In-Reply-To: <20120908093814.21c1174d-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
Am 08.09.2012 09:38, schrieb Jean Delvare:
> If kernel is compiled with CONFIG_PROVE_LOCKING the
> validator raises an error when a multiplexer is removed
> via sysfs and sub-clients are connected to it. This is a
> false positive.
> Documentation/lockdep-design.txt recommends to handle this
> via calls to mutex_lock_nested().
>
> Based on an earlier fix from Michael Lawnick.
>
> Note that the extra code resolves to nothing unless
> CONFIG_DEBUG_LOCK_ALLOC=y.
>
> Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
> Cc: Michael Lawnick <ml.lawnick-Mmb7MZpHnFY@public.gmane.org>
Tested-by: Michael Lawnick <ml.lawnick-Mmb7MZpHnFY@public.gmane.org>
Acked-by: Michael Lawnick <ml.lawnick-Mmb7MZpHnFY@public.gmane.org>
> ---
> Changes since v2:
> * Inline function i2c_adapter_depth to avoid a compiler warning.
> * Document the reason why it it implemented that way.
>
> drivers/i2c/i2c-core.c | 22 ++++++++++++++++++++--
> 1 file changed, 20 insertions(+), 2 deletions(-)
>
> --- linux-3.6-rc4.orig/drivers/i2c/i2c-core.c 2012-09-07 17:53:31.000000000 +0200
> +++ linux-3.6-rc4/drivers/i2c/i2c-core.c 2012-09-08 09:36:13.538537033 +0200
> @@ -637,6 +637,22 @@ static void i2c_adapter_dev_release(stru
> }
>
> /*
> + * This function is only needed for mutex_lock_nested, so it is never
> + * called unless locking correctness checking is enabled. Thus we
> + * make it inline to avoid a compiler warning. That's what gcc ends up
> + * doing anyway.
> + */
> +static inline unsigned int i2c_adapter_depth(struct i2c_adapter *adapter)
> +{
> + unsigned int depth = 0;
> +
> + while ((adapter = i2c_parent_is_i2c_adapter(adapter)))
> + depth++;
> +
> + return depth;
> +}
> +
> +/*
> * Let users instantiate I2C devices through sysfs. This can be used when
> * platform initialization code doesn't contain the proper data for
> * whatever reason. Also useful for drivers that do device detection and
> @@ -726,7 +742,8 @@ i2c_sysfs_delete_device(struct device *d
>
> /* Make sure the device was added through sysfs */
> res = -ENOENT;
> - mutex_lock(&adap->userspace_clients_lock);
> + mutex_lock_nested(&adap->userspace_clients_lock,
> + i2c_adapter_depth(adap));
> list_for_each_entry_safe(client, next, &adap->userspace_clients,
> detected) {
> if (client->addr == addr) {
> @@ -1073,7 +1090,8 @@ int i2c_del_adapter(struct i2c_adapter *
> return res;
>
> /* Remove devices instantiated from sysfs */
> - mutex_lock(&adap->userspace_clients_lock);
> + mutex_lock_nested(&adap->userspace_clients_lock,
> + i2c_adapter_depth(adap));
> list_for_each_entry_safe(client, next, &adap->userspace_clients,
> detected) {
> dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name,
>
>
prev parent reply other threads:[~2012-09-10 12:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-08 7:38 [PATCH v3] i2c-core: Fix for lockdep validator Jean Delvare
[not found] ` <20120908093814.21c1174d-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-09-10 12:55 ` Michael Lawnick [this message]
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=504DE326.8080706@gmx.de \
--to=ml.lawnick-mmb7mzphnfy@public.gmane.org \
--cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox