drm/sched: Adjustments for drm_sched_init()
Subsystems (4)
cover drm/sched: Adjustments for drm_sched_init()
From: Markus Elfring <[email protected]>
Date: Tue, 26 Dec 2023 16:48:48 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
One function call less after error detection
Return an error code only as a constant
drivers/gpu/drm/scheduler/sched_main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
--
2.43.0
PATCH 1/2 drm/sched: One function call less in drm_sched_init() after error detection
From: Markus Elfring <[email protected]>
Date: Tue, 26 Dec 2023 16:30:25 +0100
The kfree() function was called in one case by the drm_sched_init() function during error handling
even if the passed data structure member contained a null pointer. This issue was detected by using the Coccinelle software.
Thus adjust a jump target.
--- drivers/gpu/drm/scheduler/sched_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +3 -2
@@ -1289,7 +1289,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, sched->sched_rq =kmalloc_array (num_rqs,sizeof (*sched->sched_rq),GFP_KERNEL | __GFP_ZERO);if (!sched->sched_rq) - goto Out_free; + goto Out_check_own; sched->num_rqs = num_rqs;for (i =DRM_SCHED_PRIORITY_KERNEL ; i < sched->num_rqs; i++) { sched->sched_rq[i] =kzalloc (sizeof (*sched->sched_rq[i]),GFP_KERNEL );
@@ -1314,9 +1314,10 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, Out_unroll:for (--i ; i >=DRM_SCHED_PRIORITY_KERNEL ; i--)kfree (sched->sched_rq[i]); -Out_free: +kfree (sched->sched_rq); sched->sched_rq =NULL ; +Out_check_own:if (sched->own_submit_wq)destroy_workqueue (sched->submit_wq);drm_err (sched,"%s: Failed to setup GPU scheduler--out of memory\n" , __func__);
--
2.43.0
Re: [PATCH 1/2] drm/sched: One function call less in drm_sched_init() after error detection
Quoted 11 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 26 Dec 2023 16:30:25 +0100The
kfree()function was called in one case by thedrm_sched_init()function during error handling
even if the passed data structure member contained a null pointer. This issue was detected by using the Coccinelle software.Thus adjust a jump target.
Signed-off-by Markus Elfring <[email protected]>
Thank you Markus for this patch.
Pushed to drm-misc-next.
Signature · 2 lines
Regards, Luben
Quoted 32 lines
--- drivers/gpu/drm/scheduler/sched_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/gpu/drm/scheduler/sched_main.c +3
-3@@ -1289,7 +1289,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, sched->sched_rq =kmalloc_array (num_rqs,sizeof (*sched->sched_rq),GFP_KERNEL | __GFP_ZERO);if (!sched->sched_rq) - goto Out_free; + goto Out_check_own; sched->num_rqs = num_rqs;for (i =DRM_SCHED_PRIORITY_KERNEL ; i < sched->num_rqs; i++) { sched->sched_rq[i] =kzalloc (sizeof (*sched->sched_rq[i]),GFP_KERNEL );@@ -1314,9 +1314,10 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, Out_unroll:for (--i ; i >=DRM_SCHED_PRIORITY_KERNEL ; i--)kfree (sched->sched_rq[i]); -Out_free: +kfree (sched->sched_rq); sched->sched_rq =NULL ; +Out_check_own:if (sched->own_submit_wq)destroy_workqueue (sched->submit_wq);drm_err (sched,"%s: Failed to setup GPU scheduler--out of memory\n" , __func__); --2.43.0
PATCH 2/2 drm/sched: Return an error code only as a constant in drm_sched_init()
In reply to Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 26 Dec 2023 16:37:37 +0100
Return an error code without storing it in an intermediate variable.
--- drivers/gpu/drm/scheduler/sched_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +3 -3
@@ -1249,7 +1249,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, long timeout, struct workqueue_struct *timeout_wq, atomic_t *score, const char *name, struct device *dev) { - int i, ret; + int i; sched->ops = ops; sched->credit_limit = credit_limit;
@@ -1285,7 +1285,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, sched->own_submit_wq = true; } - ret = -ENOMEM ; + sched->sched_rq =kmalloc_array (num_rqs,sizeof (*sched->sched_rq),GFP_KERNEL | __GFP_ZERO);if (!sched->sched_rq)
@@ -1321,7 +1321,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,if (sched->own_submit_wq)destroy_workqueue (sched->submit_wq);drm_err (sched,"%s: Failed to setup GPU scheduler--out of memory\n" , __func__); -return ret; +return -ENOMEM ; }EXPORT_SYMBOL (drm_sched_init);
--
2.43.0
Re: [PATCH 2/2] drm/sched: Return an error code only as a constant in drm_sched_init()
Quoted 6 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 26 Dec 2023 16:37:37 +0100Return an error code without storing it in an intermediate variable.
Signed-off-by Markus Elfring <[email protected]>
Thank you Markus for this patch.
Pushed to drm-misc-next.
Signature · 2 lines
Regards, Luben
Quoted 38 lines
--- drivers/gpu/drm/scheduler/sched_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/scheduler/sched_main.c +3
-4@@ -1249,7 +1249,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, long timeout, struct workqueue_struct *timeout_wq, atomic_t *score, const char *name, struct device *dev) { - int i, ret; + int i; sched->ops = ops; sched->credit_limit = credit_limit;@@ -1285,7 +1285,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, sched->own_submit_wq = true; } - ret = -ENOMEM ; + sched->sched_rq =kmalloc_array (num_rqs,sizeof (*sched->sched_rq),GFP_KERNEL | __GFP_ZERO);if (!sched->sched_rq)@@ -1321,7 +1321,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,if (sched->own_submit_wq)destroy_workqueue (sched->submit_wq);drm_err (sched,"%s: Failed to setup GPU scheduler--out of memory\n" , __func__); -return ret; +return -ENOMEM ; }EXPORT_SYMBOL (drm_sched_init); --2.43.0