Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422643AbbEVNiX (ORCPT ); Fri, 22 May 2015 09:38:23 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:31299 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932451AbbEVNiV (ORCPT ); Fri, 22 May 2015 09:38:21 -0400 Date: Fri, 22 May 2015 16:38:03 +0300 From: Dan Carpenter To: "Dilger, Andreas" Cc: "open list:STAGING SUBSYSTEM" , Greg Donald , Adrian Remonda , open list , "Drokin, Oleg" , Julia Lawall , Greg Kroah-Hartman , "moderated list:STAGING - LUSTRE..." , Joe Perches Subject: Re: [PATCH 4/4] Staging: lustre: sparse lock warning fix Message-ID: <20150522133803.GP4150@mwanda> References: <1431974091-26363-1-git-send-email-adrianremonda@gmail.com> <1431974091-26363-2-git-send-email-adrianremonda@gmail.com> <1431974091-26363-3-git-send-email-adrianremonda@gmail.com> <1431974091-26363-4-git-send-email-adrianremonda@gmail.com> <1431974091-26363-5-git-send-email-adrianremonda@gmail.com> <20150518212115.GN14154@mwanda> <20150520192924.GS22558@mwanda> <20150520194243.GG4150@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1967 Lines: 56 On Wed, May 20, 2015 at 10:51:34PM +0000, Dilger, Andreas wrote: > On 2015/05/20, 1:42 PM, "Dan Carpenter" wrote: > > >In Smatch, it the equivalent warning is turned off by default because > >there are too many false positives, but you can enable it with the > >--spammy flag. > > > >kchecker --spammy drivers/staging/lustre/lustre/ptlrpc/nrs.c > > > >drivers/staging/lustre/lustre/ptlrpc/nrs.c:512 nrs_resource_put_safe() > >warn: 'spin_lock:&nrs->nrs_lock' is sometimes locked here and sometimes > >unlocked. > > Would this be happier with something like: > > for (i = 0; i < NRS_RES_MAX; i++) { > if (pols[i] == NULL) > continue; > > > if (nrs == NULL) { > nrs = pols[i]->pol_nrs; > if (likely(nrs != NULL)) /* make sparse happy */ > spin_lock(&nrs->nrs_lock); > } > nrs_policy_put_locked(pols[i]); > } > > if (nrs != NULL) > spin_unlock(&nrs->nrs_lock); > > so that the "if" conditions are the same? The code definitely doesn't > have a bug, because the lock is only locked once when nrs is first set, > and only unlocked if it is set. Or is there a comment to put there that > will quiet the static checker? Forget about Sparse, it's good at some things and it's fast but it has crappy flow analysis compared to Smatch. Adding that check does actually silence the warning in Smatch but it's a bad idea. Smatch is supposed to know that "nrs" is non-NULL because of the dereference on the next line. I think this is a recent regression. I'll look into it. Smatch doesn't have a way to silence false positives. It's still developing, so many of these false positives can be solved by improving the flow analysis. regards, dan carpenter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/