summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-07-17 13:16:14 +0200
committerSimon Rettberg2020-07-17 13:16:14 +0200
commitbc19e0cfb04517cfb7da5d891dc880f52a296126 (patch)
treea1eef2c19e815b406c0afaf3da07ed2baa61d154
parentconfig.h: Lower serializer len to 800 for now (diff)
downloaddnbd3-ng-bc19e0cfb04517cfb7da5d891dc880f52a296126.tar.gz
dnbd3-ng-bc19e0cfb04517cfb7da5d891dc880f52a296126.tar.xz
dnbd3-ng-bc19e0cfb04517cfb7da5d891dc880f52a296126.zip
[KERNEL] Properly bail out on kmalloc failures
-rw-r--r--src/kernel/net-txrx.c7
-rw-r--r--src/kernel/net.c2
2 files changed, 5 insertions, 4 deletions
diff --git a/src/kernel/net-txrx.c b/src/kernel/net-txrx.c
index 82f7408..c839561 100644
--- a/src/kernel/net-txrx.c
+++ b/src/kernel/net-txrx.c
@@ -202,8 +202,7 @@ int dnbd3_send_request_cmd(struct dnbd3_sock *sock, uint16_t dnbd3_cmd)
struct request *req = kmalloc(sizeof(struct request), GFP_KERNEL);
if (!req) {
error_sock(sock, "kmalloc failed");
- result = -EIO;
- goto error;
+ return -ENOMEM;
}
switch (dnbd3_cmd) {
@@ -282,7 +281,7 @@ int dnbd3_receive_cmd(struct dnbd3_sock *sock, dnbd3_reply_t *reply)
// buf = kmalloc(RTT_BLOCK_SIZE, GFP_KERNEL);
// if (!buf) {
// error_sock(sock, "kmalloc failed");
-// return -EIO;
+// return -ENOMEM;
// }
// iov.iov_base = buf;
// iov.iov_len = RTT_BLOCK_SIZE;
@@ -417,7 +416,7 @@ int dnbd3_receive_cmd_get_block_test(struct dnbd3_sock *sock,
char *buf = kmalloc(reply->size, GFP_KERNEL);
if (!buf) {
error_sock(sock, "kmalloc failed");
- goto error;
+ return -ENOMEM;
}
dnbd3_init_msghdr(msg);
diff --git a/src/kernel/net.c b/src/kernel/net.c
index 7058b8b..7654bdc 100644
--- a/src/kernel/net.c
+++ b/src/kernel/net.c
@@ -281,6 +281,7 @@ static int dnbd3_adjust_connections(struct dnbd3_device *dev) {
GFP_KERNEL);
if (!plan) {
error_dev(dev, "kmalloc failed");
+ return -ENOMEM;
}
if (servers && servers[0]->host.type != 0) {
@@ -802,6 +803,7 @@ int dnbd3_net_connect(struct dnbd3_device *dev)
dev->number_connections, GFP_KERNEL);
if (!dev->socks) {
error_dev(dev, "kmalloc failed");
+ return -ENOMEM;
}
memset(dev->socks, 0, sizeof(struct dnbd3_sock) *
dev->number_connections);