diff mbox series

[2/2] libceph: add error handling code for osd_req_op_xattr_init()

Message ID 20180822142438.31632-2-cgxu519@gmx.com (mailing list archive)
State New, archived
Headers show
Series [1/2] libceph: add error handling code for osd_req_op_cls_init() | expand

Commit Message

Chengguang Xu Aug. 22, 2018, 2:24 p.m. UTC
Without reservation, ceph_pagelist_append() may fail with error -ENOMEM,
so catch the error in osd_req_op_xattr_init() to avoid unexpected behavior.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 net/ceph/osd_client.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 2a84bd39b3ba..89bf2f3fbdbf 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -821,6 +821,7 @@  int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
 						      opcode, 0);
 	struct ceph_pagelist *pagelist;
 	size_t payload_len;
+	int err;
 
 	BUG_ON(opcode != CEPH_OSD_OP_SETXATTR && opcode != CEPH_OSD_OP_CMPXATTR);
 
@@ -832,10 +833,14 @@  int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
 
 	payload_len = strlen(name);
 	op->xattr.name_len = payload_len;
-	ceph_pagelist_append(pagelist, name, payload_len);
+	err = ceph_pagelist_append(pagelist, name, payload_len);
+	if (err < 0)
+		goto out_free;
 
 	op->xattr.value_len = size;
-	ceph_pagelist_append(pagelist, value, size);
+	err = ceph_pagelist_append(pagelist, value, size);
+	if (err < 0)
+		goto out_free;
 	payload_len += size;
 
 	op->xattr.cmp_op = cmp_op;
@@ -844,6 +849,10 @@  int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
 	ceph_osd_data_pagelist_init(&op->xattr.osd_data, pagelist);
 	op->indata_len = payload_len;
 	return 0;
+
+out_free:
+	ceph_pagelist_release(pagelist);
+	return err;
 }
 EXPORT_SYMBOL(osd_req_op_xattr_init);