Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	kernel-janitors@vger.kernel.org,
	"Daniel Vetter" <daniel.vetter@ffwll.ch>,
	"David Airlie" <airlied@gmail.com>,
	"Faith Ekstrand" <faith.ekstrand@collabora.com>,
	"Francois Dugast" <francois.dugast@intel.com>,
	"Jani Nikula" <jani.nikula@intel.com>,
	"José Roberto de Souza" <jose.souza@intel.com>,
	"Lucas De Marchi" <lucas.demarchi@intel.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Matt Roper" <matthew.d.roper@intel.com>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Nirmoy Das" <nirmoy.das@intel.com>,
	"Philippe Lecluse" <philippe.lecluse@intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Thomas Zimmermann" <tzimmermann@suse.de>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] drm/xe/query: Refactor copy_to_user() usage in four functions
Date: Wed, 18 Sep 2024 10:12:14 +0200	[thread overview]
Message-ID: <d1f1eb7f-1de7-4d73-a7d0-00cc1eac3d5d@web.de> (raw)

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 18 Sep 2024 09:43:07 +0200

Assign return values from copy_to_user() calls to additional local variables
so that four kfree() calls and return statements can be omitted accordingly.

This issue was transformed by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/gpu/drm/xe/xe_query.c | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_query.c b/drivers/gpu/drm/xe/xe_query.c
index 5246a4a2740e..6195e720176d 100644
--- a/drivers/gpu/drm/xe/xe_query.c
+++ b/drivers/gpu/drm/xe/xe_query.c
@@ -220,13 +220,11 @@ static int query_engines(struct xe_device *xe,

 	engines->num_engines = i;

-	if (copy_to_user(query_ptr, engines, size)) {
+	{
+		unsigned long ctu = copy_to_user(query_ptr, engines, size);
 		kfree(engines);
-		return -EFAULT;
+		return ctu ? -EFAULT : 0;
 	}
-	kfree(engines);
-
-	return 0;
 }

 static size_t calc_mem_regions_size(struct xe_device *xe)
@@ -344,13 +342,11 @@ static int query_config(struct xe_device *xe, struct drm_xe_device_query *query)
 	config->info[DRM_XE_QUERY_CONFIG_MAX_EXEC_QUEUE_PRIORITY] =
 		xe_exec_queue_device_get_max_priority(xe);

-	if (copy_to_user(query_ptr, config, size)) {
+	{
+		unsigned long ctu = copy_to_user(query_ptr, config, size);
 		kfree(config);
-		return -EFAULT;
+		return ctu ? -EFAULT : 0;
 	}
-	kfree(config);
-
-	return 0;
 }

 static int query_gt_list(struct xe_device *xe, struct drm_xe_device_query *query)
@@ -414,13 +410,11 @@ static int query_gt_list(struct xe_device *xe, struct drm_xe_device_query *query
 			REG_FIELD_GET(GMD_ID_REVID, gt->info.gmdid);
 	}

-	if (copy_to_user(query_ptr, gt_list, size)) {
+	{
+		unsigned long ctu = copy_to_user(query_ptr, gt_list, size);
 		kfree(gt_list);
-		return -EFAULT;
+		return ctu ? -EFAULT : 0;
 	}
-	kfree(gt_list);
-
-	return 0;
 }

 static int query_hwconfig(struct xe_device *xe,
@@ -444,13 +438,11 @@ static int query_hwconfig(struct xe_device *xe,

 	xe_guc_hwconfig_copy(&gt->uc.guc, hwconfig);

-	if (copy_to_user(query_ptr, hwconfig, size)) {
+	{
+		unsigned long ctu = copy_to_user(query_ptr, hwconfig, size);
 		kfree(hwconfig);
-		return -EFAULT;
+		return ctu ? -EFAULT : 0;
 	}
-	kfree(hwconfig);
-
-	return 0;
 }

 static size_t calc_topo_query_size(struct xe_device *xe)
--
2.46.0


             reply	other threads:[~2024-09-23 12:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-18  8:12 Markus Elfring [this message]
2024-09-18  9:29 ` [PATCH] drm/xe/query: Refactor copy_to_user() usage in four functions Jani Nikula
2024-09-18  9:38   ` Markus Elfring
2024-09-25 19:28 ` ✓ CI.Patch_applied: success for " Patchwork
2024-09-25 19:28 ` ✗ CI.checkpatch: warning " Patchwork
2024-09-25 19:30 ` ✓ CI.KUnit: success " Patchwork
2024-09-25 19:41 ` ✓ CI.Build: " Patchwork
2024-09-25 19:43 ` ✓ CI.Hooks: " Patchwork
2024-09-25 19:45 ` ✓ CI.checksparse: " Patchwork
2024-09-25 20:04 ` ✗ CI.BAT: failure " Patchwork
2024-09-25 21:53 ` ✗ CI.FULL: " Patchwork

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=d1f1eb7f-1de7-4d73-a7d0-00cc1eac3d5d@web.de \
    --to=markus.elfring@web.de \
    --cc=airlied@gmail.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=faith.ekstrand@collabora.com \
    --cc=francois.dugast@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    --cc=jose.souza@intel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matthew.brost@intel.com \
    --cc=matthew.d.roper@intel.com \
    --cc=mchehab@kernel.org \
    --cc=mripard@kernel.org \
    --cc=nirmoy.das@intel.com \
    --cc=philippe.lecluse@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona@ffwll.ch \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tzimmermann@suse.de \
    /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