[2/3] drm/omap: fix possible NULL ref issue in tiler_reserve_2d

Message ID 20180329104038.29154-2-tomi.valkeinen@ti.com
State New
Headers show
Series
  • [1/3] drm/omap: fix uninitialized ret variable
Related show

Commit Message

Tomi Valkeinen March 29, 2018, 10:40 a.m.
tiler_reserve_2d allocates memory but does not check if it got the
memory. Add the check and return ENOMEM on failure.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
---
 drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Emil Velikov March 29, 2018, 11:02 a.m. | #1
On 29 March 2018 at 11:40, Tomi Valkeinen <tomi.valkeinen@ti.com> wrote:
> tiler_reserve_2d allocates memory but does not check if it got the
> memory. Add the check and return ENOMEM on failure.
>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
It's funny when the function call (kzalloc here) is just outside the context ;-)

Reviewed-by: Emil Velikov <emil.velikov@collabora.com>

-Emil
Laurent Pinchart April 3, 2018, 11:03 a.m. | #2
Hi Tomi,

Thank you for the patch.

On Thursday, 29 March 2018 13:40:37 EEST Tomi Valkeinen wrote:
> tiler_reserve_2d allocates memory but does not check if it got the
> memory. Add the check and return ENOMEM on failure.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
> ---
>  drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
> b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c index c40f90d2db82..28d93ece191e
> 100644
> --- a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
> +++ b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
> @@ -532,6 +532,9 @@ struct tiler_block *tiler_reserve_2d(enum tiler_fmt fmt,
> u16 w, unsigned long flags;
>  	u32 slot_bytes;
> 
> +	if (!block)
> +		return ERR_PTR(-ENOMEM);
> +

I'd write this as

	struct tiler_block *block;
	...

	block = kzalloc(sizeof(*block), GFP_KERNEL);
	if (!block)
		return ERR_PTR(-ENOMEM);

to make it clearer. I'll leave it up to you though, so in any case

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  	BUG_ON(!validfmt(fmt));
> 
>  	/* convert width/height to slots */

Patch

diff --git a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
index c40f90d2db82..28d93ece191e 100644
--- a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
+++ b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
@@ -532,6 +532,9 @@  struct tiler_block *tiler_reserve_2d(enum tiler_fmt fmt, u16 w,
 	unsigned long flags;
 	u32 slot_bytes;
 
+	if (!block)
+		return ERR_PTR(-ENOMEM);
+
 	BUG_ON(!validfmt(fmt));
 
 	/* convert width/height to slots */