nbd: avoid losing the pointer to reallocated config->socks in nbd_add_socket()
Subsystems (2)
PATCH 1/1 nbd: avoid losing the pointer to reallocated config->socks in nbd_add_socket()
In the (very unlikely) case of config->socks reallocation success and nsock allocation failure config->nsock will not get updated with the new pointer to socks array. Fix it by updating config->socks right after reallocation successfulness check.
Fixes 9561a7ade0c2 ("nbd: add multi-connection support")
Signed-off-by Eugene Syromiatnikov <[email protected]>
Cc [email protected] # 4.10+
--- drivers/block/nbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/nbd.c +2 -2
@@ -951,14 +951,14 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,sockfd_put (sock);return -ENOMEM ; } + config->socks = socks; + nsock =kzalloc (sizeof (struct nbd_sock ),GFP_KERNEL );if (!nsock) {sockfd_put (sock);return -ENOMEM ; } - config->socks = socks; - nsock->fallback_index =-1 ; nsock->dead = false;mutex_init (&nsock->tx_lock);
Signature · 1 line
2.1.4