Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3604075pxb; Sun, 31 Jan 2021 22:49:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJyP7er3koSz0/vYgUMEOUEWNB8wiiE/TeDyC08Zt5lRKqIpKuMqQEix5QvXyk56Bge7yd8t X-Received: by 2002:a50:b246:: with SMTP id o64mr16615734edd.132.1612162184946; Sun, 31 Jan 2021 22:49:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612162184; cv=none; d=google.com; s=arc-20160816; b=of8z+utZqKo+zptqISDmwVfiQLc+rI/vOoOGGrW8RW0lxGwYtscRZTIMgMA5eGHlJ+ XuXvCOI8nZUlkI8rzPKuOmhyXfJ3sRJ3biLbpVMgx+TDDbYjW9ilpGOBUJV3+e1CN3Nv N1ApdDLMXLkFklaOS76T8V/pqRJbXK2ZhchtrOlt1yS2+SNIRKHqDKAwn+CTs5dLUv5H GbHgpOHm9DZKIHNR/jtj5ZtFFhjDrmM71LKJXaPn6lryLbQ+uZQb/UAn7hEuly1X691g 3sARRPtP9T+xqKFXPUj6PblNW0loSvgGEJvg+imfQ1PAhvujnSkBP/x0Xbs4hSwDXcSQ MJLw== 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=aA8D+fdU8iERRIrlkC1J8nqJvoIhY9eCoSyhIPyvMPo=; b=BGiU7helc/25y4V36oPezteJm1Mbbvh8LXxWsbmMwnls4SHM2uiSfmPwgSMuVik9Ve Eaon9jG1yU8BEA6O8TXTHd6/XhkeYL3xHg2CgXaGUX4kW9EszZWxZUU71KISrPN22t93 taiJdpyL0NA1ZeQifuyyKUBBR9NSm4j0khDalJb6NqANrrj0S5Rr+kyyq1wJFd+4rxYC xtg8fhAGlECzxfVflETdEUzRu+swaZg8cD0EpT9Ju6paF6jiaeva6s9WkixUjGLiyAmp IJQyzvXqf0FFOAOpAGvc0Hbwnl4559nTa8YFntLBe+wPbuQxM95Ajkhbu4L4saC6Wbq8 VplA== 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 l24si755109eje.495.2021.01.31.22.49.20; Sun, 31 Jan 2021 22:49:44 -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 S230159AbhBAGsL (ORCPT + 99 others); Mon, 1 Feb 2021 01:48:11 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:11650 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232272AbhBAGnw (ORCPT ); Mon, 1 Feb 2021 01:43:52 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DTddk6LW6z162QB; Mon, 1 Feb 2021 14:41:46 +0800 (CST) Received: from [10.174.179.80] (10.174.179.80) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.498.0; Mon, 1 Feb 2021 14:43:01 +0800 Subject: Re: [PATCH] nbd: Fix NULL pointer in flush_workqueue To: Markus Elfring , , CC: , , "Jens Axboe" , Josef Bacik References: <20210128074153.1633374-1-sunke32@huawei.com> <1739e522-5980-f86e-cb90-19b61539a5cf@web.de> From: Sun Ke Message-ID: <28c83b00-7d0b-ee0d-640b-017c9f8410eb@huawei.com> Date: Mon, 1 Feb 2021 14:43:00 +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: <1739e522-5980-f86e-cb90-19b61539a5cf@web.de> 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/1/29 3:42, Markus Elfring 写道: > … >> +++ b/drivers/block/nbd.c >> @@ -2011,12 +2011,20 @@ 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); >> + mutex_unlock(&nbd->config_lock); > Can an other function call order become relevant for the unlocking of these mutexes? Do you think the nbd->config_lock  mutex here is useless? > > >> printk(KERN_ERR "nbd: device at index %d is going down\n", >> index); > May such an error message be moved into the lock scope? Sure. > > >> return -EINVAL; >> } >> + if (!nbd->recv_workq) { >> + mutex_unlock(&nbd->config_lock); >> + mutex_unlock(&nbd_index_mutex); >> + return -EINVAL; >> + } > How do you think about to connect the code from this if branch > with a jump target like “unlock” so that such statements would be shareable > for the desired exception handling? OK, I will improve it in V2 patch. > > >> + mutex_unlock(&nbd->config_lock); >> mutex_unlock(&nbd_index_mutex); >> if (!refcount_inc_not_zero(&nbd->config_refs)) { >> nbd_put(nbd); > > Regards, > Markus > .