From: Gao Xiang <hsiangkao@aol.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
xiang@kernel.org, linux-erofs@lists.ozlabs.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [bug report] staging: erofs: tidy up decompression frontend
Date: Fri, 15 Nov 2019 08:45:14 +0800 [thread overview]
Message-ID: <20191115004512.GA7969@hsiangkao-HP-ZHAN-66-Pro-G1> (raw)
Message-ID: <20191115004514.7TIkSUorgDEJ1mSCFfH9qKOYaZdNvM25NmyXBmLV6_0@z> (raw)
In-Reply-To: <20191114220015.GA20752@bombadil.infradead.org>
Hi Dan and Matthew,
On Thu, Nov 14, 2019 at 02:00:15PM -0800, Matthew Wilcox wrote:
> On Thu, Nov 14, 2019 at 10:10:03PM +0300, Dan Carpenter wrote:
> > fs/erofs/zdata.c:443 z_erofs_register_collection()
> > error: double unlocked 'cl->lock' (orig line 439)
> >
> > fs/erofs/zdata.c
> > 432 cl = z_erofs_primarycollection(pcl);
> > 433 cl->pageofs = map->m_la & ~PAGE_MASK;
> > 434
> > 435 /*
> > 436 * lock all primary followed works before visible to others
> > 437 * and mutex_trylock *never* fails for a new pcluster.
> > 438 */
> > 439 mutex_trylock(&cl->lock);
> > ^^^^^^^^^^^^^^^^^^^^^^^^
> > 440
> > 441 err = erofs_register_workgroup(inode->i_sb, &pcl->obj, 0);
> > 442 if (err) {
> > 443 mutex_unlock(&cl->lock);
> > ^^^^^^^^^^^^^^^^^^^^^^^
> > How can we unlock if we don't know that the trylock succeeded?
>
> The comment says it'll always succeed. That said, this is an uncommon
> pattern -- usually we just mutex_lock(). If there's a good reason to use
> mutex_trylock() instead, then I'd prefer it to be guarded with a BUG_ON.
>
I think there is no actual problem here. If I am wrong, please kindly point out.
The selected code snippet is too short. The current full code is
static struct z_erofs_collection *clregister(struct z_erofs_collector *clt,
struct inode *inode,
struct erofs_map_blocks *map)
{
struct z_erofs_pcluster *pcl;
struct z_erofs_collection *cl;
int err;
/* no available workgroup, let's allocate one */
pcl = kmem_cache_alloc(pcluster_cachep, GFP_NOFS);
if (!pcl)
return ERR_PTR(-ENOMEM);
^ Note that this is a new object here, which is guaranteed that the lock
was always unlocked with the last free (and it firstly inited in init_once).
z_erofs_pcluster_init_always(pcl);
pcl->obj.index = map->m_pa >> PAGE_SHIFT;
pcl->length = (map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT) |
(map->m_flags & EROFS_MAP_FULL_MAPPED ?
Z_EROFS_PCLUSTER_FULL_LENGTH : 0);
if (map->m_flags & EROFS_MAP_ZIPPED)
pcl->algorithmformat = Z_EROFS_COMPRESSION_LZ4;
else
pcl->algorithmformat = Z_EROFS_COMPRESSION_SHIFTED;
pcl->clusterbits = EROFS_I(inode)->z_physical_clusterbits[0];
pcl->clusterbits -= PAGE_SHIFT;
/* new pclusters should be claimed as type 1, primary and followed */
pcl->next = clt->owned_head;
clt->mode = COLLECT_PRIMARY_FOLLOWED;
cl = z_erofs_primarycollection(pcl);
cl->pageofs = map->m_la & ~PAGE_MASK;
/*
* lock all primary followed works before visible to others
* and mutex_trylock *never* fails for a new pcluster.
*/
mutex_trylock(&cl->lock);
^ That was simply once guarded by BUG_ON, but checkpatch.pl raised a warning,
I can use DBG_BUGON here instead.
err = erofs_register_workgroup(inode->i_sb, &pcl->obj, 0);
if (err) {
mutex_unlock(&cl->lock);
^ free with unlock as a convention as one example above.
kmem_cache_free(pcluster_cachep, pcl);
return ERR_PTR(-EAGAIN);
}
Thanks,
Gao Xiang
next prev parent reply other threads:[~2019-11-15 0:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-14 19:10 [bug report] staging: erofs: tidy up decompression frontend Dan Carpenter
2019-11-14 22:00 ` Matthew Wilcox
2019-11-15 0:45 ` Gao Xiang via Linux-erofs [this message]
2019-11-15 0:45 ` Gao Xiang
-- strict thread matches above, loose matches on Subject: below --
2019-08-27 9:03 Dan Carpenter
2019-08-27 9:36 ` Gao Xiang
2019-08-27 9:53 ` Dan Carpenter
2019-08-27 10:05 ` Gao Xiang
2019-08-27 10:42 ` Dan Carpenter
2019-08-27 10:46 ` Gao Xiang
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=20191115004512.GA7969@hsiangkao-HP-ZHAN-66-Pro-G1 \
--to=hsiangkao@aol.com \
--cc=dan.carpenter@oracle.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=willy@infradead.org \
--cc=xiang@kernel.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;
as well as URLs for NNTP newsgroup(s).