Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4264171pxb; Mon, 1 Feb 2021 17:39:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbo/PARWR0ZQEgyEk3XGvRwQutImoXRigp2qLnena+0edDRSrPABNUo1y7a7Z4bmqKdLlS X-Received: by 2002:a17:906:2495:: with SMTP id e21mr3438147ejb.280.1612229985026; Mon, 01 Feb 2021 17:39:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612229985; cv=none; d=google.com; s=arc-20160816; b=Qv1hnyEb37byIO0TvSnzInuhvOv7JrOelSzDB/4r6q4vuV0UuBNm1tGaMRGzCx3nez RVlp1S+xjR+X1hauhHs+pgkXMgnD2xXxE6nuMBG7yKgHC8sG1I2wHXt19DkvpY+6tQuD Eqfn4KM7PO4Vo3pzQF5IRDQuw6jRd7B3nTaHQ1vcJGpKC316jFQ2yqstmYAdWm6xlYBm zWrwkze5dpgWGEx5s5SOC8yaOuPyL/+2qsFClUb274DNZ7iDCAPSnKMY6A6xHbU4TcST ZjknGJ3OSKI7+7qEUN/MpjAYNsSgfos/ZEtix5G4wsHhyOH/AsUv/9AH4huzyWP7FnSp s+qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=8IVLNbwluGXYVq227GfHAXmKar9MBZT2qZ9hamCDacA=; b=WNqtdN7AtpGgXBEj1ju1ZKPQhHCpTps8UL5jb9oUavEFgaUneztXdQogVJAk+KdS/t mtKbBIZrb9T1KA9WlAdONXo5/8fL0JHjWt1+gbOJEimxRRAf1rukYZdt7PfpsUpoxShS Y+vsQMus/7Jplabm8te8US7aYl5LCI4pxTTV5HLoMu3FuXXcDa44PTVGcz+AhjZutyYe dCQxO7OQ0wtwprEepEUbxxod/K5n5DhBpt8i2nW6S61fMtT7bTByClwkMOaTgaWEl0gL JHGp27TavTE+dHJxrizr/xlg2YZi9s3w24qLhBZ49SDcW9ZyVm3aGIjnHQG3TD0689wK 2e/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ji7si12163432ejc.617.2021.02.01.17.39.20; Mon, 01 Feb 2021 17:39:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231285AbhBBBhl (ORCPT + 99 others); Mon, 1 Feb 2021 20:37:41 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:11657 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbhBBBhk (ORCPT ); Mon, 1 Feb 2021 20:37:40 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DV6p26rrnz162xB; Tue, 2 Feb 2021 09:35:38 +0800 (CST) Received: from [10.174.179.80] (10.174.179.80) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.498.0; Tue, 2 Feb 2021 09:36:54 +0800 Subject: Re: [PATCH v2] nbd: Fix NULL pointer in flush_workqueue To: Markus Elfring , Josef Bacik , Jens Axboe , , CC: , References: <20210201081918.558905-1-sunke32@huawei.com> From: Sun Ke Message-ID: <68668f92-b605-3abf-9e9a-cddf6444f478@huawei.com> Date: Tue, 2 Feb 2021 09:36:54 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.80] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org hi,Markus 在 2021/2/2 3:05, Markus Elfring 写道: > … >> +++ b/drivers/block/nbd.c >> @@ -2011,12 +2011,14 @@ static int nbd_genl_disconnect(struct sk_buff *skb, struct genl_info *info) >> index); >> return -EINVAL; >> } >> + mutex_lock(&nbd->config_lock); >> if (!refcount_inc_not_zero(&nbd->refs)) { >> - mutex_unlock(&nbd_index_mutex); >> - printk(KERN_ERR "nbd: device at index %d is going down\n", >> - index); >> - return -EINVAL; >> + goto unlock; >> } >> + if (!nbd->recv_workq) { >> + goto unlock; >> + } > How do you think about to use the following patch variant > (so that unwanted curly brackets would be avoided for proposed single statements > in two if branches)? > > + mutex_lock(&nbd->config_lock); > - if (!refcount_inc_not_zero(&nbd->refs)) { > + if (!refcount_inc_not_zero(&nbd->refs) || !nbd->recv_workq) { > + mutex_unlock(&nbd->config_lock); > mutex_unlock(&nbd_index_mutex); > printk(KERN_ERR "nbd: device at index %d is going down\n",tter > index); > return -EINVAL; > } It looks better,  thanks for your suggestion. > > By the way: > Would you like to replace the following two statements by the statement > “goto put_nbd;” in another update step for this function implementation? > > nbd_put(nbd); > return 0; Sure, I will do it. > > Regards, > Markus Thanks, Sun Ke > .