Commit fe53d2ae authored by Ritesh Harjani (IBM)'s avatar Ritesh Harjani (IBM) Committed by Madhavan Srinivasan
Browse files

pseries/papr-hvpipe: Refactor and simplify hvpipe_rtas_recv_msg()



Simplify hvpipe_rtas_recv_msg() by removing three levels of nesting...
if (!ret)
    if (buf)
	if (size < bytes_written)
... this refactoring of the function bails out to "out:" label first, in case
of any error. This simplifies the init flow.

Signed-off-by: default avatarRitesh Harjani (IBM) <ritesh.list@gmail.com>
Signed-off-by: default avatarMadhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/bbe7ddf8b8e25c9be8fc5e2c4aea9e5fca128bf4.1777606826.git.ritesh.list@gmail.com
parent 4e2d83c8
Loading
Loading
Loading
Loading
+26 −26
Original line number Diff line number Diff line
@@ -190,9 +190,6 @@ static int hvpipe_rtas_recv_msg(char __user *buf, int size)
		return -ENOMEM;
	}

	ret = rtas_ibm_receive_hvpipe_msg(work_area, &srcID,
					&bytes_written);
	if (!ret) {
	/*
	 * Recv HVPIPE RTAS is successful.
	 * When releasing FD or no one is waiting on the
@@ -200,24 +197,27 @@ static int hvpipe_rtas_recv_msg(char __user *buf, int size)
	 * so that pipe is not blocked - this func is called
	 * with NULL buf.
	 */
		if (buf) {
	ret = rtas_ibm_receive_hvpipe_msg(work_area, &srcID, &bytes_written);
	if (ret) {
		pr_err("ibm,receive-hvpipe-msg failed with %d\n", ret);
		goto out;
	}

	if (!buf)
		goto out;

	if (size < bytes_written) {
		pr_err("Received the payload size = %d, but the buffer size = %d\n",
				bytes_written, size);
		bytes_written = size;
	}
			if (copy_to_user(buf,
					rtas_work_area_raw_buf(work_area),
					bytes_written))

	if (copy_to_user(buf, rtas_work_area_raw_buf(work_area), bytes_written))
		ret = -EFAULT;
	else
		ret = bytes_written;
		}
	} else {
		pr_err("ibm,receive-hvpipe-msg failed with %d\n",
				ret);
	}

out:
	rtas_work_area_free(work_area);
	return ret;
}