[PATCH v2] drm/i915: Fix memory leak by correcting cache object name in error handler

2024-05-13 Thread Jiasheng Jiang
Replace "slab_priorities" with "slab_dependencies" in the error handler
to avoid memory leak.

Fixes: 32eb6bcfdda9 ("drm/i915: Make request allocation caches global")
Cc:  # v5.2+
Reviewed-by: Nirmoy Das 
Signed-off-by: Jiasheng Jiang 
---
Changelog:

v1 -> v2:

1. Alter the subject.
---
 drivers/gpu/drm/i915/i915_scheduler.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_scheduler.c 
b/drivers/gpu/drm/i915/i915_scheduler.c
index 762127dd56c5..70a854557e6e 100644
--- a/drivers/gpu/drm/i915/i915_scheduler.c
+++ b/drivers/gpu/drm/i915/i915_scheduler.c
@@ -506,6 +506,6 @@ int __init i915_scheduler_module_init(void)
return 0;
 
 err_priorities:
-   kmem_cache_destroy(slab_priorities);
+   kmem_cache_destroy(slab_dependencies);
return -ENOMEM;
 }
-- 
2.25.1



[PATCH v2] drm/i915: Fix memory leak by correcting cache object name in error handler

2024-05-13 Thread Jiasheng Jiang
Replace "slab_priorities" with "slab_dependencies" in the error handler
to avoid memory leak.

Fixes: 32eb6bcfdda9 ("drm/i915: Make request allocation caches global")
Signed-off-by: Jiasheng Jiang 
---
Changelog:

v1 -> v2:

1. Alter the subject.
---
 drivers/gpu/drm/i915/i915_scheduler.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_scheduler.c 
b/drivers/gpu/drm/i915/i915_scheduler.c
index 762127dd56c5..70a854557e6e 100644
--- a/drivers/gpu/drm/i915/i915_scheduler.c
+++ b/drivers/gpu/drm/i915/i915_scheduler.c
@@ -506,6 +506,6 @@ int __init i915_scheduler_module_init(void)
return 0;
 
 err_priorities:
-   kmem_cache_destroy(slab_priorities);
+   kmem_cache_destroy(slab_dependencies);
return -ENOMEM;
 }
-- 
2.25.1



[PATCH] drm/i915: Correct error handler

2024-05-13 Thread Jiasheng Jiang
> On 5/11/2024 5:48 PM, Jiasheng Jiang wrote:
>> Replace "slab_priorities" with "slab_dependencies" in the error handler to 
>> avoid memory leak.
> 
> Nice catch. I would make the subject more like:
> 
> drm/i915: Fix memory leak by correcting cache object name in error handler
> 
>>
>> Fixes: 32eb6bcfdda9 ("drm/i915: Make request allocation caches global")
> 
> Also need Cc:  # v5.2+
> 
> With those:
> 
> Reviewed-by: Nirmoy Das 
> 
> 
> Nirmoy

Thanks.
I will submit a v2.

- Jiasheng


[PATCH] drm/i915: Correct error handler

2024-05-13 Thread Jiasheng Jiang
> On 5/11/2024 5:48 PM, Jiasheng Jiang wrote:
>> Replace "slab_priorities" with "slab_dependencies" in the error handler to 
>> avoid memory leak.
> 
> Nice catch. I would make the subject more like:
> 
> drm/i915: Fix memory leak by correcting cache object name in error handler
> 
>>
>> Fixes: 32eb6bcfdda9 ("drm/i915: Make request allocation caches global")
> 
> Also need Cc:  # v5.2+
> 
> With those:
> 
> Reviewed-by: Nirmoy Das 
> 
> 
> Nirmoy

Thanks.
I will submit a v2.

- Jiasheng


[PATCH] drm/i915: Correct error handler

2024-05-11 Thread Jiasheng Jiang
Replace "slab_priorities" with "slab_dependencies" in the error handler to 
avoid memory leak.

Fixes: 32eb6bcfdda9 ("drm/i915: Make request allocation caches global")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/i915/i915_scheduler.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_scheduler.c 
b/drivers/gpu/drm/i915/i915_scheduler.c
index 762127dd56c5..70a854557e6e 100644
--- a/drivers/gpu/drm/i915/i915_scheduler.c
+++ b/drivers/gpu/drm/i915/i915_scheduler.c
@@ -506,6 +506,6 @@ int __init i915_scheduler_module_init(void)
return 0;
 
 err_priorities:
-   kmem_cache_destroy(slab_priorities);
+   kmem_cache_destroy(slab_dependencies);
return -ENOMEM;
 }
-- 
2.25.1



[PATCH] drm/i915: Correct error handler

2024-05-11 Thread Jiasheng Jiang
From: Jiasheng Jiang 

Replace "slab_priorities" with "slab_dependencies" in the error handler
to avoid memory leak.

Fixes: 32eb6bcfdda9 ("drm/i915: Make request allocation caches global")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/i915/i915_scheduler.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_scheduler.c 
b/drivers/gpu/drm/i915/i915_scheduler.c
index 762127dd56c5..70a854557e6e 100644
--- a/drivers/gpu/drm/i915/i915_scheduler.c
+++ b/drivers/gpu/drm/i915/i915_scheduler.c
@@ -506,6 +506,6 @@ int __init i915_scheduler_module_init(void)
return 0;
 
 err_priorities:
-   kmem_cache_destroy(slab_priorities);
+   kmem_cache_destroy(slab_dependencies);
return -ENOMEM;
 }
-- 
2.25.1



Re: [PATCH] drm/i915: Correct error handler

2024-05-11 Thread Jiasheng Jiang
Maybe the format is incorrect. I would like to use 
"jiashengjiangc...@outlook.com" to resend my patch.

-Jiasheng

____
From: Jiasheng Jiang
Sent: Saturday, May 11, 2024 3:40
To: jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com; 
rodrigo.v...@intel.com; tursu...@ursulin.net; airl...@gmail.com; 
dan...@ffwll.ch; ch...@chris-wilson.co.uk
Cc: intel-...@lists.freedesktop.org; dri-devel@lists.freedesktop.org; 
linux-ker...@vger.kernel.org
Subject: [PATCH] drm/i915: Correct error handler

Replace "slab_priorities" with "slab_dependencies" in the error handler
to avoid memory leak.

Fixes: 32eb6bcfdda9 ("drm/i915: Make request allocation caches global")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/i915/i915_scheduler.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_scheduler.c 
b/drivers/gpu/drm/i915/i915_scheduler.c
index 762127dd56c5..70a854557e6e 100644
--- a/drivers/gpu/drm/i915/i915_scheduler.c
+++ b/drivers/gpu/drm/i915/i915_scheduler.c
@@ -506,6 +506,6 @@ int __init i915_scheduler_module_init(void)
return 0;

 err_priorities:
-   kmem_cache_destroy(slab_priorities);
+   kmem_cache_destroy(slab_dependencies);
return -ENOMEM;
 }
--
2.25.1



[PATCH] drm/i915: Correct error handler

2024-05-10 Thread Jiasheng Jiang
Replace "slab_priorities" with "slab_dependencies" in the error handler
to avoid memory leak.

Fixes: 32eb6bcfdda9 ("drm/i915: Make request allocation caches global")
Signed-off-by: Jiasheng Jiang 
---
drivers/gpu/drm/i915/i915_scheduler.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_scheduler.c 
b/drivers/gpu/drm/i915/i915_scheduler.c
index 762127dd56c5..70a854557e6e 100644
--- a/drivers/gpu/drm/i915/i915_scheduler.c
+++ b/drivers/gpu/drm/i915/i915_scheduler.c
@@ -506,6 +506,6 @@ int __init i915_scheduler_module_init(void)
   return 0;
 err_priorities:
-  kmem_cache_destroy(slab_priorities);
+  kmem_cache_destroy(slab_dependencies);
   return -ENOMEM;
}
--
2.25.1



[PATCH] drm/i915: Correct error handler

2024-05-10 Thread Jiasheng Jiang
Replace "slab_priorities" with "slab_dependencies" in the error handler
to avoid memory leak.

Fixes: 32eb6bcfdda9 ("drm/i915: Make request allocation caches global")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/i915/i915_scheduler.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_scheduler.c 
b/drivers/gpu/drm/i915/i915_scheduler.c
index 762127dd56c5..70a854557e6e 100644
--- a/drivers/gpu/drm/i915/i915_scheduler.c
+++ b/drivers/gpu/drm/i915/i915_scheduler.c
@@ -506,6 +506,6 @@ int __init i915_scheduler_module_init(void)
return 0;
 
 err_priorities:
-   kmem_cache_destroy(slab_priorities);
+   kmem_cache_destroy(slab_dependencies);
return -ENOMEM;
 }
-- 
2.25.1



[PATCH] drm/i915/gem: Add check for bitmap_zalloc()

2023-07-27 Thread Jiasheng Jiang
Add the check for the return value of bitmap_zalloc() in order to
guarantee the success of the allocation.

Fixes: e9b73c67390a ("drm/i915: Reduce memory pressure during shrinker by 
preallocating swizzle pages")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/i915/gem/i915_gem_tiling.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_tiling.c 
b/drivers/gpu/drm/i915/gem/i915_gem_tiling.c
index a049ca0b7980..e9cf99d95966 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_tiling.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_tiling.c
@@ -311,6 +311,11 @@ i915_gem_object_set_tiling(struct drm_i915_gem_object *obj,
if (!obj->bit_17) {
obj->bit_17 = bitmap_zalloc(obj->base.size >> 
PAGE_SHIFT,
GFP_KERNEL);
+   if (!obj->bit_17) {
+   i915_gem_object_unlock(obj);
+   i915_gem_object_release_mmap_gtt(obj);
+   return -ENOMEM;
+   }
}
} else {
bitmap_free(obj->bit_17);
-- 
2.25.1



[PATCH] drm: xlnx: zynqmp_dpsub: Add missing check for dma_set_mask

2023-06-06 Thread Jiasheng Jiang
Add check for dma_set_mask() and return the error if it fails.

Fixes: d76271d22694 ("drm: xlnx: DRM/KMS driver for Xilinx ZynqMP DisplayPort 
Subsystem")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/xlnx/zynqmp_dpsub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xlnx/zynqmp_dpsub.c 
b/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
index bab862484d42..068413be6527 100644
--- a/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
+++ b/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
@@ -227,7 +227,9 @@ static int zynqmp_dpsub_probe(struct platform_device *pdev)
dpsub->dev = &pdev->dev;
platform_set_drvdata(pdev, dpsub);
 
-   dma_set_mask(dpsub->dev, DMA_BIT_MASK(ZYNQMP_DISP_MAX_DMA_BIT));
+   ret = dma_set_mask(dpsub->dev, DMA_BIT_MASK(ZYNQMP_DISP_MAX_DMA_BIT));
+   if (ret)
+   return ret;
 
/* Try the reserved memory. Proceed if there's none. */
of_reserved_mem_device_init(&pdev->dev);
-- 
2.25.1



Re: [PATCH 01/10] Revert "drm/msm: Add missing check and destroy for alloc_ordered_workqueue"

2023-03-07 Thread Jiasheng Jiang
On Mon, 06 Mar 2023 18:07:13 +0800, Johan Hovold wrote:
> This reverts commit 643b7d0869cc7f1f7a5ac7ca6bd25d88f54e31d0.

The commit not only adds the allocation sanity check, but also adds the
destroy_workqueue to release the allocated priv->wq.
Therefore, revert the commit will cause memory leak.

> A recent patch that tried to fix up the msm_drm_init() paths with
> respect to the workqueue but only ended up making things worse:
> 
> First, the newly added calls to msm_drm_uninit() on early errors would
> trigger NULL-pointer dereferences, for example, as the kms pointer would
> not have been initialised. (Note that these paths were also modified by
> a second broken error handling patch which in effect cancelled out this
> part when merged.)

There is a check for the kms pointer to avoid NULL-pointer dereference in
the msm_drm_uninit().

> Second, the newly added allocation sanity check would still leak the
> previously allocated drm device.

The ddev is allocated by drm_dev_alloc which support automatic cleanup.

Thanks,
Jiang



Re: [PATCH 1/2] drm: Add DRM-managed alloc_workqueue() and alloc_ordered_workqueue()

2023-01-17 Thread Jiasheng Jiang
> On Tue, Jan 10, 2023 at 11:24:47PM +0800, Jiasheng Jiang wrote:
>> Add drmm_alloc_workqueue() and drmm_alloc_ordered_workqueue(), the helpers
>> that provide managed workqueue cleanup. The workqueue will be destroyed
>> with the final reference of the DRM device.
>> 
>> Signed-off-by: Jiasheng Jiang 
> 
> Yeah I think this looks nice.
> 
> Reviewed-by: Daniel Vetter 
> 
> I'm assuming driver maintainers will pick this up, if not please holler.
> 
> Also the threading seems broken, it's not a patch series. The b4 tool or
> git send-email (of all the patches of the entire series at once, not each
> individually) should get this right.
> 
> Unfortunately I did't find the right link in the kernel docs, or at least
> they're not as detailed as I hoped.
> 
> Also your previous submission had iirc a bunch more patches, do you plan
> to include them all in the next patch set?

I have found that some previous patches have already been applied.
Need I just convert alloc*workqueue into drmm_alloc*workqueue and remove
the destroy_workqueue?
Or need I convert all the alloc*workqueue in the DRM?

Thanks,
Jiang



[PATCH v2] drm/msm/dsi: Drop the redundant fail label

2023-01-10 Thread Jiasheng Jiang
Drop the redundant fail label and change the "goto fail" into "return ret"
since they are the same.

Reviewed-by: Doug Anderson 
Signed-off-by: Jiasheng Jiang 
---
Changelog:

v1 -> v2:

1. No change of the error handling of the irq_of_parse_and_map.
---
 drivers/gpu/drm/msm/dsi/dsi_host.c | 24 
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c 
b/drivers/gpu/drm/msm/dsi/dsi_host.c
index 89aadd3b3202..de615c505def 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -1883,8 +1883,7 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
 
msm_host = devm_kzalloc(&pdev->dev, sizeof(*msm_host), GFP_KERNEL);
if (!msm_host) {
-   ret = -ENOMEM;
-   goto fail;
+   return -ENOMEM;
}
 
msm_host->pdev = pdev;
@@ -1893,31 +1892,28 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
ret = dsi_host_parse_dt(msm_host);
if (ret) {
pr_err("%s: failed to parse dt\n", __func__);
-   goto fail;
+   return ret;
}
 
msm_host->ctrl_base = msm_ioremap_size(pdev, "dsi_ctrl", 
&msm_host->ctrl_size);
if (IS_ERR(msm_host->ctrl_base)) {
pr_err("%s: unable to map Dsi ctrl base\n", __func__);
-   ret = PTR_ERR(msm_host->ctrl_base);
-   goto fail;
+   return PTR_ERR(msm_host->ctrl_base);
}
 
pm_runtime_enable(&pdev->dev);
 
msm_host->cfg_hnd = dsi_get_config(msm_host);
if (!msm_host->cfg_hnd) {
-   ret = -EINVAL;
pr_err("%s: get config failed\n", __func__);
-   goto fail;
+   return -EINVAL;
}
cfg = msm_host->cfg_hnd->cfg;
 
msm_host->id = dsi_host_get_id(msm_host);
if (msm_host->id < 0) {
-   ret = msm_host->id;
pr_err("%s: unable to identify DSI host index\n", __func__);
-   goto fail;
+   return msm_host->id;
}
 
/* fixup base address by io offset */
@@ -1927,19 +1923,18 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
cfg->regulator_data,
&msm_host->supplies);
if (ret)
-   goto fail;
+   return ret;
 
ret = dsi_clk_init(msm_host);
if (ret) {
pr_err("%s: unable to initialize dsi clks\n", __func__);
-   goto fail;
+   return ret;
}
 
msm_host->rx_buf = devm_kzalloc(&pdev->dev, SZ_4K, GFP_KERNEL);
if (!msm_host->rx_buf) {
-   ret = -ENOMEM;
pr_err("%s: alloc rx temp buf failed\n", __func__);
-   goto fail;
+   return -ENOMEM;
}
 
ret = devm_pm_opp_set_clkname(&pdev->dev, "byte");
@@ -1983,9 +1978,6 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
 
DBG("Dsi Host %d initialized", msm_host->id);
return 0;
-
-fail:
-   return ret;
 }
 
 void msm_dsi_host_destroy(struct mipi_dsi_host *host)
-- 
2.25.1



[PATCH 2/2 v2] drm/i915: Replace alloc*workqueue with DRM helpers

2023-01-10 Thread Jiasheng Jiang
Replace alloc*workqueue with DRM helpers in order to avoid memory leak
Because in `drivers/gpu/drm/i915/i915_driver.c`, if
intel_modeset_init_noirq fails, its workqueues will not be destroyed.
And drop the destroy_workqueue in intel_modeset_driver_remove_noirq to
avoid double free.
Moreover, check the return value since the workqueue may be NULL and
cause NULL pointer dereference.

Fixes: c26a058680dc ("drm/i915: Use a high priority wq for nonblocking plane 
updates")
Fixes: 757fffcfdffb ("drm/i915: Put all non-blocking modesets onto an ordered 
wq")
Signed-off-by: Jiasheng Jiang 
---
Changelog:

v1 -> v2:

1. Drop the destroy_workqueue in intel_modeset_driver_remove_noirq.
---
 drivers/gpu/drm/i915/display/intel_display.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display.c 
b/drivers/gpu/drm/i915/display/intel_display.c
index 6c2686ecb62a..5cbec0af1773 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -8654,9 +8655,16 @@ int intel_modeset_init_noirq(struct drm_i915_private 
*i915)
 
intel_dmc_ucode_init(i915);
 
-   i915->display.wq.modeset = alloc_ordered_workqueue("i915_modeset", 0);
-   i915->display.wq.flip = alloc_workqueue("i915_flip", WQ_HIGHPRI |
-   WQ_UNBOUND, 
WQ_UNBOUND_MAX_ACTIVE);
+   ret = drmm_alloc_ordered_workqueue(&i915->drm,
+  i915->display.wq.modeset, 
"i915_modeset", 0);
+   if (ret)
+   goto cleanup_vga_client_pw_domain_dmc;
+
+   ret = drmm_alloc_workqueue(&i915->drm, i915->display.wq.flip,
+  "i915_flip", WQ_HIGHPRI | WQ_UNBOUND,
+  WQ_UNBOUND_MAX_ACTIVE);
+   if (ret)
+   goto cleanup_vga_client_pw_domain_dmc;
 
intel_mode_config_init(i915);
 
@@ -9004,9 +9012,6 @@ void intel_modeset_driver_remove_noirq(struct 
drm_i915_private *i915)
 
intel_gmbus_teardown(i915);
 
-   destroy_workqueue(i915->display.wq.flip);
-   destroy_workqueue(i915->display.wq.modeset);
-
intel_fbc_cleanup(i915);
 }
 
-- 
2.25.1



Re: [PATCH] drm/i915: Add missing check and destroy for alloc_workqueue

2023-01-10 Thread Jiasheng Jiang
On Sat, Jan 07, 2023 at 02:29:22AM +0800, Daniel Vetter wrote:
>On Fri, Jan 06, 2023 at 05:09:34PM +0800, Jiasheng Jiang wrote:
>> Add checks for the return value of alloc_workqueue and
>> alloc_ordered_workqueue as they may return NULL pointer and cause NULL
>> pointer dereference.
>> Moreover, destroy them when fails later in order to avoid memory leak.
>> Because in `drivers/gpu/drm/i915/i915_driver.c`, if
>> intel_modeset_init_noirq fails, its workqueues will not be destroyed.
>> 
>> Fixes: c26a058680dc ("drm/i915: Use a high priority wq for nonblocking plane 
>> updates")
>> Fixes: 757fffcfdffb ("drm/i915: Put all non-blocking modesets onto an 
>> ordered wq")
>> Signed-off-by: Jiasheng Jiang 
> 
> So you have an entire pile of these, and I think that's a really good
> excuse to
> - create a drmm_alloc_workqueue helper for these (and
>   drmm_alloc_ordered_workqueue) using the drmm_add_action_or_reset()
>   function for automatic drm_device cleanup
> - use that instead in all drivers, which means you do not have to make any
>   error handling mor complex
> 
> Up for that? In that case please also convert any existing alloc*workqueue
> callsites in drm, and make this all a patch series (since then there would
> be dependencies).

Fine, I have submitted two patches. The first one create the
drmm_alloc_workqueue and drmm_alloc_ordered_workqueue helpers. And the
second one replace the alloc*workqueue with DRM helpers in
`drivers/gpu/drm/i915/display/intel_display.c`.
If there is no problem in these two, I will submitted the other patches
that replace the alloc*workqueue in other DRM files.

Thanks,
Jiang



[PATCH 2/2] drm/i915: Replace alloc*workqueue with DRM helpers

2023-01-10 Thread Jiasheng Jiang
Replace alloc*workqueue with DRM helpers in order to avoid memory leak.
Moreover, check the return value since the workqueue may be NULL and
cause NULL pointer dereference.

Fixes: c26a058680dc ("drm/i915: Use a high priority wq for nonblocking plane 
updates")
Fixes: 757fffcfdffb ("drm/i915: Put all non-blocking modesets onto an ordered 
wq")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/i915/display/intel_display.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display.c 
b/drivers/gpu/drm/i915/display/intel_display.c
index 6c2686ecb62a..8acef38ca985 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -8654,9 +8655,16 @@ int intel_modeset_init_noirq(struct drm_i915_private 
*i915)
 
intel_dmc_ucode_init(i915);
 
-   i915->display.wq.modeset = alloc_ordered_workqueue("i915_modeset", 0);
-   i915->display.wq.flip = alloc_workqueue("i915_flip", WQ_HIGHPRI |
-   WQ_UNBOUND, 
WQ_UNBOUND_MAX_ACTIVE);
+   ret = drmm_alloc_ordered_workqueue(&i915->drm,
+  i915->display.wq.modeset, 
"i915_modeset", 0);
+   if (ret)
+   goto cleanup_vga_client_pw_domain_dmc;
+
+   ret = drmm_alloc_workqueue(&i915->drm, i915->display.wq.flip,
+  "i915_flip", WQ_HIGHPRI | WQ_UNBOUND,
+  WQ_UNBOUND_MAX_ACTIVE);
+   if (ret)
+   goto cleanup_vga_client_pw_domain_dmc;
 
intel_mode_config_init(i915);
 
-- 
2.25.1



[PATCH 1/2] drm: Add DRM-managed alloc_workqueue() and alloc_ordered_workqueue()

2023-01-10 Thread Jiasheng Jiang
Add drmm_alloc_workqueue() and drmm_alloc_ordered_workqueue(), the helpers
that provide managed workqueue cleanup. The workqueue will be destroyed
with the final reference of the DRM device.

Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/drm_managed.c | 66 +++
 include/drm/drm_managed.h |  8 +
 2 files changed, 74 insertions(+)

diff --git a/drivers/gpu/drm/drm_managed.c b/drivers/gpu/drm/drm_managed.c
index 4cf214de50c4..d3bd6247eec9 100644
--- a/drivers/gpu/drm/drm_managed.c
+++ b/drivers/gpu/drm/drm_managed.c
@@ -271,6 +271,13 @@ static void drmm_mutex_release(struct drm_device *dev, 
void *res)
mutex_destroy(lock);
 }
 
+static void drmm_destroy_workqueue(struct drm_device *dev, void *res)
+{
+   struct workqueue_struct *wq = res;
+
+   destroy_workqueue(wq);
+}
+
 /**
  * drmm_mutex_init - &drm_device-managed mutex_init()
  * @dev: DRM device
@@ -289,3 +296,62 @@ int drmm_mutex_init(struct drm_device *dev, struct mutex 
*lock)
return drmm_add_action_or_reset(dev, drmm_mutex_release, lock);
 }
 EXPORT_SYMBOL(drmm_mutex_init);
+
+/**
+ * drmm_alloc_workqueue - &drm_device-managed alloc_workqueue()
+ * @dev: DRM device
+ * @wq: workqueue to be allocated
+ *
+ * Returns:
+ * 0 on success, or a negative errno code otherwise.
+ *
+ * This is a &drm_device-managed version of alloc_workqueue().
+ * The initialized lock is automatically destroyed on the final
+ * drm_dev_put().
+ */
+int drmm_alloc_workqueue(struct drm_device *dev,
+ struct workqueue_struct *wq, const char *fmt,
+ unsigned int flags, int max_active, ...)
+{
+   va_list args;
+
+   va_start(args, max_active);
+   wq = alloc_workqueue(fmt, flags, max_active, args);
+   va_end(args);
+
+   if (!wq)
+   return -ENOMEM;
+
+   return drmm_add_action_or_reset(dev, drmm_destroy_workqueue, wq);
+}
+EXPORT_SYMBOL(drmm_alloc_workqueue);
+
+/**
+ * drmm_alloc_ordered_workqueue - &drm_device-managed
+ * alloc_ordered_workqueue()
+ * @dev: DRM device
+ * @wq: workqueue to be allocated
+ *
+ * Returns:
+ * 0 on success, or a negative errno code otherwise.
+ *
+ * This is a &drm_device-managed version of alloc_ordered_workqueue().
+ * The initialized lock is automatically destroyed on the final
+ * drm_dev_put().
+ */
+int drmm_alloc_ordered_workqueue(struct drm_device *dev,
+ struct workqueue_struct *wq,
+ const char *fmt, unsigned int flags, ...)
+{
+   va_list args;
+
+   va_start(args, flags);
+   wq = alloc_ordered_workqueue(fmt, flags, args);
+   va_end(args);
+
+   if (!wq)
+   return -ENOMEM;
+
+   return drmm_add_action_or_reset(dev, drmm_destroy_workqueue, wq);
+}
+EXPORT_SYMBOL(drmm_alloc_ordered_workqueue);
diff --git a/include/drm/drm_managed.h b/include/drm/drm_managed.h
index 359883942612..68cecc14e1af 100644
--- a/include/drm/drm_managed.h
+++ b/include/drm/drm_managed.h
@@ -107,4 +107,12 @@ void drmm_kfree(struct drm_device *dev, void *data);
 
 int drmm_mutex_init(struct drm_device *dev, struct mutex *lock);
 
+int drmm_alloc_workqueue(struct drm_device *dev,
+ struct workqueue_struct *wq, const char *fmt,
+ unsigned int flags, int max_active, ...);
+
+int drmm_alloc_ordered_workqueue(struct drm_device *dev,
+ struct workqueue_struct *wq,
+ const char *fmt, unsigned int flags, ...);
+
 #endif
-- 
2.25.1



[PATCH] drm/msm/dsi: Drop the redundant fail label

2023-01-09 Thread Jiasheng Jiang
Drop the redundant fail label and change the "goto fail" into "return ret"
since they are the same.

Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/msm/dsi/dsi_host.c | 27 +--
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c 
b/drivers/gpu/drm/msm/dsi/dsi_host.c
index 89aadd3b3202..d2a4fefa7b76 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -1883,8 +1883,7 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
 
msm_host = devm_kzalloc(&pdev->dev, sizeof(*msm_host), GFP_KERNEL);
if (!msm_host) {
-   ret = -ENOMEM;
-   goto fail;
+   return -ENOMEM;
}
 
msm_host->pdev = pdev;
@@ -1893,31 +1892,28 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
ret = dsi_host_parse_dt(msm_host);
if (ret) {
pr_err("%s: failed to parse dt\n", __func__);
-   goto fail;
+   return ret;
}
 
msm_host->ctrl_base = msm_ioremap_size(pdev, "dsi_ctrl", 
&msm_host->ctrl_size);
if (IS_ERR(msm_host->ctrl_base)) {
pr_err("%s: unable to map Dsi ctrl base\n", __func__);
-   ret = PTR_ERR(msm_host->ctrl_base);
-   goto fail;
+   return PTR_ERR(msm_host->ctrl_base);
}
 
pm_runtime_enable(&pdev->dev);
 
msm_host->cfg_hnd = dsi_get_config(msm_host);
if (!msm_host->cfg_hnd) {
-   ret = -EINVAL;
pr_err("%s: get config failed\n", __func__);
-   goto fail;
+   return -EINVAL;
}
cfg = msm_host->cfg_hnd->cfg;
 
msm_host->id = dsi_host_get_id(msm_host);
if (msm_host->id < 0) {
-   ret = msm_host->id;
pr_err("%s: unable to identify DSI host index\n", __func__);
-   goto fail;
+   return msm_host->id;
}
 
/* fixup base address by io offset */
@@ -1927,19 +1923,18 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
cfg->regulator_data,
&msm_host->supplies);
if (ret)
-   goto fail;
+   return ret;
 
ret = dsi_clk_init(msm_host);
if (ret) {
pr_err("%s: unable to initialize dsi clks\n", __func__);
-   goto fail;
+   return ret;
}
 
msm_host->rx_buf = devm_kzalloc(&pdev->dev, SZ_4K, GFP_KERNEL);
if (!msm_host->rx_buf) {
-   ret = -ENOMEM;
pr_err("%s: alloc rx temp buf failed\n", __func__);
-   goto fail;
+   return -ENOMEM;
}
 
ret = devm_pm_opp_set_clkname(&pdev->dev, "byte");
@@ -1954,9 +1949,8 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
 
msm_host->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
if (msm_host->irq < 0) {
-   ret = msm_host->irq;
dev_err(&pdev->dev, "failed to get irq: %d\n", ret);
-   return ret;
+   return msm_host->irq;
}
 
/* do not autoenable, will be enabled later */
@@ -1983,9 +1977,6 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
 
DBG("Dsi Host %d initialized", msm_host->id);
return 0;
-
-fail:
-   return ret;
 }
 
 void msm_dsi_host_destroy(struct mipi_dsi_host *host)
-- 
2.25.1



[PATCH v3] drm/msm/dsi: Add missing check for alloc_ordered_workqueue

2023-01-09 Thread Jiasheng Jiang
Add check for the return value of alloc_ordered_workqueue as it may return
NULL pointer and cause NULL pointer dereference.

Signed-off-by: Jiasheng Jiang 
---
Changelog:

v2 -> v3:

1. Simply return -ENOMEM instead of using ret.
2. No change of the "goto fail".

v1 -> v2:

1. Change the "goto fail" into "return ret" and drop the "fail" label.
---
 drivers/gpu/drm/msm/dsi/dsi_host.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c 
b/drivers/gpu/drm/msm/dsi/dsi_host.c
index 89aadd3b3202..f167a45f1fbd 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -1977,6 +1977,9 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
 
/* setup workqueue */
msm_host->workqueue = alloc_ordered_workqueue("dsi_drm_work", 0);
+   if (!msm_host->workqueue)
+   return -ENOMEM;
+
INIT_WORK(&msm_host->err_work, dsi_err_worker);
 
msm_dsi->id = msm_host->id;
-- 
2.25.1



[PATCH v2] drm/msm/dsi: Add missing check for alloc_ordered_workqueue

2023-01-08 Thread Jiasheng Jiang
Add check for the return value of alloc_ordered_workqueue as it may return
NULL pointer and cause NULL pointer dereference.
Moreover, change the "goto fail" into "return ret" and drop the "fail"
label since they are the same.

Signed-off-by: Jiasheng Jiang 
---
Changelog:

v1 -> v2:

1. Change the "goto fail" into "return ret" and drop the "fail" label.
---
 drivers/gpu/drm/msm/dsi/dsi_host.c | 24 +---
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c 
b/drivers/gpu/drm/msm/dsi/dsi_host.c
index 89aadd3b3202..819f5be5fd77 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -1884,7 +1884,7 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
msm_host = devm_kzalloc(&pdev->dev, sizeof(*msm_host), GFP_KERNEL);
if (!msm_host) {
ret = -ENOMEM;
-   goto fail;
+   return ret;
}
 
msm_host->pdev = pdev;
@@ -1893,14 +1893,14 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
ret = dsi_host_parse_dt(msm_host);
if (ret) {
pr_err("%s: failed to parse dt\n", __func__);
-   goto fail;
+   return ret;
}
 
msm_host->ctrl_base = msm_ioremap_size(pdev, "dsi_ctrl", 
&msm_host->ctrl_size);
if (IS_ERR(msm_host->ctrl_base)) {
pr_err("%s: unable to map Dsi ctrl base\n", __func__);
ret = PTR_ERR(msm_host->ctrl_base);
-   goto fail;
+   return ret;
}
 
pm_runtime_enable(&pdev->dev);
@@ -1909,7 +1909,7 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
if (!msm_host->cfg_hnd) {
ret = -EINVAL;
pr_err("%s: get config failed\n", __func__);
-   goto fail;
+   return ret;
}
cfg = msm_host->cfg_hnd->cfg;
 
@@ -1917,7 +1917,7 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
if (msm_host->id < 0) {
ret = msm_host->id;
pr_err("%s: unable to identify DSI host index\n", __func__);
-   goto fail;
+   return ret;
}
 
/* fixup base address by io offset */
@@ -1927,19 +1927,19 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
cfg->regulator_data,
&msm_host->supplies);
if (ret)
-   goto fail;
+   return ret;
 
ret = dsi_clk_init(msm_host);
if (ret) {
pr_err("%s: unable to initialize dsi clks\n", __func__);
-   goto fail;
+   return ret;
}
 
msm_host->rx_buf = devm_kzalloc(&pdev->dev, SZ_4K, GFP_KERNEL);
if (!msm_host->rx_buf) {
ret = -ENOMEM;
pr_err("%s: alloc rx temp buf failed\n", __func__);
-   goto fail;
+   return ret;
}
 
ret = devm_pm_opp_set_clkname(&pdev->dev, "byte");
@@ -1977,15 +1977,17 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
 
/* setup workqueue */
msm_host->workqueue = alloc_ordered_workqueue("dsi_drm_work", 0);
+   if (!msm_host->workqueue) {
+   ret = -ENOMEM;
+   return ret;
+   }
+
INIT_WORK(&msm_host->err_work, dsi_err_worker);
 
msm_dsi->id = msm_host->id;
 
DBG("Dsi Host %d initialized", msm_host->id);
return 0;
-
-fail:
-   return ret;
 }
 
 void msm_dsi_host_destroy(struct mipi_dsi_host *host)
-- 
2.25.1



[PATCH v2] drm/msm: Add missing check and destroy for alloc_ordered_workqueue

2023-01-08 Thread Jiasheng Jiang
Add check for the return value of alloc_ordered_workqueue as it may return
NULL pointer.
Moreover, use the destroy_workqueue in the later fails in order to avoid
memory leak.

Signed-off-by: Jiasheng Jiang 
---
Changelog:

v1 -> v2:

1. Convert "goto err_destroy_workqueue" into "goto err_msm_unit" and
remove "err_destroy_workqueue" label.
---
 drivers/gpu/drm/msm/msm_drv.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index 8b0b0ac74a6f..54be323ed33d 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -418,6 +418,8 @@ static int msm_drm_init(struct device *dev, const struct 
drm_driver *drv)
priv->dev = ddev;
 
priv->wq = alloc_ordered_workqueue("msm", 0);
+   if (!priv->wq)
+   return -ENOMEM;
 
INIT_LIST_HEAD(&priv->objects);
mutex_init(&priv->obj_lock);
@@ -440,12 +442,12 @@ static int msm_drm_init(struct device *dev, const struct 
drm_driver *drv)
 
ret = msm_init_vram(ddev);
if (ret)
-   return ret;
+   goto err_msm_uninit;
 
/* Bind all our sub-components: */
ret = component_bind_all(dev, ddev);
if (ret)
-   return ret;
+   goto err_msm_uninit;
 
dma_set_max_seg_size(dev, UINT_MAX);
 
-- 
2.25.1



[PATCH] drm/i915: Add missing check and destroy for alloc_workqueue

2023-01-06 Thread Jiasheng Jiang
Add checks for the return value of alloc_workqueue and
alloc_ordered_workqueue as they may return NULL pointer and cause NULL
pointer dereference.
Moreover, destroy them when fails later in order to avoid memory leak.
Because in `drivers/gpu/drm/i915/i915_driver.c`, if
intel_modeset_init_noirq fails, its workqueues will not be destroyed.

Fixes: c26a058680dc ("drm/i915: Use a high priority wq for nonblocking plane 
updates")
Fixes: 757fffcfdffb ("drm/i915: Put all non-blocking modesets onto an ordered 
wq")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/i915/display/intel_display.c | 21 
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display.c 
b/drivers/gpu/drm/i915/display/intel_display.c
index 6c2686ecb62a..58f6840d6bd8 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -8655,26 +8655,35 @@ int intel_modeset_init_noirq(struct drm_i915_private 
*i915)
intel_dmc_ucode_init(i915);
 
i915->display.wq.modeset = alloc_ordered_workqueue("i915_modeset", 0);
+   if (!i915->display.wq.modeset) {
+   ret = -ENOMEM;
+   goto cleanup_vga_client_pw_domain_dmc;
+   }
+
i915->display.wq.flip = alloc_workqueue("i915_flip", WQ_HIGHPRI |
WQ_UNBOUND, 
WQ_UNBOUND_MAX_ACTIVE);
+   if (!i915->display.wq.flip) {
+   ret = -ENOMEM;
+   goto cleanup_modeset;
+   }
 
intel_mode_config_init(i915);
 
ret = intel_cdclk_init(i915);
if (ret)
-   goto cleanup_vga_client_pw_domain_dmc;
+   goto cleanup_flip;
 
ret = intel_color_init(i915);
if (ret)
-   goto cleanup_vga_client_pw_domain_dmc;
+   goto cleanup_flip;
 
ret = intel_dbuf_init(i915);
if (ret)
-   goto cleanup_vga_client_pw_domain_dmc;
+   goto cleanup_flip;
 
ret = intel_bw_init(i915);
if (ret)
-   goto cleanup_vga_client_pw_domain_dmc;
+   goto cleanup_flip;
 
init_llist_head(&i915->display.atomic_helper.free_list);
INIT_WORK(&i915->display.atomic_helper.free_work,
@@ -8686,6 +8695,10 @@ int intel_modeset_init_noirq(struct drm_i915_private 
*i915)
 
return 0;
 
+cleanup_flip:
+   destroy_workqueue(i915->display.wq.flip);
+cleanup_modeset:
+   destroy_workqueue(i915->display.wq.modeset);
 cleanup_vga_client_pw_domain_dmc:
intel_dmc_ucode_fini(i915);
intel_power_domains_driver_remove(i915);
-- 
2.25.1



[PATCH RESEND] drm/msm: Add missing check and destroy for alloc_ordered_workqueue

2023-01-06 Thread Jiasheng Jiang
Add check for the return value of alloc_ordered_workqueue as it may return
NULL pointer.
Moreover, use the destroy_workqueue in the later fails in order to avoid
memory leak.

Fixes: c8afe684c95c ("drm/msm: basic KMS driver for snapdragon")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/msm/msm_drv.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index 8b0b0ac74a6f..b82d938226ad 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -418,6 +418,8 @@ static int msm_drm_init(struct device *dev, const struct 
drm_driver *drv)
priv->dev = ddev;
 
priv->wq = alloc_ordered_workqueue("msm", 0);
+   if (!priv->wq)
+   return -ENOMEM;
 
INIT_LIST_HEAD(&priv->objects);
mutex_init(&priv->obj_lock);
@@ -440,12 +442,12 @@ static int msm_drm_init(struct device *dev, const struct 
drm_driver *drv)
 
ret = msm_init_vram(ddev);
if (ret)
-   return ret;
+   goto err_destroy_workqueue;
 
/* Bind all our sub-components: */
ret = component_bind_all(dev, ddev);
if (ret)
-   return ret;
+   goto err_destroy_workqueue;
 
dma_set_max_seg_size(dev, UINT_MAX);
 
@@ -540,6 +542,8 @@ static int msm_drm_init(struct device *dev, const struct 
drm_driver *drv)
 
 err_msm_uninit:
msm_drm_uninit(dev);
+err_destroy_workqueue:
+   destroy_workqueue(priv->wq);
return ret;
 }
 
-- 
2.25.1



[PATCH] drm/msm/dsi: Add missing check for alloc_ordered_workqueue

2023-01-05 Thread Jiasheng Jiang
Add check for the return value of alloc_ordered_workqueue as it may return
NULL pointer and cause NULL pointer dereference.
Moreover, change the "return ret" into "goto fail" in order to be
consistent with the others.

Fixes: a689554ba6ed ("drm/msm: Initial add DSI connector support")
Fixes: 32d3e0feccfe ("drm/msm: dsi: Use OPP API to set clk/perf state")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/msm/dsi/dsi_host.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c 
b/drivers/gpu/drm/msm/dsi/dsi_host.c
index 89aadd3b3202..12239f628d5a 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -1944,19 +1944,19 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
 
ret = devm_pm_opp_set_clkname(&pdev->dev, "byte");
if (ret)
-   return ret;
+   goto fail;
/* OPP table is optional */
ret = devm_pm_opp_of_add_table(&pdev->dev);
if (ret && ret != -ENODEV) {
dev_err(&pdev->dev, "invalid OPP table in device tree\n");
-   return ret;
+   goto fail;
}
 
msm_host->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
if (msm_host->irq < 0) {
ret = msm_host->irq;
dev_err(&pdev->dev, "failed to get irq: %d\n", ret);
-   return ret;
+   goto fail;
}
 
/* do not autoenable, will be enabled later */
@@ -1966,7 +1966,7 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
if (ret < 0) {
dev_err(&pdev->dev, "failed to request IRQ%u: %d\n",
msm_host->irq, ret);
-   return ret;
+   goto fail;
}
 
init_completion(&msm_host->dma_comp);
@@ -1977,6 +1977,11 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
 
/* setup workqueue */
msm_host->workqueue = alloc_ordered_workqueue("dsi_drm_work", 0);
+   if (!msm_host->workqueue) {
+   ret = -ENOMEM;
+   goto fail;
+   }
+
INIT_WORK(&msm_host->err_work, dsi_err_worker);
 
msm_dsi->id = msm_host->id;
-- 
2.25.1



[PATCH] drm/msm/hdmi: Add missing check for alloc_ordered_workqueue

2023-01-05 Thread Jiasheng Jiang
Add check for the return value of alloc_ordered_workqueue as it may return
NULL pointer and cause NULL pointer dereference in `hdmi_hdcp.c` and
`hdmi_hpd.c`.

Fixes: c6a57a50ad56 ("drm/msm/hdmi: add hdmi hdcp support (V3)")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/msm/hdmi/hdmi.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/msm/hdmi/hdmi.c b/drivers/gpu/drm/msm/hdmi/hdmi.c
index 4d3fdc806bef..8e801ec0b33f 100644
--- a/drivers/gpu/drm/msm/hdmi/hdmi.c
+++ b/drivers/gpu/drm/msm/hdmi/hdmi.c
@@ -120,6 +120,10 @@ static int msm_hdmi_init(struct hdmi *hdmi)
int ret;
 
hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0);
+   if (!hdmi->workq) {
+   ret = -ENOMEM;
+   goto fail;
+   }
 
hdmi->i2c = msm_hdmi_i2c_init(hdmi);
if (IS_ERR(hdmi->i2c)) {
-- 
2.25.1



[PATCH] drm/msm: Add missing check and destroy for alloc_ordered_workqueue

2023-01-05 Thread Jiasheng Jiang
Add check for the return value of alloc_ordered_workqueue as it may return
NULL pointer.
Moreover, use the destroy_workqueue in the later fails in order to avoid
memory leak.

Fixes: c8afe684c95c ("drm/msm: basic KMS driver for snapdragon")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/msm/msm_drv.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index 8b0b0ac74a6f..b82d938226ad 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -418,6 +418,8 @@ static int msm_drm_init(struct device *dev, const struct 
drm_driver *drv)
priv->dev = ddev;
 
priv->wq = alloc_ordered_workqueue("msm", 0);
+   if (!priv->wq)
+   return -ENOMEM;
 
INIT_LIST_HEAD(&priv->objects);
mutex_init(&priv->obj_lock);
@@ -440,12 +442,12 @@ static int msm_drm_init(struct device *dev, const struct 
drm_driver *drv)
 
ret = msm_init_vram(ddev);
if (ret)
-   return ret;
+   goto err_destroy_workqueue;
 
/* Bind all our sub-components: */
ret = component_bind_all(dev, ddev);
if (ret)
-   return ret;
+   goto err_destroy_workqueue;
 
dma_set_max_seg_size(dev, UINT_MAX);
 
@@ -540,6 +542,8 @@ static int msm_drm_init(struct device *dev, const struct 
drm_driver *drv)
 
 err_msm_uninit:
msm_drm_uninit(dev);
+err_destroy_workqueue:
+   destroy_workqueue(priv->wq);
return ret;
 }
 
-- 
2.25.1



Re: [PATCH v3] usb: gadget: aspeed_udc: Add check for dma_alloc_coherent

2022-12-23 Thread Jiasheng Jiang
On Fri, Dec 23, 2022 at 10:54:37PM +0800, Greg KH wrote:
>> diff --git a/drivers/usb/gadget/udc/aspeed_udc.c 
>> b/drivers/usb/gadget/udc/aspeed_udc.c
>> index 01968e2167f9..7dc2457c7460 100644
>> --- a/drivers/usb/gadget/udc/aspeed_udc.c
>> +++ b/drivers/usb/gadget/udc/aspeed_udc.c
>> @@ -1516,6 +1516,10 @@ static int ast_udc_probe(struct platform_device *pdev)
>>AST_UDC_EP_DMA_SIZE *
>>AST_UDC_NUM_ENDPOINTS,
>>&udc->ep0_buf_dma, GFP_KERNEL);
>> +if (!udc->ep0_buf) {
>> +rc = -ENOMEM;
>> +goto err;
>> +}
>>  
>>  udc->gadget.speed = USB_SPEED_UNKNOWN;
>>  udc->gadget.max_speed = USB_SPEED_HIGH;
>> -- 
>> 2.25.1
>> 
> 
> Why is this just a duplicate of the patch previously submitted here:
>   https://lore.kernel.org/r/20221125092833.74822-1-yuan...@huawei.com
> 
> confused,
> 
> greg k-h

Yes, it is the same as mine.
As the previous patch had not been merged into the Linux kernel,
my tool found the same error and report it.
And both of us chose the most concise way to fix the error.
That is why the patches are the same.

Thanks,
Jiang



Re: [PATCH v3] usb: gadget: aspeed_udc: Add check for dma_alloc_coherent

2022-12-23 Thread Jiasheng Jiang
Yes, it is the same as mine.
As the previous patch had not been merged into the Linux kernel,
my tool found the same error and report it.
And both of us chose the most concise way to fix the error.
That is why the patches are the same.

Thanks,
Jiang



[PATCH v3] usb: gadget: aspeed_udc: Add check for dma_alloc_coherent

2022-12-15 Thread Jiasheng Jiang
Add the check for the return value of dma_alloc_coherent in order to
avoid NULL pointer dereference.

This flaw was found using an experimental static analysis tool we are
developing, APP-Miner, which has not been disclosed.

The allyesconfig build using GCC 9.3.0 shows no new warning. As we
don't have a UDC device to test with, no runtime testing was able to
be performed.

Signed-off-by: Jiasheng Jiang 
---
Changelog:

v2 -> v3:

1. Add information of finding tool and tests to commit message.

v1 -> v2:

1. Add "goto err;" when allocation fails.
---
 drivers/usb/gadget/udc/aspeed_udc.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/gadget/udc/aspeed_udc.c 
b/drivers/usb/gadget/udc/aspeed_udc.c
index 01968e2167f9..7dc2457c7460 100644
--- a/drivers/usb/gadget/udc/aspeed_udc.c
+++ b/drivers/usb/gadget/udc/aspeed_udc.c
@@ -1516,6 +1516,10 @@ static int ast_udc_probe(struct platform_device *pdev)
  AST_UDC_EP_DMA_SIZE *
  AST_UDC_NUM_ENDPOINTS,
  &udc->ep0_buf_dma, GFP_KERNEL);
+   if (!udc->ep0_buf) {
+   rc = -ENOMEM;
+   goto err;
+   }
 
udc->gadget.speed = USB_SPEED_UNKNOWN;
udc->gadget.max_speed = USB_SPEED_HIGH;
-- 
2.25.1



[PATCH v2] usb: gadget: aspeed_udc: Add check for dma_alloc_coherent

2022-12-13 Thread Jiasheng Jiang
Add the check for the return value of dma_alloc_coherent in order to
avoid NULL pointer dereference.

This flaw was found using an experimental static analysis tool we are
developing, APP-Miner, which has not been disclosed.

The allyesconfig build using GCC 9.3.0 shows no new warning. As we
don't have a UDC device to test with, no runtime testing was able to
be performed.

Signed-off-by: Jiasheng Jiang 
---
Changelog:

v1 -> v2:

1. Add "goto err;" when allocation fails.
---
 drivers/usb/gadget/udc/aspeed_udc.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/gadget/udc/aspeed_udc.c 
b/drivers/usb/gadget/udc/aspeed_udc.c
index 01968e2167f9..7dc2457c7460 100644
--- a/drivers/usb/gadget/udc/aspeed_udc.c
+++ b/drivers/usb/gadget/udc/aspeed_udc.c
@@ -1516,6 +1516,10 @@ static int ast_udc_probe(struct platform_device *pdev)
  AST_UDC_EP_DMA_SIZE *
  AST_UDC_NUM_ENDPOINTS,
  &udc->ep0_buf_dma, GFP_KERNEL);
+   if (!udc->ep0_buf) {
+   rc = -ENOMEM;
+   goto err;
+   }
 
udc->gadget.speed = USB_SPEED_UNKNOWN;
udc->gadget.max_speed = USB_SPEED_HIGH;
-- 
2.25.1



[PATCH v2] usb: gadget: aspeed_udc: Add check for dma_alloc_coherent

2022-12-13 Thread Jiasheng Jiang
Add the check for the return value of dma_alloc_coherent
in order to avoid NULL pointer dereference.

Fixes: 055276c13205 ("usb: gadget: add Aspeed ast2600 udc driver")
Signed-off-by: Jiasheng Jiang 
---
Changelog:

v1 -> v2:

1. Add "goto err;" when allocation fails.
---
 drivers/usb/gadget/udc/aspeed_udc.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/gadget/udc/aspeed_udc.c 
b/drivers/usb/gadget/udc/aspeed_udc.c
index 01968e2167f9..7dc2457c7460 100644
--- a/drivers/usb/gadget/udc/aspeed_udc.c
+++ b/drivers/usb/gadget/udc/aspeed_udc.c
@@ -1516,6 +1516,10 @@ static int ast_udc_probe(struct platform_device *pdev)
  AST_UDC_EP_DMA_SIZE *
  AST_UDC_NUM_ENDPOINTS,
  &udc->ep0_buf_dma, GFP_KERNEL);
+   if (!udc->ep0_buf) {
+   rc = -ENOMEM;
+   goto err;
+   }
 
udc->gadget.speed = USB_SPEED_UNKNOWN;
udc->gadget.max_speed = USB_SPEED_HIGH;
-- 
2.25.1



Re: [PATCH] usb: gadget: aspeed_udc: Add check for dma_alloc_coherent

2022-12-13 Thread Jiasheng Jiang
Thanks, I found my mistake and I will submit a v2.

> And how did you find this potential problem?  What tool did you use and
> why did you not follow the documentation for properly describing the
> tool?

I used a tool I wrote myself to find it, which is unpublished.
Therefore, I think it is okay to submit patches without description of the
tools.

Thanks,
Jiang



[PATCH] usb: gadget: aspeed_udc: Add check for dma_alloc_coherent

2022-12-12 Thread Jiasheng Jiang
Add the check for the return value of dma_alloc_coherent
in order to avoid NULL pointer dereference.

Fixes: 055276c13205 ("usb: gadget: add Aspeed ast2600 udc driver")
Signed-off-by: Jiasheng Jiang 
---
 drivers/usb/gadget/udc/aspeed_udc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/gadget/udc/aspeed_udc.c 
b/drivers/usb/gadget/udc/aspeed_udc.c
index 01968e2167f9..6cf46562bb25 100644
--- a/drivers/usb/gadget/udc/aspeed_udc.c
+++ b/drivers/usb/gadget/udc/aspeed_udc.c
@@ -1516,6 +1516,8 @@ static int ast_udc_probe(struct platform_device *pdev)
  AST_UDC_EP_DMA_SIZE *
  AST_UDC_NUM_ENDPOINTS,
  &udc->ep0_buf_dma, GFP_KERNEL);
+   if (!udc->ep0_buf)
+   return -ENOMEM;
 
udc->gadget.speed = USB_SPEED_UNKNOWN;
udc->gadget.max_speed = USB_SPEED_HIGH;
-- 
2.25.1



[PATCH] drm/msm/gem: Add check for kmalloc

2022-12-12 Thread Jiasheng Jiang
Add the check for the return value of kmalloc in order to avoid
NULL pointer dereference in copy_from_user.

Fixes: 20224d715a88 ("drm/msm/submit: Move copy_from_user ahead of locking bos")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/msm/msm_gem_submit.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c 
b/drivers/gpu/drm/msm/msm_gem_submit.c
index 45a3e5cadc7d..7c2cc1262c05 100644
--- a/drivers/gpu/drm/msm/msm_gem_submit.c
+++ b/drivers/gpu/drm/msm/msm_gem_submit.c
@@ -209,6 +209,10 @@ static int submit_lookup_cmds(struct msm_gem_submit 
*submit,
goto out;
}
submit->cmd[i].relocs = kmalloc(sz, GFP_KERNEL);
+   if (!submit->cmd[i].relocs) {
+   ret = -ENOMEM;
+   goto out;
+   }
ret = copy_from_user(submit->cmd[i].relocs, userptr, sz);
if (ret) {
ret = -EFAULT;
-- 
2.25.1



[PATCH] drm: mali-dp: Add check for kzalloc

2022-12-07 Thread Jiasheng Jiang
As kzalloc may fail and return NULL pointer, the "mw_state" can be NULL.
If the layout of struct malidp_mw_connector_state ever changes, it
will cause NULL poineter derefernce of "&mw_state->base".
Therefore, the "mw_state" should be checked whether it is NULL in order
to improve the robust.

Fixes: 8cbc5caf36ef ("drm: mali-dp: Add writeback connector")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/arm/malidp_mw.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_mw.c
index ef76d0e6ee2f..fe4474c2ddcf 100644
--- a/drivers/gpu/drm/arm/malidp_mw.c
+++ b/drivers/gpu/drm/arm/malidp_mw.c
@@ -72,7 +72,11 @@ static void malidp_mw_connector_reset(struct drm_connector 
*connector)
__drm_atomic_helper_connector_destroy_state(connector->state);
 
kfree(connector->state);
-   __drm_atomic_helper_connector_reset(connector, &mw_state->base);
+
+   if (mw_state)
+   __drm_atomic_helper_connector_reset(connector, &mw_state->base);
+   else
+   __drm_atomic_helper_connector_reset(connector, NULL);
 }
 
 static enum drm_connector_status
-- 
2.25.1



[PATCH] drm: mali-dp: Add check for kzalloc

2022-12-07 Thread Jiasheng Jiang
As kzalloc may fail and return NULL pointer, the "mw_state" can be NULL.
If the layout of struct malidp_mw_connector_state ever changes, it
will cause NULL poineter derefernce of "&mw_state->base".
Therefore, the "mw_state" should be check whether it is NULL in order
to improve the robust.

Fixes: 8cbc5caf36ef ("drm: mali-dp: Add writeback connector")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/arm/malidp_mw.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_mw.c
index ef76d0e6ee2f..fe4474c2ddcf 100644
--- a/drivers/gpu/drm/arm/malidp_mw.c
+++ b/drivers/gpu/drm/arm/malidp_mw.c
@@ -72,7 +72,11 @@ static void malidp_mw_connector_reset(struct drm_connector 
*connector)
__drm_atomic_helper_connector_destroy_state(connector->state);
 
kfree(connector->state);
-   __drm_atomic_helper_connector_reset(connector, &mw_state->base);
+
+   if (mw_state)
+   __drm_atomic_helper_connector_reset(connector, &mw_state->base);
+   else
+   __drm_atomic_helper_connector_reset(connector, NULL);
 }
 
 static enum drm_connector_status
-- 
2.25.1



Re: [PATCH] drm: mali-dp: Add check for kzalloc

2022-12-07 Thread Jiasheng Jiang
On Wed, Dec 07, 2022 at 09:59:04PM +0800, Robin Murphy wrote:
>> As kzalloc may fail and return NULL pointer, it should be better to check
>> the return value in order to avoid the NULL pointer dereference in
>> __drm_atomic_helper_connector_reset.
> 
> This commit message is nonsense; if 
> __drm_atomic_helper_connector_reset() would dereference the NULL implied 
> by &mw_state->base, it would equally still dereference the explicit NULL 
> pointer passed after this patch.
> 
> The current code works out OK because "base" is the first member of 
> struct malidp_mw_connector_state, thus if mw_state is NULL then 
> &mw_state->base == NULL + 0 == NULL. Now you *could* argue that this 
> isn't robust if the layout of struct malidp_mw_connector_state ever 
> changes, and that could be a valid justification for making this change, 
> but the reason given certainly isn't.
> 
> Arithmetic on a (potentially) NULL pointer may well be a sign that it's 
> worth a closer look to check whether it really is what the code intended 
> to do, but don't automatically assume it has to be a bug. Otherwise, 
> good luck with "fixing" every user of container_of() throughout the 
> entire kernel.

I have sent a new patch with the modified commit mesage.

Thanks,
Jiang



[PATCH] drm: mali-dp: Add check for kzalloc

2022-12-07 Thread Jiasheng Jiang
As kzalloc may fail and return NULL pointer, the "mw_state" can be NULL.
If the the layout of struct malidp_mw_connector_state ever changes, it
will cause NULL poineter derefernce of "&mw_state->base".
Therefore, the "mw_state" should be check whether it is NULL in order
to improve the robust.

Fixes: 8cbc5caf36ef ("drm: mali-dp: Add writeback connector")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/arm/malidp_mw.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_mw.c
index ef76d0e6ee2f..c74c7c4e6006 100644
--- a/drivers/gpu/drm/arm/malidp_mw.c
+++ b/drivers/gpu/drm/arm/malidp_mw.c
@@ -72,7 +72,11 @@ static void malidp_mw_connector_reset(struct drm_connector 
*connector)
__drm_atomic_helper_connector_destroy_state(connector->state);
 
kfree(connector->state);
-   __drm_atomic_helper_connector_reset(connector, &mw_state->base);
+
+   if (mw_state)
+   __drm_atomic_helper_connector_reset(connector, &mw_state->base);
+   else:
+   __drm_atomic_helper_connector_reset(connector, NULL);
 }
 
 static enum drm_connector_status
-- 
2.25.1



[PATCH] drm/amd/display: Add check for kzalloc

2022-12-07 Thread Jiasheng Jiang
As kzalloc may fail and return NULL pointer, it should be better to check
the return value in order to avoid the NULL pointer dereference.
Moreover, dcn3_clk_mgr_construct should return the error and
should be checked cascadingly.

Fixes: 4d55b0dd1cdd ("drm/amd/display: Add DCN3 CLK_MGR")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/amd/display/dc/clk_mgr/clk_mgr.c | 9 ++---
 .../gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c | 6 +-
 .../gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.h | 2 +-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/clk_mgr/clk_mgr.c 
b/drivers/gpu/drm/amd/display/dc/clk_mgr/clk_mgr.c
index f276abb63bcd..c08916bd5650 100644
--- a/drivers/gpu/drm/amd/display/dc/clk_mgr/clk_mgr.c
+++ b/drivers/gpu/drm/amd/display/dc/clk_mgr/clk_mgr.c
@@ -257,15 +257,18 @@ struct clk_mgr *dc_clk_mgr_create(struct dc_context *ctx, 
struct pp_smu_funcs *p
return NULL;
}
if (ASICREV_IS_SIENNA_CICHLID_P(asic_id.hw_internal_rev)) {
-   dcn3_clk_mgr_construct(ctx, clk_mgr, pp_smu, dccg);
+   if (dcn3_clk_mgr_construct(ctx, clk_mgr, pp_smu, dccg))
+   return NULL;
return &clk_mgr->base;
}
if (ASICREV_IS_DIMGREY_CAVEFISH_P(asic_id.hw_internal_rev)) {
-   dcn3_clk_mgr_construct(ctx, clk_mgr, pp_smu, dccg);
+   if (dcn3_clk_mgr_construct(ctx, clk_mgr, pp_smu, dccg))
+   return NULL;
return &clk_mgr->base;
}
if (ASICREV_IS_BEIGE_GOBY_P(asic_id.hw_internal_rev)) {
-   dcn3_clk_mgr_construct(ctx, clk_mgr, pp_smu, dccg);
+   if (dcn3_clk_mgr_construct(ctx, clk_mgr, pp_smu, dccg))
+   return NULL;
return &clk_mgr->base;
}
if (asic_id.chip_id == DEVICE_ID_NV_13FE) {
diff --git a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c 
b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c
index 3ce0ee0d012f..86c29dc45b70 100644
--- a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c
+++ b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c
@@ -517,7 +517,7 @@ struct clk_mgr_funcs dcn3_fpga_funcs = {
 };
 
 /*todo for dcn30 for clk register offset*/
-void dcn3_clk_mgr_construct(
+int dcn3_clk_mgr_construct(
struct dc_context *ctx,
struct clk_mgr_internal *clk_mgr,
struct pp_smu_funcs *pp_smu,
@@ -568,11 +568,15 @@ void dcn3_clk_mgr_construct(
dce_clock_read_ss_info(clk_mgr);
 
clk_mgr->base.bw_params = kzalloc(sizeof(*clk_mgr->base.bw_params), 
GFP_KERNEL);
+   if (!clk_mgr->base.bw_params)
+   return -ENOMEM;
 
/* need physical address of table to give to PMFW */
clk_mgr->wm_range_table = dm_helpers_allocate_gpu_mem(clk_mgr->base.ctx,
DC_MEM_ALLOC_TYPE_GART, sizeof(WatermarksExternal_t),
&clk_mgr->wm_range_table_addr);
+
+   return 0;
 }
 
 void dcn3_clk_mgr_destroy(struct clk_mgr_internal *clk_mgr)
diff --git a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.h 
b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.h
index 2cd95ec38266..8bdfed735184 100644
--- a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.h
+++ b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.h
@@ -88,7 +88,7 @@
 #endif
 void dcn3_init_clocks(struct clk_mgr *clk_mgr_base);
 
-void dcn3_clk_mgr_construct(struct dc_context *ctx,
+int dcn3_clk_mgr_construct(struct dc_context *ctx,
struct clk_mgr_internal *clk_mgr,
struct pp_smu_funcs *pp_smu,
struct dccg *dccg);
-- 
2.25.1



[PATCH] drm: mali-dp: Add check for kzalloc

2022-12-07 Thread Jiasheng Jiang
As kzalloc may fail and return NULL pointer, it should be better to check
the return value in order to avoid the NULL pointer dereference in
__drm_atomic_helper_connector_reset.

Fixes: 8cbc5caf36ef ("drm: mali-dp: Add writeback connector")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/arm/malidp_mw.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_mw.c
index ef76d0e6ee2f..fe4474c2ddcf 100644
--- a/drivers/gpu/drm/arm/malidp_mw.c
+++ b/drivers/gpu/drm/arm/malidp_mw.c
@@ -72,7 +72,11 @@ static void malidp_mw_connector_reset(struct drm_connector 
*connector)
__drm_atomic_helper_connector_destroy_state(connector->state);
 
kfree(connector->state);
-   __drm_atomic_helper_connector_reset(connector, &mw_state->base);
+
+   if (mw_state)
+   __drm_atomic_helper_connector_reset(connector, &mw_state->base);
+   else
+   __drm_atomic_helper_connector_reset(connector, NULL);
 }
 
 static enum drm_connector_status
-- 
2.25.1



[PATCH] drm/msm/dpu: Add check for cstate

2022-12-06 Thread Jiasheng Jiang
As kzalloc may fail and return NULL pointer,
it should be better to check cstate
in order to avoid the NULL pointer dereference
in __drm_atomic_helper_crtc_reset.

Fixes: 1cff7440a86e ("drm/msm: Convert to using 
__drm_atomic_helper_crtc_reset() for reset.")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
index 13ce321283ff..22c2787b7b38 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
@@ -968,7 +968,10 @@ static void dpu_crtc_reset(struct drm_crtc *crtc)
if (crtc->state)
dpu_crtc_destroy_state(crtc, crtc->state);
 
-   __drm_atomic_helper_crtc_reset(crtc, &cstate->base);
+   if (cstate)
+   __drm_atomic_helper_crtc_reset(crtc, &cstate->base);
+   else
+   __drm_atomic_helper_crtc_reset(crtc, NULL);
 }
 
 /**
-- 
2.25.1



[PATCH] drm/msm/dpu: Add check for pstates

2022-12-06 Thread Jiasheng Jiang
As kzalloc may fail and return NULL pointer,
it should be better to check pstates
in order to avoid the NULL pointer dereference.

Fixes: 25fdd5933e4c ("drm/msm: Add SDM845 DPU support")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
index 13ce321283ff..f51cb46ecfd6 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
@@ -1150,6 +1150,8 @@ static int dpu_crtc_atomic_check(struct drm_crtc *crtc,
bool needs_dirtyfb = dpu_crtc_needs_dirtyfb(crtc_state);
 
pstates = kzalloc(sizeof(*pstates) * DPU_STAGE_MAX * 4, GFP_KERNEL);
+   if (!pstates)
+   return -ENOMEM;
 
if (!crtc_state->enable || !crtc_state->active) {
DRM_DEBUG_ATOMIC("crtc%d -> enable %d, active %d, skip 
atomic_check\n",
-- 
2.25.1



[PATCH] drm/msm/dpu: Add check for cstate

2022-12-06 Thread Jiasheng Jiang
As kzalloc may fail and return NULL pointer,
it should be better to check pstates
in order to avoid the NULL pointer dereference
later.

Fixes: 25fdd5933e4c ("drm/msm: Add SDM845 DPU support")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
index 13ce321283ff..f51cb46ecfd6 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
@@ -1150,6 +1150,8 @@ static int dpu_crtc_atomic_check(struct drm_crtc *crtc,
bool needs_dirtyfb = dpu_crtc_needs_dirtyfb(crtc_state);
 
pstates = kzalloc(sizeof(*pstates) * DPU_STAGE_MAX * 4, GFP_KERNEL);
+   if (!pstates)
+   return -ENOMEM;
 
if (!crtc_state->enable || !crtc_state->active) {
DRM_DEBUG_ATOMIC("crtc%d -> enable %d, active %d, skip 
atomic_check\n",
-- 
2.25.1



[PATCH] drm/msm/mdp5: Add check for kzalloc

2022-12-05 Thread Jiasheng Jiang
As kzalloc may fail and return NULL pointer,
it should be better to check the return value
in order to avoid the NULL pointer dereference.

Fixes: 1cff7440a86e ("drm/msm: Convert to using 
__drm_atomic_helper_crtc_reset() for reset.")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c 
b/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
index e86421c69bd1..86036dd4e1e8 100644
--- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
+++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
@@ -1139,7 +1139,10 @@ static void mdp5_crtc_reset(struct drm_crtc *crtc)
if (crtc->state)
mdp5_crtc_destroy_state(crtc, crtc->state);
 
-   __drm_atomic_helper_crtc_reset(crtc, &mdp5_cstate->base);
+   if (mdp5_cstate)
+   __drm_atomic_helper_crtc_reset(crtc, &mdp5_cstate->base);
+   else
+   __drm_atomic_helper_crtc_reset(crtc, NULL);
 }
 
 static const struct drm_crtc_funcs mdp5_crtc_no_lm_cursor_funcs = {
-- 
2.25.1



[PATCH] drm/msm/mdp5: Add check for kzalloc

2022-12-05 Thread Jiasheng Jiang
As kzalloc may fail and return NULL pointer,
it should be better to check the return value
in order to avoid the NULL pointer dereference.

Fixes: 1cff7440a86e ("drm/msm: Convert to using 
__drm_atomic_helper_crtc_reset() for reset.")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c 
b/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
index e86421c69bd1..86036dd4e1e8 100644
--- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
+++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
@@ -1139,7 +1139,10 @@ static void mdp5_crtc_reset(struct drm_crtc *crtc)
if (crtc->state)
mdp5_crtc_destroy_state(crtc, crtc->state);
 
-   __drm_atomic_helper_crtc_reset(crtc, &mdp5_cstate->base);
+   if (mdp5_cstate)
+   __drm_atomic_helper_crtc_reset(crtc, &mdp5_cstate->base);
+   else
+   __drm_atomic_helper_crtc_reset(crtc, NULL);
 }
 
 static const struct drm_crtc_funcs mdp5_crtc_no_lm_cursor_funcs = {
-- 
2.25.1



[PATCH] drm/amd/display: rewrite the check for mods

2022-11-19 Thread Jiasheng Jiang
On Thu, 17 Nov 2022 15:56:09 +0800, Simon Ser wrote:
>> @@ -638,11 +638,14 @@ static int get_plane_modifiers(struct amdgpu_device 
>> *adev, unsigned int plane_ty
>>  return 0;
>>  
>>  *mods = kmalloc(capacity * sizeof(uint64_t), GFP_KERNEL);
>> +if (!*mods)
>> +return -ENOMEM;
>> +
>>  
>>  if (plane_type == DRM_PLANE_TYPE_CURSOR) {
>>  add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_LINEAR);
>>  add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_INVALID);
>> -return *mods ? 0 : -ENOMEM;
>> +return 0;
>>  }
>>  
>>  switch (adev->family) {
>> @@ -671,9 +674,6 @@ static int get_plane_modifiers(struct amdgpu_device 
>> *adev, unsigned int plane_ty
>>  /* INVALID marks the end of the list. */
>>  add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_INVALID);
>>  
>> -if (!*mods)
>> -return -ENOMEM;
>> -
>>  return 0;
>>  }
 
> This breaks the "size" out-parameter.

No, it will not change the value of the "size".
The "size" can only be modified by add_modifier().
However, when the "*mods" is NULL, add_modifier() will return immediately,
without the execution of "*size += 1;".
Therefore, when the "*mods" is NULL, the rest of the function is useless,
which should be better to skip.

Jiang



[PATCH] drm/amd/display: rewrite the check for mods

2022-11-16 Thread Jiasheng Jiang
When the *mods is NULL, it should be better to return error immediately,
rather than continue with redundant operations.

Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
index e6854f7270a6..05efc76b2226 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
@@ -638,11 +638,14 @@ static int get_plane_modifiers(struct amdgpu_device 
*adev, unsigned int plane_ty
return 0;
 
*mods = kmalloc(capacity * sizeof(uint64_t), GFP_KERNEL);
+   if (!*mods)
+   return -ENOMEM;
+
 
if (plane_type == DRM_PLANE_TYPE_CURSOR) {
add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_LINEAR);
add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_INVALID);
-   return *mods ? 0 : -ENOMEM;
+   return 0;
}
 
switch (adev->family) {
@@ -671,9 +674,6 @@ static int get_plane_modifiers(struct amdgpu_device *adev, 
unsigned int plane_ty
/* INVALID marks the end of the list. */
add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_INVALID);
 
-   if (!*mods)
-   return -ENOMEM;
-
return 0;
 }
 
-- 
2.25.1



[PATCH] drm/amd/display: Add check for memory allocation

2022-09-26 Thread Jiasheng Jiang
As kzalloc and dm_helpers_allocate_gpu_mem can return NULL pointer,
it should be better to check the return value and return error.
Moreover, the return value of dcn32_clk_mgr_construct should be checked
by cascade.

Fixes: 265280b99822 ("drm/amd/display: add CLKMGR changes for DCN32/321")
Signed-off-by: Jiasheng Jiang 
---
 .../drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c   | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c 
b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c
index c6785969eb1a..3dc04d780fbf 100644
--- a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c
+++ b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c
@@ -718,7 +718,7 @@ static struct clk_mgr_funcs dcn32_funcs = {
.is_smu_present = dcn32_is_smu_present,
 };
 
-void dcn32_clk_mgr_construct(
+int dcn32_clk_mgr_construct(
struct dc_context *ctx,
struct clk_mgr_internal *clk_mgr,
struct pp_smu_funcs *pp_smu,
@@ -779,11 +779,19 @@ void dcn32_clk_mgr_construct(
clk_mgr->smu_present = false;
 
clk_mgr->base.bw_params = kzalloc(sizeof(*clk_mgr->base.bw_params), 
GFP_KERNEL);
+   if (!clk_mgr->base.bw_params)
+   return -ENOMEM;
 
/* need physical address of table to give to PMFW */
clk_mgr->wm_range_table = dm_helpers_allocate_gpu_mem(clk_mgr->base.ctx,
DC_MEM_ALLOC_TYPE_GART, sizeof(WatermarksExternal_t),
&clk_mgr->wm_range_table_addr);
+   if (!clk_mgr->wm_range_table) {
+   kfree(clk_mgr->base.bw_params);
+   return -ENOMEM;
+   }
+
+   return 0;
 }
 
 void dcn32_clk_mgr_destroy(struct clk_mgr_internal *clk_mgr)
-- 
2.25.1



[PATCH 1/2] video: fbdev: gbefb: Convert to use dev_groups

2022-09-01 Thread Jiasheng Jiang
The driver core supports the ability to handle the creation and removal
of device-specific sysfs files in a race-free manner. Moreover, it can
guarantee the success of creation. Therefore, it should be better to
convert to use dev_groups.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Jiasheng Jiang 
---
 drivers/video/fbdev/gbefb.c | 20 +++-
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/drivers/video/fbdev/gbefb.c b/drivers/video/fbdev/gbefb.c
index 6b4d5a7f3e15..1582c718329c 100644
--- a/drivers/video/fbdev/gbefb.c
+++ b/drivers/video/fbdev/gbefb.c
@@ -1072,17 +1072,12 @@ static ssize_t gbefb_show_rev(struct device *device, 
struct device_attribute *at
 
 static DEVICE_ATTR(revision, S_IRUGO, gbefb_show_rev, NULL);
 
-static void gbefb_remove_sysfs(struct device *dev)
-{
-   device_remove_file(dev, &dev_attr_size);
-   device_remove_file(dev, &dev_attr_revision);
-}
-
-static void gbefb_create_sysfs(struct device *dev)
-{
-   device_create_file(dev, &dev_attr_size);
-   device_create_file(dev, &dev_attr_revision);
-}
+static struct attribute *gbefb_attrs[] = {
+   &dev_attr_size.attr,
+   &dev_attr_revision.attr,
+   NULL,
+};
+ATTRIBUTE_GROUPS(gbefb);
 
 /*
  * Initialization
@@ -1221,7 +1216,6 @@ static int gbefb_probe(struct platform_device *p_dev)
}
 
platform_set_drvdata(p_dev, info);
-   gbefb_create_sysfs(&p_dev->dev);
 
fb_info(info, "%s rev %d @ 0x%08x using %dkB memory\n",
info->fix.id, gbe_revision, (unsigned)GBE_BASE,
@@ -1248,7 +1242,6 @@ static int gbefb_remove(struct platform_device* p_dev)
gbe_turn_off();
arch_phys_wc_del(par->wc_cookie);
release_mem_region(GBE_BASE, sizeof(struct sgi_gbe));
-   gbefb_remove_sysfs(&p_dev->dev);
framebuffer_release(info);
 
return 0;
@@ -1259,6 +1252,7 @@ static struct platform_driver gbefb_driver = {
.remove = gbefb_remove,
.driver = {
.name = "gbefb",
+   .dev_groups = gbefb_groups,
},
 };
 
-- 
2.25.1



[PATCH 2/2] video: fbdev: gbefb: Remove unproper information

2022-09-01 Thread Jiasheng Jiang
When drivers are working properly, they are quiet.
Therefore, the fb_info() should be removed.

Signed-off-by: Jiasheng Jiang 
---
 drivers/video/fbdev/gbefb.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/video/fbdev/gbefb.c b/drivers/video/fbdev/gbefb.c
index 1582c718329c..7e39ab939691 100644
--- a/drivers/video/fbdev/gbefb.c
+++ b/drivers/video/fbdev/gbefb.c
@@ -1217,10 +1217,6 @@ static int gbefb_probe(struct platform_device *p_dev)
 
platform_set_drvdata(p_dev, info);
 
-   fb_info(info, "%s rev %d @ 0x%08x using %dkB memory\n",
-   info->fix.id, gbe_revision, (unsigned)GBE_BASE,
-   gbe_mem_size >> 10);
-
return 0;
 
 out_gbe_unmap:
-- 
2.25.1



[PATCH v2] drm: bridge: adv7511: Add check for mipi_dsi_driver_register

2022-06-02 Thread Jiasheng Jiang
As mipi_dsi_driver_register could return error if fails,
it should be better to check the return value and return error
if fails.
Moreover, if i2c_add_driver fails,  mipi_dsi_driver_register
should be reverted.

Fixes: 1e4d58cd7f88 ("drm/bridge: adv7533: Create a MIPI DSI device")
Signed-off-by: Jiasheng Jiang 
---
Changelog:

v1 -> v2

*Change 1. Add the mipi_dsi_driver_unregister if i2c_add_driver fails.
---
 drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c 
b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
index 5bb9300040dd..2275d15d4a8b 100644
--- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
+++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
@@ -1392,10 +1392,21 @@ static struct i2c_driver adv7511_driver = {
 
 static int __init adv7511_init(void)
 {
-   if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
-   mipi_dsi_driver_register(&adv7533_dsi_driver);
+   int ret;
+
+   if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
+   ret = mipi_dsi_driver_register(&adv7533_dsi_driver);
+   if (ret)
+   return ret;
+   }
 
-   return i2c_add_driver(&adv7511_driver);
+   ret = i2c_add_driver(&adv7511_driver);
+   if (ret) {
+   if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
+   mipi_dsi_driver_unregister(&adv7533_dsi_driver);
+   }
+
+   return ret;
 }
 module_init(adv7511_init);
 
-- 
2.25.1



Re: Re: [PATCH] drm: bridge: adv7511: Add check for mipi_dsi_driver_register

2022-06-01 Thread Jiasheng Jiang
On Wed, Jun 01, 2022 at 05:15:37PM +0800, Laurent Pinchart wrote:
>> Well, as far as I am concerned, the adv7511_exit() in the same file has 
>> already dealt with the issue.
>> Therefore, it might not be necessary to add another 
>> mipi_dsi_driver_unregister().
> 
> The issue is that adv7511_exit() is not called if adv7511_init() fails.

Sorry, I can not find the caller of adv7511_init().
Please give me more detail.

Thanks,
Jiang



Re: Re: [PATCH] drm: bridge: adv7511: Add check for mipi_dsi_driver_register

2022-06-01 Thread Jiasheng Jiang
On Wed, Jun 01, 2022 at 02:52:00PM +0800, Laurent Pinchart wrote:
>>  static int __init adv7511_init(void)
>>  {
>> -if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
>> -mipi_dsi_driver_register(&adv7533_dsi_driver);
>> +int ret;
>> +
>> +if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
>> +ret = mipi_dsi_driver_register(&adv7533_dsi_driver);
>> +if (ret)
>> +return ret;
>> +}
>>  
>>  return i2c_add_driver(&adv7511_driver);
> 
> While at it, should this then call mipi_dsi_driver_unregister() on
> failure ?

Well, as far as I am concerned, the adv7511_exit() in the same file has already 
dealt with the issue.
Therefore, it might not be necessary to add another 
mipi_dsi_driver_unregister().

Thanks,
Jiang



[PATCH] drm: bridge: adv7511: Add check for mipi_dsi_driver_register

2022-05-31 Thread Jiasheng Jiang
As mipi_dsi_driver_register could return error if fails,
it should be better to check the return value and return error
if fails.

Fixes: 1e4d58cd7f88 ("drm/bridge: adv7533: Create a MIPI DSI device")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c 
b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
index 5bb9300040dd..795855b41eb2 100644
--- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
+++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
@@ -1392,8 +1392,13 @@ static struct i2c_driver adv7511_driver = {
 
 static int __init adv7511_init(void)
 {
-   if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
-   mipi_dsi_driver_register(&adv7533_dsi_driver);
+   int ret;
+
+   if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
+   ret = mipi_dsi_driver_register(&adv7533_dsi_driver);
+   if (ret)
+   return ret;
+   }
 
return i2c_add_driver(&adv7511_driver);
 }
-- 
2.25.1



[PATCH] drm/panel/raspberrypi-touchscreen: Add check for mipi_dsi_driver_register

2022-05-31 Thread Jiasheng Jiang
As mipi_dsi_driver_register could return error if fails,
it should be better to check the return value and return error
if fails.

Fixes: 2f733d6194bd ("drm/panel: Add support for the Raspberry Pi 7" 
Touchscreen.")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c 
b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
index 145047e19394..cc90afbf4b3e 100644
--- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
+++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
@@ -498,7 +498,12 @@ static struct i2c_driver rpi_touchscreen_driver = {
 
 static int __init rpi_touchscreen_init(void)
 {
-   mipi_dsi_driver_register(&rpi_touchscreen_dsi_driver);
+   int ret;
+
+   ret = mipi_dsi_driver_register(&rpi_touchscreen_dsi_driver);
+   if (ret)
+   return ret;
+
return i2c_add_driver(&rpi_touchscreen_driver);
 }
 module_init(rpi_touchscreen_init);
-- 
2.25.1



[PATCH] drm/xlnx: Handle error for dma_set_mask

2022-03-02 Thread Jiasheng Jiang
As the potential failure of the dma_set_mask(),
it should be better to check it and return error
if fails.

Fixes: d76271d22694 ("drm: xlnx: DRM/KMS driver for Xilinx ZynqMP DisplayPort 
Subsystem")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/xlnx/zynqmp_dpsub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xlnx/zynqmp_dpsub.c 
b/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
index ac37053412a1..5bb42d0a2de9 100644
--- a/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
+++ b/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
@@ -200,7 +200,9 @@ static int zynqmp_dpsub_probe(struct platform_device *pdev)
dpsub->dev = &pdev->dev;
platform_set_drvdata(pdev, dpsub);
 
-   dma_set_mask(dpsub->dev, DMA_BIT_MASK(ZYNQMP_DISP_MAX_DMA_BIT));
+   ret = dma_set_mask(dpsub->dev, DMA_BIT_MASK(ZYNQMP_DISP_MAX_DMA_BIT));
+   if (ret)
+   return ret;
 
/* Try the reserved memory. Proceed if there's none. */
of_reserved_mem_device_init(&pdev->dev);
-- 
2.25.1



[PATCH] drm/i915/gt: Handle errors for i915_gem_object_trylock

2022-03-01 Thread Jiasheng Jiang
As the potential failure of the i915_gem_object_trylock(),
it should be better to check it and return error if fails.

Fixes: 94ce0d65076c ("drm/i915/gt: Setup a default migration context on the GT")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/i915/gt/selftest_migrate.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/gt/selftest_migrate.c 
b/drivers/gpu/drm/i915/gt/selftest_migrate.c
index fa4293d2944f..79c6c68f7316 100644
--- a/drivers/gpu/drm/i915/gt/selftest_migrate.c
+++ b/drivers/gpu/drm/i915/gt/selftest_migrate.c
@@ -465,7 +465,11 @@ create_init_lmem_internal(struct intel_gt *gt, size_t sz, 
bool try_lmem)
return obj;
}
 
-   i915_gem_object_trylock(obj, NULL);
+   if (!i915_gem_object_trylock(obj, NULL)) {
+   i915_gem_object_put(obj);
+   return ERR_PTR(-EBUSY);
+   }
+
err = i915_gem_object_pin_pages(obj);
if (err) {
i915_gem_object_unlock(obj);
-- 
2.25.1



Re: [PATCH] drm/arm/mali: Check for NULL pointer after calling kzalloc

2022-01-14 Thread Jiasheng Jiang
Sorry, I just noticed that I have already sent the patch before and it has been 
reviewed.
Please ignore this one.

Sincerely thanks,
Jiang



[PATCH] drm/arm/mali: Check for NULL pointer after calling kzalloc

2022-01-14 Thread Jiasheng Jiang
As the possible failure of the kzalloc(), mw_state could be NULL
pointer.
Therefore, it should be better to check it in order to avoid the
dereference of the NULL pointer, like the kzalloc() in
malidp_mw_connector_duplicate_state().
If fails, we can directly use the 'NULL' instead of the
'&mw_state->base' and __drm_atomic_helper_connector_reset() will deal
with it correctly.

Fixes: 8cbc5caf36ef ("drm: mali-dp: Add writeback connector")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/arm/malidp_mw.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_mw.c
index f5847a79dd7e..96752353b5a1 100644
--- a/drivers/gpu/drm/arm/malidp_mw.c
+++ b/drivers/gpu/drm/arm/malidp_mw.c
@@ -70,7 +70,11 @@ static void malidp_mw_connector_reset(struct drm_connector 
*connector)
__drm_atomic_helper_connector_destroy_state(connector->state);
 
kfree(connector->state);
-   __drm_atomic_helper_connector_reset(connector, &mw_state->base);
+
+   if (!mw_state)
+   __drm_atomic_helper_connector_reset(connector, NULL);
+   else
+   __drm_atomic_helper_connector_reset(connector, &mw_state->base);
 }
 
 static enum drm_connector_status
-- 
2.25.1



[PATCH] drm/rockchip: Check for NULL pointer after calling kzalloc

2022-01-14 Thread Jiasheng Jiang
As the possible failure of the kzalloc(), crtc_state could be NULL
pointer.
Therefore, it should be better to check it in order to avoid the
dereference of the NULL pointer, like the kzalloc() in
vop_crtc_duplicate_state().
If fails, we can directly use the 'NULL' instead of the
'&crtc_state->base' and __drm_atomic_helper_crtc_duplicate_state() will
deal with it correctly.

Fixes: dc0b408f5a87 ("drm/rockchip: allocate correct crtc state structure on 
reset")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index 3e8d9e2d1b67..db672ff5e37b 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -1577,7 +1577,10 @@ static void vop_crtc_reset(struct drm_crtc *crtc)
if (crtc->state)
vop_crtc_destroy_state(crtc, crtc->state);
 
-   __drm_atomic_helper_crtc_reset(crtc, &crtc_state->base);
+   if (!crtc_state)
+   __drm_atomic_helper_crtc_reset(crtc, NULL);
+   else
+   __drm_atomic_helper_crtc_reset(crtc, &crtc_state->base);
 }
 
 #ifdef CONFIG_DRM_ANALOGIX_DP
-- 
2.25.1



[PATCH v2] drm/v3d/v3d_drv: Check for error num after setting mask

2022-01-09 Thread Jiasheng Jiang
Because of the possible failure of the dma_supported(), the
dma_set_mask_and_coherent() may return error num.
Therefore, it should be better to check it and return the error if
fails.
Also, we can create a variable for the mask to solve the
alignment issue.

Fixes: 334dd38a3878 ("drm/v3d: Set dma_mask as well as coherent_dma_mask")
Signed-off-by: Jiasheng Jiang 
Reviewed-by: Melissa Wen 
---
Changelog:

v1 -> v2

* Change 1. Add a variable for the mask.
---
 drivers/gpu/drm/v3d/v3d_drv.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/v3d/v3d_drv.c b/drivers/gpu/drm/v3d/v3d_drv.c
index 9403c3b36aca..6407a006d6ec 100644
--- a/drivers/gpu/drm/v3d/v3d_drv.c
+++ b/drivers/gpu/drm/v3d/v3d_drv.c
@@ -221,6 +221,7 @@ static int v3d_platform_drm_probe(struct platform_device 
*pdev)
int ret;
u32 mmu_debug;
u32 ident1;
+   u64 mask;
 
 
v3d = devm_drm_dev_alloc(dev, &v3d_drm_driver, struct v3d_dev, drm);
@@ -240,8 +241,11 @@ static int v3d_platform_drm_probe(struct platform_device 
*pdev)
return ret;
 
mmu_debug = V3D_READ(V3D_MMU_DEBUG_INFO);
-   dma_set_mask_and_coherent(dev,
-   DMA_BIT_MASK(30 + V3D_GET_FIELD(mmu_debug, V3D_MMU_PA_WIDTH)));
+   mask = DMA_BIT_MASK(30 + V3D_GET_FIELD(mmu_debug, V3D_MMU_PA_WIDTH));
+   ret = dma_set_mask_and_coherent(dev, mask);
+   if (ret)
+   return ret;
+
v3d->va_width = 30 + V3D_GET_FIELD(mmu_debug, V3D_MMU_VA_WIDTH);
 
ident1 = V3D_READ(V3D_HUB_IDENT1);
-- 
2.25.1



[PATCH] drm/panfrost: Check for error num after setting mask

2022-01-05 Thread Jiasheng Jiang
Because of the possible failure of the dma_supported(), the
dma_set_mask_and_coherent() may return error num.
Therefore, it should be better to check it and return the error if
fails.

Fixes: d9b631f0a0c4 ("drm/panfrost: Set DMA masks earlier")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/panfrost/panfrost_gpu.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/panfrost/panfrost_gpu.c 
b/drivers/gpu/drm/panfrost/panfrost_gpu.c
index 2aae636f1cf5..107ad2d764ec 100644
--- a/drivers/gpu/drm/panfrost/panfrost_gpu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_gpu.c
@@ -359,8 +359,11 @@ int panfrost_gpu_init(struct panfrost_device *pfdev)
 
panfrost_gpu_init_features(pfdev);
 
-   dma_set_mask_and_coherent(pfdev->dev,
+   err = dma_set_mask_and_coherent(pfdev->dev,
DMA_BIT_MASK(FIELD_GET(0xff00, pfdev->features.mmu_features)));
+   if (err)
+   return err;
+
dma_set_max_seg_size(pfdev->dev, UINT_MAX);
 
irq = platform_get_irq_byname(to_platform_device(pfdev->dev), "gpu");
-- 
2.25.1



[PATCH] drm/v3d/v3d_drv: Check for error num after setting mask

2022-01-05 Thread Jiasheng Jiang
Because of the possible failure of the dma_supported(), the
dma_set_mask_and_coherent() may return error num.
Therefore, it should be better to check it and return the error if
fails.

Fixes: 334dd38a3878 ("drm/v3d: Set dma_mask as well as coherent_dma_mask")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/v3d/v3d_drv.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/v3d/v3d_drv.c b/drivers/gpu/drm/v3d/v3d_drv.c
index 99e22beea90b..bedd52195723 100644
--- a/drivers/gpu/drm/v3d/v3d_drv.c
+++ b/drivers/gpu/drm/v3d/v3d_drv.c
@@ -232,8 +232,11 @@ static int v3d_platform_drm_probe(struct platform_device 
*pdev)
return ret;
 
mmu_debug = V3D_READ(V3D_MMU_DEBUG_INFO);
-   dma_set_mask_and_coherent(dev,
+   ret = dma_set_mask_and_coherent(dev,
DMA_BIT_MASK(30 + V3D_GET_FIELD(mmu_debug, V3D_MMU_PA_WIDTH)));
+   if (ret)
+   return ret;
+
v3d->va_width = 30 + V3D_GET_FIELD(mmu_debug, V3D_MMU_VA_WIDTH);
 
ident1 = V3D_READ(V3D_HUB_IDENT1);
-- 
2.25.1



[PATCH] misc: fastrpc: Check for error num after setting mask

2022-01-05 Thread Jiasheng Jiang
Because of the possible failure of the dma_supported(), the
dma_set_mask_and_coherent() may return error num.
Therefore, it should be better to check it and return the error if
fails.

Fixes: f6f9279f2bf0 ("misc: fastrpc: Add Qualcomm fastrpc basic driver model")
Signed-off-by: Jiasheng Jiang 
---
 drivers/misc/fastrpc.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index beda610e6b30..dd1c4a75bb1d 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1644,7 +1644,12 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device 
*rpdev)
kref_init(&data->refcount);
 
dev_set_drvdata(&rpdev->dev, data);
-   dma_set_mask_and_coherent(rdev, DMA_BIT_MASK(32));
+   err = dma_set_mask_and_coherent(rdev, DMA_BIT_MASK(32));
+   if (err) {
+   kfree(data);
+   return err;
+   }
+
INIT_LIST_HEAD(&data->users);
spin_lock_init(&data->lock);
idr_init(&data->ctx_idr);
-- 
2.25.1



[PATCH] drm/amdkfd: Check for null pointer after calling kmemdup

2022-01-05 Thread Jiasheng Jiang
As the possible failure of the allocation, kmemdup() may return NULL
pointer.
Therefore, it should be better to check the 'props2' in order to prevent
the dereference of NULL pointer.

Fixes: 3a87177eb141 ("drm/amdkfd: Add topology support for dGPUs")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
index c60e82697385..d15380c65c6d 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
@@ -410,6 +410,9 @@ static int kfd_parse_subtype_iolink(struct 
crat_subtype_iolink *iolink,
return -ENODEV;
/* same everything but the other direction */
props2 = kmemdup(props, sizeof(*props2), GFP_KERNEL);
+   if (!props2)
+   return -ENOMEM;
+
props2->node_from = id_to;
props2->node_to = id_from;
props2->kobj = NULL;
-- 
2.25.1



[PATCH] drm/imx: imx-ldb: Check for null pointer after calling kmemdup

2022-01-04 Thread Jiasheng Jiang
As the possible failure of the allocation, kmemdup() may return NULL
pointer.
Therefore, it should be better to check the return value of kmemdup()
and return error if fails.

Fixes: dc80d7038883 ("drm/imx-ldb: Add support to drm-bridge")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/imx/imx-ldb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c
index 53132ddf9587..f9880a779678 100644
--- a/drivers/gpu/drm/imx/imx-ldb.c
+++ b/drivers/gpu/drm/imx/imx-ldb.c
@@ -574,6 +574,8 @@ static int imx_ldb_panel_ddc(struct device *dev,
edidp = of_get_property(child, "edid", &edid_len);
if (edidp) {
channel->edid = kmemdup(edidp, edid_len, GFP_KERNEL);
+   if (!channel->edid)
+   return -ENOMEM;
} else if (!channel->panel) {
/* fallback to display-timings node */
ret = of_get_drm_display_mode(child,
-- 
2.25.1



[PATCH v2] video: fbdev: Check for null res pointer

2021-12-20 Thread Jiasheng Jiang
The return value of platform_get_resource() needs to be checked.
To avoid use of error pointer in case that there is no suitable resource.

Fixes: f7018c213502 ("video: move fbdev to drivers/video/fbdev")
Signed-off-by: Jiasheng Jiang 
---
Changelog:

v1 -> v2

*Change 1. Correct the commit message.
---
 drivers/video/fbdev/imxfb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c
index ad598257ab38..68288756 100644
--- a/drivers/video/fbdev/imxfb.c
+++ b/drivers/video/fbdev/imxfb.c
@@ -1083,6 +1083,8 @@ static int imxfb_remove(struct platform_device *pdev)
struct resource *res;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!res)
+   return -EINVAL;
 
imxfb_disable_controller(fbi);
 
-- 
2.25.1



[PATCH] video: fbdev: Check for null res pointer

2021-12-19 Thread Jiasheng Jiang
The return value of platform_get_resource() needs to be checked.
To avoid use of error pointer in case of the failure of alloc.

Fixes: f7018c213502 ("video: move fbdev to drivers/video/fbdev")
Signed-off-by: Jiasheng Jiang 
---
 drivers/video/fbdev/imxfb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c
index ad598257ab38..68288756 100644
--- a/drivers/video/fbdev/imxfb.c
+++ b/drivers/video/fbdev/imxfb.c
@@ -1083,6 +1083,8 @@ static int imxfb_remove(struct platform_device *pdev)
struct resource *res;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!res)
+   return -EINVAL;
 
imxfb_disable_controller(fbi);
 
-- 
2.25.1



[PATCH] drm/amdgpu: potential dereference of null pointer

2021-12-16 Thread Jiasheng Jiang
The return value of dma_alloc_coherent() needs to be checked.
To avoid use of null pointer in memcpy_toio() in case of the failure of
alloc.

Fixes: 57430471e2fa ("drm/amdgpu: Add support for USBC PD FW download")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index a09483beb968..613e25bf87e5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -3034,6 +3034,10 @@ static ssize_t psp_usbc_pd_fw_sysfs_write(struct device 
*dev,
 
/* We need contiguous physical mem to place the FW  for psp to access */
cpu_addr = dma_alloc_coherent(adev->dev, usbc_pd_fw->size, &dma_addr, 
GFP_KERNEL);
+   if (!cpu_addr) {
+   ret = -ENOMEM;
+   goto rel_buf;
+   }
 
ret = dma_mapping_error(adev->dev, dma_addr);
if (ret)
-- 
2.25.1



[PATCH] drm/nouveau/acr: potential dereference of null pointer

2021-12-15 Thread Jiasheng Jiang
The return value of kmalloc() needs to be checked.
To avoid use in memcpy() in case of the failure of alloc.

Fixes: 22dcda45a3d1 ("drm/nouveau/acr: implement new subdev to replace "secure 
boot"")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c 
b/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c
index 667fa016496e..776573e77988 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c
@@ -143,6 +143,9 @@ nvkm_acr_hsfw_load_bl(struct nvkm_acr *acr, const char 
*name, int ver,
hsfw->imem_size = desc->code_size;
hsfw->imem_tag = desc->start_tag;
hsfw->imem = kmalloc(desc->code_size, GFP_KERNEL);
+   if (!hsfw->imem)
+   return -ENOMEM;
+
memcpy(hsfw->imem, data + desc->code_off, desc->code_size);
 
nvkm_firmware_put(fw);
-- 
2.25.1



[PATCH v3] drm: mali-dp: potential dereference of null pointer

2021-12-14 Thread Jiasheng Jiang
The return value of kzalloc() needs to be checked.
To avoid use of null pointer '&state->base' in case of the
failure of alloc.

Fixes: 99665d072183 ("drm: mali-dp: add malidp_crtc_state struct")
Signed-off-by: Jiasheng Jiang 
Reviewed-by: Brian Starkey 
---
Changelog:

v2 -> v3

*Change 1. Change reported to reviewed.
---
 drivers/gpu/drm/arm/malidp_crtc.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/malidp_crtc.c 
b/drivers/gpu/drm/arm/malidp_crtc.c
index 494075ddbef6..b5928b52e279 100644
--- a/drivers/gpu/drm/arm/malidp_crtc.c
+++ b/drivers/gpu/drm/arm/malidp_crtc.c
@@ -487,7 +487,10 @@ static void malidp_crtc_reset(struct drm_crtc *crtc)
if (crtc->state)
malidp_crtc_destroy_state(crtc, crtc->state);
 
-   __drm_atomic_helper_crtc_reset(crtc, &state->base);
+   if (state)
+   __drm_atomic_helper_crtc_reset(crtc, &state->base);
+   else
+   __drm_atomic_helper_crtc_reset(crtc, NULL);
 }
 
 static int malidp_crtc_enable_vblank(struct drm_crtc *crtc)
-- 
2.25.1



[PATCH v2] drm: mali-dp: potential dereference of null pointer

2021-12-14 Thread Jiasheng Jiang
The return value of kzalloc() needs to be checked.
To avoid use of null pointer '&state->base' in case of the
failure of alloc.

Fixes: 99665d072183 ("drm: mali-dp: add malidp_crtc_state struct")
Signed-off-by: Jiasheng Jiang 
Reported-by: Brian Starkey 
---
Changelog:

v1 -> v2

*Change 1. Add r-p.
---
 drivers/gpu/drm/arm/malidp_crtc.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/malidp_crtc.c 
b/drivers/gpu/drm/arm/malidp_crtc.c
index 494075ddbef6..b5928b52e279 100644
--- a/drivers/gpu/drm/arm/malidp_crtc.c
+++ b/drivers/gpu/drm/arm/malidp_crtc.c
@@ -487,7 +487,10 @@ static void malidp_crtc_reset(struct drm_crtc *crtc)
if (crtc->state)
malidp_crtc_destroy_state(crtc, crtc->state);
 
-   __drm_atomic_helper_crtc_reset(crtc, &state->base);
+   if (state)
+   __drm_atomic_helper_crtc_reset(crtc, &state->base);
+   else
+   __drm_atomic_helper_crtc_reset(crtc, NULL);
 }
 
 static int malidp_crtc_enable_vblank(struct drm_crtc *crtc)
-- 
2.25.1



[PATCH] drm: mali-dp: potential dereference of null pointer

2021-12-14 Thread Jiasheng Jiang
The return value of kzalloc() needs to be checked.
To avoid use of null pointer '&state->base' in case of the
failure of alloc.

Fixes: 99665d072183 ("drm: mali-dp: add malidp_crtc_state struct")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/arm/malidp_crtc.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/malidp_crtc.c 
b/drivers/gpu/drm/arm/malidp_crtc.c
index 494075ddbef6..b5928b52e279 100644
--- a/drivers/gpu/drm/arm/malidp_crtc.c
+++ b/drivers/gpu/drm/arm/malidp_crtc.c
@@ -487,7 +487,10 @@ static void malidp_crtc_reset(struct drm_crtc *crtc)
if (crtc->state)
malidp_crtc_destroy_state(crtc, crtc->state);
 
-   __drm_atomic_helper_crtc_reset(crtc, &state->base);
+   if (state)
+   __drm_atomic_helper_crtc_reset(crtc, &state->base);
+   else
+   __drm_atomic_helper_crtc_reset(crtc, NULL);
 }
 
 static int malidp_crtc_enable_vblank(struct drm_crtc *crtc)
-- 
2.25.1



[PATCH] drm/arm/mali: potential dereference of null pointer

2021-12-14 Thread Jiasheng Jiang
The return value of kzalloc() needs to be checked.
To avoid use of null pointer '&mw_state->base' in case of the
failure of alloc.

Fixes: 8cbc5caf36ef ("drm: mali-dp: Add writeback connector")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/arm/malidp_mw.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_mw.c
index f5847a79dd7e..612d386ee7d2 100644
--- a/drivers/gpu/drm/arm/malidp_mw.c
+++ b/drivers/gpu/drm/arm/malidp_mw.c
@@ -70,7 +70,11 @@ static void malidp_mw_connector_reset(struct drm_connector 
*connector)
__drm_atomic_helper_connector_destroy_state(connector->state);
 
kfree(connector->state);
-   __drm_atomic_helper_connector_reset(connector, &mw_state->base);
+
+   if (mw_state)
+   __drm_atomic_helper_connector_reset(connector, &mw_state->base);
+   else
+   __drm_atomic_helper_connector_reset(connector, NULL);
 }
 
 static enum drm_connector_status
-- 
2.25.1



[PATCH v2] drm/ast: potential dereference of null pointer

2021-12-13 Thread Jiasheng Jiang
The return value of kzalloc() needs to be checked.
To avoid use of null pointer '&ast_state->base' in case of the
failure of alloc.

Fixes: f0adbc382b8b ("drm/ast: Allocate initial CRTC state of the correct size")
Signed-off-by: Jiasheng Jiang 
---
Changelog:

v1 -> v2

*Change 1. Add the else statement that calling
__drm_atomic_helper_crtc_reset() with a state of NULL.
---
 drivers/gpu/drm/ast/ast_mode.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index 36d9575aa27b..65099f0359f9 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -1120,7 +1120,10 @@ static void ast_crtc_reset(struct drm_crtc *crtc)
if (crtc->state)
crtc->funcs->atomic_destroy_state(crtc, crtc->state);
 
-   __drm_atomic_helper_crtc_reset(crtc, &ast_state->base);
+   if (ast_state)
+   __drm_atomic_helper_crtc_reset(crtc, &ast_state->base);
+   else
+   __drm_atomic_helper_crtc_reset(crtc, NULL);
 }
 
 static struct drm_crtc_state *
-- 
2.25.1



[PATCH] drm/ast: potential dereference of null pointer

2021-12-13 Thread Jiasheng Jiang
The return value of kzalloc() needs to be checked.
To avoid use of null pointer '&ast_state->base' in case of the
failure of alloc.

Fixes: f0adbc382b8b ("drm/ast: Allocate initial CRTC state of the correct size")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/ast/ast_mode.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index 36d9575aa27b..65099f0359f9 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -1120,7 +1120,10 @@ static void ast_crtc_reset(struct drm_crtc *crtc)
if (crtc->state)
crtc->funcs->atomic_destroy_state(crtc, crtc->state);
 
-   __drm_atomic_helper_crtc_reset(crtc, &ast_state->base);
+   if (ast_state)
+   __drm_atomic_helper_crtc_reset(crtc, &ast_state->base);
+   else
+   __drm_atomic_helper_crtc_reset(crtc, NULL);
 }
 
 static struct drm_crtc_state *
-- 
2.25.1



[PATCH] drm/ast: potential dereference of null pointer

2021-12-12 Thread Jiasheng Jiang
he return value of kzalloc() needs to be checked.
To avoid use of null pointer '&ast_state->base' in case of the
failure of alloc.

Fixes: f0adbc382b8b ("drm/ast: Allocate initial CRTC state of the correct size")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/ast/ast_mode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index 36d9575aa27b..67f8e3f90ea2 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -1120,7 +1120,8 @@ static void ast_crtc_reset(struct drm_crtc *crtc)
if (crtc->state)
crtc->funcs->atomic_destroy_state(crtc, crtc->state);
 
-   __drm_atomic_helper_crtc_reset(crtc, &ast_state->base);
+   if (ast_state)
+   __drm_atomic_helper_crtc_reset(crtc, &ast_state->base);
 }
 
 static struct drm_crtc_state *
-- 
2.25.1



[PATCH] drm/lima: Handle dma_set_coherent_mask error codes

2021-12-06 Thread Jiasheng Jiang
The return value of dma_set_coherent_mask() is not always 0.
To catch the exception in case that dma is not support the mask.

Fixes: a1d2a6339961 ("drm/lima: driver for ARM Mali4xx GPUs")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/lima/lima_device.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/lima/lima_device.c 
b/drivers/gpu/drm/lima/lima_device.c
index 65fdca366e41..75e9a2060b47 100644
--- a/drivers/gpu/drm/lima/lima_device.c
+++ b/drivers/gpu/drm/lima/lima_device.c
@@ -356,7 +356,9 @@ int lima_device_init(struct lima_device *ldev)
struct platform_device *pdev = to_platform_device(ldev->dev);
int err, i;
 
-   dma_set_coherent_mask(ldev->dev, DMA_BIT_MASK(32));
+   err = dma_set_coherent_mask(ldev->dev, DMA_BIT_MASK(32));
+   if (err)
+   return err;
 
err = lima_clk_init(ldev);
if (err)
-- 
2.25.1



Re: Re: [PATCH] drm: mxsfb: Check NULL pointer

2021-11-04 Thread Jiasheng Jiang
On 11/3/21 8:58 AM, Marek Vasut wrote:
>> As we see in the drm_connector_list_iter_next(), it could return
>> NULL. In order to avoid the use of the NULL pointer, it may be
>> better to check the return value.
>> 
>> Fixes: c42001e ("drm: mxsfb: Use drm_panel_bridge")
>> Signed-off-by: Jiasheng Jiang 
>> ---
>>   drivers/gpu/drm/mxsfb/mxsfb_drv.c | 2 ++
>>   1 file changed, 2 insertions(+)
>> 
>> diff --git a/drivers/gpu/drm/mxsfb/mxsfb_drv.c 
>> b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
>> index 6da9355..b875c11 100644
>> --- a/drivers/gpu/drm/mxsfb/mxsfb_drv.c
>> +++ b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
>> @@ -145,6 +145,8 @@ static int mxsfb_attach_bridge(struct mxsfb_drm_private 
>> *mxsfb)
>>   */
>>  drm_connector_list_iter_begin(drm, &iter);
>>  mxsfb->connector = drm_connector_list_iter_next(&iter);
>> +if (!mxsfb->connector)
>> +return 1;

> In which case does this happen failure happen ?
> What is the test case ?

As fas as I am concerned, 'connector_list' in the
drm_connector_list_iter_next() is initialized in the
drm_mode_config_init(), which is 'connector_list->next = connector_list'.
And therefore, the check in drm_connector_list_iter_next() that
'if (lhead->next == &config->connector_list)' is directly satisfied and
returns NULL.
I am not sure wheter it is designed on purpose. If not, please fix it.



[PATCH] drm: mxsfb: Check NULL pointer

2021-11-03 Thread Jiasheng Jiang
As we see in the drm_connector_list_iter_next(), it could return
NULL. In order to avoid the use of the NULL pointer, it may be
better to check the return value.

Fixes: c42001e ("drm: mxsfb: Use drm_panel_bridge")
Signed-off-by: Jiasheng Jiang 
---
 drivers/gpu/drm/mxsfb/mxsfb_drv.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/mxsfb/mxsfb_drv.c 
b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
index 6da9355..b875c11 100644
--- a/drivers/gpu/drm/mxsfb/mxsfb_drv.c
+++ b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
@@ -145,6 +145,8 @@ static int mxsfb_attach_bridge(struct mxsfb_drm_private 
*mxsfb)
 */
drm_connector_list_iter_begin(drm, &iter);
mxsfb->connector = drm_connector_list_iter_next(&iter);
+   if (!mxsfb->connector)
+   return 1;
drm_connector_list_iter_end(&iter);
 
return 0;
-- 
2.7.4