If we add first socket to nbd, config->socks is malloced butI suggest to improve this change description.
num_connections does not update(nsock's allocation fail), the memory
is leaked. Cause in later nbd_config_put(), will only free config->socks
when num_connections is not 0.
Let nsock's allocation first to avoid this.
Can an other wording variant be nicer?
â
+++ b/drivers/block/nbd.cPlease use the following code variant.
@@ -1037,21 +1037,22 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
return -EBUSY;
}
+ nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL);
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=4333a9b0b67bb4e8bcd91bdd80da80b0ec151162#n854
+ nsock = kzalloc(sizeof(*nsock), GFP_KERNEL);
â
if (!socks) {Please take another software design possibility into account.
sockfd_put(sock);
+ kfree(nsock);
return -ENOMEM;
}
if (!socks) {
- sockfd_put(sock);
- return -ENOMEM;
+ kfree(nsock);
+ goto put_socket;
}
Regards,
Markus
.