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

Jiasheng Jiang posted 1 patch 4 years, 5 months ago
drivers/gpu/drm/imx/imx-ldb.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] drm/imx: imx-ldb: Check for null pointer after calling kmemdup
Posted by Jiasheng Jiang 4 years, 5 months ago
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 <jiasheng@iscas.ac.cn>
---
 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

Re: [PATCH] drm/imx: imx-ldb: Check for null pointer after calling kmemdup
Posted by Philipp Zabel 4 years, 3 months ago
On Mi, 2022-01-05 at 15:47 +0800, Jiasheng Jiang wrote:
> 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 <jiasheng@iscas.ac.cn>
> ---
>  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,

Thank you, applied to imx-drm/fixes.

regards
Philipp