mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: oleg.drokin@intel.com, andreas.dilger@intel.com,
	gdonald@gmail.com, keith.mannthey@intel.com,
	john.hammond@intel.com, devel@driverdev.osuosl.org,
	HPDD-discuss@ml01.01.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance
Date: Wed, 26 Nov 2014 12:54:43 -0800	[thread overview]
Message-ID: <20141126205443.GB10615@kroah.com> (raw)
In-Reply-To: <02a457cec587341d0f1665491f6360323694b008.1417017302.git.loic@loicp.eu>

On Wed, Nov 26, 2014 at 05:15:48PM +0100, Loic Pefferkorn wrote:
> Add __acquires() and __releases() function annotations, to fix sparse warnings related to lock context imbalance.
> 
> This fixes the following warnings:
> 
> drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c:153:5: warning: context imbalance in 'cfs_trace_lock_tcd' - wrong count at exit
> drivers/staging/lustre/lustre/libcfs/hash.c:128:1: warning: context imbalance in 'cfs_hash_spin_lock' - wrong count at exit
> drivers/staging/lustre/lustre/libcfs/hash.c:142:9: warning: context imbalance in 'cfs_hash_rw_lock' - wrong count at exit
> drivers/staging/lustre/lustre/ptlrpc/../../lustre/ldlm/l_lock.c:57:17: warning: context imbalance in 'lock_res_and_lock' - wrong count at exit
> drivers/staging/lustre/lustre/libcfs/libcfs_lock.c:93:1: warning: context imbalance in 'cfs_percpt_lock' - wrong count at exit
> 
> Signed-off-by: Loic Pefferkorn <loic@loicp.eu>
> ---
>  drivers/staging/lustre/lustre/libcfs/hash.c                  | 4 ++++
>  drivers/staging/lustre/lustre/libcfs/libcfs_lock.c           | 2 ++
>  drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c | 2 ++
>  drivers/staging/lustre/lustre/obdclass/cl_object.c           | 2 ++
>  4 files changed, 10 insertions(+)
> 
> diff --git a/drivers/staging/lustre/lustre/libcfs/hash.c b/drivers/staging/lustre/lustre/libcfs/hash.c
> index 32da783..7c6e2a3 100644
> --- a/drivers/staging/lustre/lustre/libcfs/hash.c
> +++ b/drivers/staging/lustre/lustre/libcfs/hash.c
> @@ -126,18 +126,21 @@ cfs_hash_nl_unlock(union cfs_hash_lock *lock, int exclusive) {}
>  
>  static inline void
>  cfs_hash_spin_lock(union cfs_hash_lock *lock, int exclusive)
> +	__acquires(&lock->spin)
>  {
>  	spin_lock(&lock->spin);
>  }
>  
>  static inline void
>  cfs_hash_spin_unlock(union cfs_hash_lock *lock, int exclusive)
> +	__releases(&lock->spin)
>  {
>  	spin_unlock(&lock->spin);
>  }

Ugh, how horrid, please just delete these functions and push down the
spin_lock/unlock calls down into the places these are called.

>  
>  static inline void
>  cfs_hash_rw_lock(union cfs_hash_lock *lock, int exclusive)
> +	__acquires(&lock->rw)
>  {
>  	if (!exclusive)
>  		read_lock(&lock->rw);
> @@ -147,6 +150,7 @@ cfs_hash_rw_lock(union cfs_hash_lock *lock, int exclusive)
>  
>  static inline void
>  cfs_hash_rw_unlock(union cfs_hash_lock *lock, int exclusive)
> +	__releases(&lock->rw)
>  {
>  	if (!exclusive)
>  		read_unlock(&lock->rw);


Same for these.

> diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c b/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
> index 2c199c7..1e529fc 100644
> --- a/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
> +++ b/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
> @@ -91,6 +91,7 @@ EXPORT_SYMBOL(cfs_percpt_lock_alloc);
>   */
>  void
>  cfs_percpt_lock(struct cfs_percpt_lock *pcl, int index)
> +	__acquires(pcl->pcl_locks[index])
>  {
>  	int	ncpt = cfs_cpt_number(pcl->pcl_cptab);
>  	int	i;
> @@ -125,6 +126,7 @@ EXPORT_SYMBOL(cfs_percpt_lock);
>  /** unlock a CPU partition */
>  void
>  cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index)
> +	__releases(pcl->pcl_locks[index])
>  {
>  	int	ncpt = cfs_cpt_number(pcl->pcl_cptab);
>  	int	i;
> diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
> index 976c61e..257669b 100644
> --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
> +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
> @@ -151,6 +151,7 @@ cfs_trace_buf_type_t cfs_trace_buf_idx_get(void)
>   * for details.
>   */
>  int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
> +	__acquires(&tcd->tc_lock)
>  {
>  	__LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX);
>  	if (tcd->tcd_type == CFS_TCD_TYPE_IRQ)
> @@ -165,6 +166,7 @@ int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
>  }
>  
>  void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
> +	__releases(&tcd->tcd_lock)
>  {
>  	__LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX);
>  	if (tcd->tcd_type == CFS_TCD_TYPE_IRQ)
> diff --git a/drivers/staging/lustre/lustre/obdclass/cl_object.c b/drivers/staging/lustre/lustre/obdclass/cl_object.c
> index ce96bd2..8577f97 100644
> --- a/drivers/staging/lustre/lustre/obdclass/cl_object.c
> +++ b/drivers/staging/lustre/lustre/obdclass/cl_object.c
> @@ -193,6 +193,7 @@ static spinlock_t *cl_object_attr_guard(struct cl_object *o)
>   * cl_object_attr_get(), cl_object_attr_set().
>   */
>  void cl_object_attr_lock(struct cl_object *o)
> +	__acquires(cl_object_attr_guard(o))
>  {
>  	spin_lock(cl_object_attr_guard(o));
>  }
> @@ -202,6 +203,7 @@ EXPORT_SYMBOL(cl_object_attr_lock);
>   * Releases data-attributes lock, acquired by cl_object_attr_lock().
>   */
>  void cl_object_attr_unlock(struct cl_object *o)
> +	__releases(cl_object_attr_guard(o))
>  {
>  	spin_unlock(cl_object_attr_guard(o));
>  }

Same thing here.


  reply	other threads:[~2014-11-26 20:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-26 16:15 Loic Pefferkorn
2014-11-26 20:54 ` Greg KH [this message]
2014-11-27  5:30   ` Loïc Pefferkorn
2014-11-27 18:34   ` Loïc Pefferkorn
2014-11-28 10:00     ` Dan Carpenter
2014-11-28 15:45       ` [HPDD-discuss] " Patrick Farrell
2014-11-28 16:28         ` Dan Carpenter
2014-11-28 22:22     ` Greg KH
2014-11-30 19:54       ` Loïc Pefferkorn

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=20141126205443.GB10615@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=HPDD-discuss@ml01.01.org \
    --cc=andreas.dilger@intel.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gdonald@gmail.com \
    --cc=john.hammond@intel.com \
    --cc=keith.mannthey@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg.drokin@intel.com \
    /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

all inboxes | Powered by JetHome®