All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [media] saa7146: fix a possible NULL pointer reference in saa7146_set_position
@ 2014-01-05  2:08 Ethan Zhao
  2014-01-05  6:14 ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Ethan Zhao @ 2014-01-05  2:08 UTC (permalink / raw)
  To: hans.verkuil, m.chehab, gregkh, mchehab; +Cc: linux-kernel, Ethan Zhao

Function saa7146_format_by_fourcc() may return NULL, reference of the returned
result would cause NULL pointer issue without checking.

Signed-off-by: Ethan Zhao <ethan.kernel@gmail.com>
---
 drivers/media/common/saa7146/saa7146_hlp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/media/common/saa7146/saa7146_hlp.c b/drivers/media/common/saa7146/saa7146_hlp.c
index be746d1..3e23eab 100644
--- a/drivers/media/common/saa7146/saa7146_hlp.c
+++ b/drivers/media/common/saa7146/saa7146_hlp.c
@@ -575,6 +575,7 @@ static void saa7146_set_position(struct saa7146_dev *dev, int w_x, int w_y, int
 	 */
 	u32 base = (u32)(unsigned long)vv->ov_fb.base;
 
+	int which = 1;
 	struct	saa7146_video_dma vdma1;
 
 	/* calculate memory offsets for picture, look if we shall top-down-flip */
@@ -608,10 +609,14 @@ static void saa7146_set_position(struct saa7146_dev *dev, int w_x, int w_y, int
 		vdma1.pitch *= -1;
 	}
 
-	vdma1.base_page = sfmt->swap;
+	if (sfmt)
+		vdma1.base_page = sfmt->swap;
+	else
+		which = 0;
+
 	vdma1.num_line_byte = (vv->standard->v_field<<16)+vv->standard->h_pixels;
 
-	saa7146_write_out_dma(dev, 1, &vdma1);
+	saa7146_write_out_dma(dev, which, &vdma1);
 }
 
 static void saa7146_set_output_format(struct saa7146_dev *dev, unsigned long palette)
-- 
1.8.3.4 (Apple Git-47)


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] [media] saa7146: fix a possible NULL pointer reference in saa7146_set_position
  2014-01-05  2:08 [PATCH] [media] saa7146: fix a possible NULL pointer reference in saa7146_set_position Ethan Zhao
@ 2014-01-05  6:14 ` Dmitry Torokhov
  2014-01-06  5:47   ` Ethan Zhao
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Torokhov @ 2014-01-05  6:14 UTC (permalink / raw)
  To: Ethan Zhao; +Cc: hans.verkuil, m.chehab, gregkh, mchehab, linux-kernel

On Sun, Jan 05, 2014 at 10:08:00AM +0800, Ethan Zhao wrote:
> Function saa7146_format_by_fourcc() may return NULL, reference of the returned
> result would cause NULL pointer issue without checking.
> 
> Signed-off-by: Ethan Zhao <ethan.kernel@gmail.com>
> ---
>  drivers/media/common/saa7146/saa7146_hlp.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/common/saa7146/saa7146_hlp.c b/drivers/media/common/saa7146/saa7146_hlp.c
> index be746d1..3e23eab 100644
> --- a/drivers/media/common/saa7146/saa7146_hlp.c
> +++ b/drivers/media/common/saa7146/saa7146_hlp.c
> @@ -575,6 +575,7 @@ static void saa7146_set_position(struct saa7146_dev *dev, int w_x, int w_y, int
>  	 */
>  	u32 base = (u32)(unsigned long)vv->ov_fb.base;
>  
> +	int which = 1;
>  	struct	saa7146_video_dma vdma1;
>  
>  	/* calculate memory offsets for picture, look if we shall top-down-flip */
> @@ -608,10 +609,14 @@ static void saa7146_set_position(struct saa7146_dev *dev, int w_x, int w_y, int
>  		vdma1.pitch *= -1;
>  	}
>  
> -	vdma1.base_page = sfmt->swap;
> +	if (sfmt)
> +		vdma1.base_page = sfmt->swap;
> +	else
> +		which = 0;
> +
>  	vdma1.num_line_byte = (vv->standard->v_field<<16)+vv->standard->h_pixels;
>  
> -	saa7146_write_out_dma(dev, 1, &vdma1);
> +	saa7146_write_out_dma(dev, which, &vdma1);

If saa7146_format_by_fourcc() returns NULL you'll crash much earlier
when trying to do

	int depth = sfmt->depth;

I am not familiar with the code by it seems you are papering over the
problem. Will we ever get here with unknown pixel format?

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [media] saa7146: fix a possible NULL pointer reference in saa7146_set_position
  2014-01-05  6:14 ` Dmitry Torokhov
@ 2014-01-06  5:47   ` Ethan Zhao
  0 siblings, 0 replies; 3+ messages in thread
From: Ethan Zhao @ 2014-01-06  5:47 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: hans.verkuil, m.chehab, Greg KH, mchehab, LKML

Dmitry,
   Yup,thank you point out that, need NULL pointer checking in
calculate_video_dma_grab_packed() ,  I am not familiar with saa7146
too. wouldn't paper over it, just a fix to pass code review.

Thanks,
Ethan

On Sun, Jan 5, 2014 at 2:14 PM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Sun, Jan 05, 2014 at 10:08:00AM +0800, Ethan Zhao wrote:
>> Function saa7146_format_by_fourcc() may return NULL, reference of the returned
>> result would cause NULL pointer issue without checking.
>>
>> Signed-off-by: Ethan Zhao <ethan.kernel@gmail.com>
>> ---
>>  drivers/media/common/saa7146/saa7146_hlp.c | 9 +++++++--
>>  1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/media/common/saa7146/saa7146_hlp.c b/drivers/media/common/saa7146/saa7146_hlp.c
>> index be746d1..3e23eab 100644
>> --- a/drivers/media/common/saa7146/saa7146_hlp.c
>> +++ b/drivers/media/common/saa7146/saa7146_hlp.c
>> @@ -575,6 +575,7 @@ static void saa7146_set_position(struct saa7146_dev *dev, int w_x, int w_y, int
>>        */
>>       u32 base = (u32)(unsigned long)vv->ov_fb.base;
>>
>> +     int which = 1;
>>       struct  saa7146_video_dma vdma1;
>>
>>       /* calculate memory offsets for picture, look if we shall top-down-flip */
>> @@ -608,10 +609,14 @@ static void saa7146_set_position(struct saa7146_dev *dev, int w_x, int w_y, int
>>               vdma1.pitch *= -1;
>>       }
>>
>> -     vdma1.base_page = sfmt->swap;
>> +     if (sfmt)
>> +             vdma1.base_page = sfmt->swap;
>> +     else
>> +             which = 0;
>> +
>>       vdma1.num_line_byte = (vv->standard->v_field<<16)+vv->standard->h_pixels;
>>
>> -     saa7146_write_out_dma(dev, 1, &vdma1);
>> +     saa7146_write_out_dma(dev, which, &vdma1);
>
> If saa7146_format_by_fourcc() returns NULL you'll crash much earlier
> when trying to do
>
>         int depth = sfmt->depth;
>
> I am not familiar with the code by it seems you are papering over the
> problem. Will we ever get here with unknown pixel format?
>
> Thanks.
>
> --
> Dmitry

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-06  5:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-05  2:08 [PATCH] [media] saa7146: fix a possible NULL pointer reference in saa7146_set_position Ethan Zhao
2014-01-05  6:14 ` Dmitry Torokhov
2014-01-06  5:47   ` Ethan Zhao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.