Re: [PATCH] nbd: Fix NULL pointer in flush_workqueue

From: Sun Ke
Date: Mon Feb 01 2021 - 01:48:32 EST


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
.