linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frediano Ziglio <fziglio@redhat.com>
To: fziglio@redhat.com, spice-devel@lists.freedesktop.org,
	airlied@linux.ie, dri-devel@lists.freedesktop.org,
	airlied@redhat.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 11/11] Propagate correctly errors from qxlhw_handle_to_bo
Date: Wed, 27 May 2015 11:04:06 +0100	[thread overview]
Message-ID: <1432721046-4418-12-git-send-email-fziglio@redhat.com> (raw)
In-Reply-To: <1432721046-4418-1-git-send-email-fziglio@redhat.com>

This function could return a NULL pointer in case of handle not
present and in case of out of memory conditions however caller
function always returned EINVAL error hiding a possible ENOMEM.
This patch change the function to return the error instead to
be able to propagate the error instead of assuming EINVAL.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 qxl/qxl_ioctl.c | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/qxl/qxl_ioctl.c b/qxl/qxl_ioctl.c
index bb326ff..37f1faf 100644
--- a/qxl/qxl_ioctl.c
+++ b/qxl/qxl_ioctl.c
@@ -107,9 +107,9 @@ apply_surf_reloc(struct qxl_device *qdev, struct qxl_reloc_info *info)
 }
 
 /* return holding the reference to this object */
-static struct qxl_bo *qxlhw_handle_to_bo(struct qxl_device *qdev,
-					 struct drm_file *file_priv, uint64_t handle,
-					 struct qxl_release *release)
+static int qxlhw_handle_to_bo(struct qxl_device *qdev,
+			      struct drm_file *file_priv, uint64_t handle,
+			      struct qxl_release *release, struct qxl_bo **qbo_p)
 {
 	struct drm_gem_object *gobj;
 	struct qxl_bo *qobj;
@@ -117,16 +117,17 @@ static struct qxl_bo *qxlhw_handle_to_bo(struct qxl_device *qdev,
 
 	gobj = drm_gem_object_lookup(qdev->ddev, file_priv, handle);
 	if (!gobj)
-		return NULL;
+		return -EINVAL;
 
 	qobj = gem_to_qxl_bo(gobj);
 
 	ret = qxl_release_list_add(release, qobj);
 	drm_gem_object_unreference_unlocked(gobj);
 	if (ret)
-		return NULL;
+		return ret;
 
-	return qobj;
+	*qbo_p = qobj;
+	return 0;
 }
 
 /*
@@ -219,13 +220,10 @@ static int qxl_process_single_command(struct qxl_device *qdev,
 		reloc_info[i].type = reloc.reloc_type;
 
 		if (reloc.dst_handle) {
-			reloc_info[i].dst_bo = qxlhw_handle_to_bo(qdev, file_priv,
-								  reloc.dst_handle, release);
-			if (!reloc_info[i].dst_bo) {
-				ret = -EINVAL;
-				reloc_info[i].src_bo = NULL;
+			ret = qxlhw_handle_to_bo(qdev, file_priv, reloc.dst_handle, release,
+						 &reloc_info[i].dst_bo);
+			if (ret)
 				goto out_free_bos;
-			}
 			reloc_info[i].dst_offset = reloc.dst_offset;
 		} else {
 			reloc_info[i].dst_bo = cmd_bo;
@@ -234,14 +232,11 @@ static int qxl_process_single_command(struct qxl_device *qdev,
 		num_relocs++;
 
 		/* reserve and validate the reloc dst bo */
-		if (reloc.reloc_type == QXL_RELOC_TYPE_BO || reloc.src_handle > 0) {
-			reloc_info[i].src_bo =
-				qxlhw_handle_to_bo(qdev, file_priv,
-						   reloc.src_handle, release);
-			if (!reloc_info[i].src_bo) {
-				ret = -EINVAL;
+		if (reloc.reloc_type == QXL_RELOC_TYPE_BO || reloc.src_handle) {
+			ret = qxlhw_handle_to_bo(qdev, file_priv, reloc.src_handle, release,
+						 &reloc_info[i].src_bo);
+			if (ret)
 				goto out_free_bos;
-			}
 			reloc_info[i].src_offset = reloc.src_offset;
 		} else {
 			reloc_info[i].src_bo = NULL;
-- 
2.1.0


  parent reply	other threads:[~2015-05-27 10:05 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-27 10:03 [PATCH 00/11] Miscellaneous stability patches Frediano Ziglio
2015-05-27 10:03 ` [PATCH 01/11] Do not cause spice-server to clean our objects Frediano Ziglio
2015-05-28  3:08   ` [Spice-devel] " Dave Airlie
2015-05-27 10:03 ` [PATCH 02/11] Do not leak memory if qxl_release_list_add fails Frediano Ziglio
2015-05-28  3:09   ` [Spice-devel] " Dave Airlie
2015-05-27 10:03 ` [PATCH 03/11] Fix print statement not using uninitialized variable Frediano Ziglio
2015-05-28  3:10   ` [Spice-devel] " Dave Airlie
2015-05-27 10:03 ` [PATCH 04/11] Avoid double free on error Frediano Ziglio
2015-05-28  3:11   ` [Spice-devel] " Dave Airlie
2015-05-27 10:04 ` [PATCH 05/11] Handle all errors in qxl_surface_evict Frediano Ziglio
2015-05-28  3:16   ` [Spice-devel] " Dave Airlie
2015-05-27 10:04 ` [PATCH 06/11] Fix return for qxl_release_alloc Frediano Ziglio
2015-05-28  3:17   ` [Spice-devel] " Dave Airlie
2015-05-27 10:04 ` [PATCH 07/11] Handle correctly failures in qxl_alloc_relase_reserved Frediano Ziglio
2015-05-28  3:20   ` [Spice-devel] " Dave Airlie
2015-05-27 10:04 ` [PATCH 08/11] Remove format string errors Frediano Ziglio
2015-05-28  3:20   ` [Spice-devel] " Dave Airlie
2015-05-27 10:04 ` [PATCH 09/11] Move main reference counter to GEM object instead of TTM ones Frediano Ziglio
2015-05-28  3:31   ` [Spice-devel] " Dave Airlie
2015-05-29 11:11     ` Frediano Ziglio
2015-05-27 10:04 ` [PATCH 10/11] Simplify cleaning qxl processing command Frediano Ziglio
2015-05-28  3:32   ` [Spice-devel] " Dave Airlie
2015-05-27 10:04 ` Frediano Ziglio [this message]
2015-05-28  3:33   ` [Spice-devel] [PATCH 11/11] Propagate correctly errors from qxlhw_handle_to_bo Dave Airlie
2015-05-27 12:47 ` [PATCH 00/11] Miscellaneous stability patches Josh Boyer
2015-05-27 12:49   ` Josh Boyer
2015-05-27 13:28     ` Frediano Ziglio
2015-05-28  3:07       ` [Spice-devel] " Dave Airlie
2015-05-28 14:10         ` Frediano Ziglio
2015-05-29  5:48           ` Frans Klaver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1432721046-4418-12-git-send-email-fziglio@redhat.com \
    --to=fziglio@redhat.com \
    --cc=airlied@linux.ie \
    --cc=airlied@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=spice-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).