diff mbox series

drm/i915/display: fix missing null check on allocated dsb object

Message ID 20200616114221.73971-1-colin.king@canonical.com (mailing list archive)
State New, archived
Headers show
Series drm/i915/display: fix missing null check on allocated dsb object | expand

Commit Message

Colin King June 16, 2020, 11:42 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Currently there is no null check for a failed memory allocation
on the dsb object and without this a null pointer dereference
error can occur. Fix this by adding a null check.

Note: added a drm_err message in keeping with the error message style
in the function.

Addresses-Coverity: ("Dereference null return")
Fixes: afeda4f3b1c8 ("drm/i915/dsb: Pre allocate and late cleanup of cmd buffer")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpu/drm/i915/display/intel_dsb.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Dan Carpenter June 16, 2020, 11:54 a.m. UTC | #1
On Tue, Jun 16, 2020 at 12:42:21PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently there is no null check for a failed memory allocation
> on the dsb object and without this a null pointer dereference
> error can occur. Fix this by adding a null check.
> 
> Note: added a drm_err message in keeping with the error message style
> in the function.

Don't give in to peer pressure!  That's like being a lemming when Disney
film makers come to push you off the cliff to create the 1958 nature
film "White Wilderness".

regards,
dan carpenter
Colin King June 16, 2020, 11:56 a.m. UTC | #2
On 16/06/2020 12:54, Dan Carpenter wrote:
> On Tue, Jun 16, 2020 at 12:42:21PM +0100, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Currently there is no null check for a failed memory allocation
>> on the dsb object and without this a null pointer dereference
>> error can occur. Fix this by adding a null check.
>>
>> Note: added a drm_err message in keeping with the error message style
>> in the function.
> 
> Don't give in to peer pressure!  That's like being a lemming when Disney
> film makers come to push you off the cliff to create the 1958 nature
> film "White Wilderness".

:-)

> 
> regards,
> dan carpenter
>
Jani Nikula June 30, 2020, 11:28 a.m. UTC | #3
On Tue, 16 Jun 2020, Colin Ian King <colin.king@canonical.com> wrote:
> On 16/06/2020 12:54, Dan Carpenter wrote:
>> On Tue, Jun 16, 2020 at 12:42:21PM +0100, Colin King wrote:
>>> From: Colin Ian King <colin.king@canonical.com>
>>>
>>> Currently there is no null check for a failed memory allocation
>>> on the dsb object and without this a null pointer dereference
>>> error can occur. Fix this by adding a null check.
>>>
>>> Note: added a drm_err message in keeping with the error message style
>>> in the function.
>> 
>> Don't give in to peer pressure!  That's like being a lemming when Disney
>> film makers come to push you off the cliff to create the 1958 nature
>> film "White Wilderness".
>
> :-)

Pushed, thanks for the patch and smile.

BR,
Jani.


>
>> 
>> regards,
>> dan carpenter
>> 
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/intel_dsb.c b/drivers/gpu/drm/i915/display/intel_dsb.c
index 24e6d63e2d47..566fa72427b3 100644
--- a/drivers/gpu/drm/i915/display/intel_dsb.c
+++ b/drivers/gpu/drm/i915/display/intel_dsb.c
@@ -271,6 +271,10 @@  void intel_dsb_prepare(struct intel_crtc_state *crtc_state)
 		return;
 
 	dsb = kmalloc(sizeof(*dsb), GFP_KERNEL);
+	if (!dsb) {
+		drm_err(&i915->drm, "DSB object creation failed\n");
+		return;
+	}
 
 	wakeref = intel_runtime_pm_get(&i915->runtime_pm);