1
0
Fork 0

media: pwc-ctl: pChoose can't be NULL

The way the code works, compression will be a valid value (less or equal to 3)
on both set_video_mode_foo() calls at the beginning of the while() loop.

So, the value for pChoose can't be NULL.

Solves those smatch warnings:

	drivers/media/usb/pwc/pwc-ctrl.c: drivers/media/usb/pwc/pwc-ctrl.c:252 set_video_mode_Timon() warn: variable dereferenced before check 'pChoose' (see line 248)
	drivers/media/usb/pwc/pwc-ctrl.c: drivers/media/usb/pwc/pwc-ctrl.c:302 set_video_mode_Kiara() warn: variable dereferenced before check 'pChoose' (see line 298)

and simplifies the code a little bit.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
hifive-unleashed-5.2
Mauro Carvalho Chehab 2019-03-25 16:20:47 -04:00
parent 3d19cde7be
commit 4f777d011b
1 changed files with 9 additions and 8 deletions

View File

@ -242,14 +242,14 @@ static int set_video_mode_Timon(struct pwc_device *pdev, int size, int pixfmt,
fps = (frames / 5) - 1; fps = (frames / 5) - 1;
/* Find a supported framerate with progressively higher compression */ /* Find a supported framerate with progressively higher compression */
pChoose = NULL; do {
while (*compression <= 3) {
pChoose = &Timon_table[size][fps][*compression]; pChoose = &Timon_table[size][fps][*compression];
if (pChoose->alternate != 0) if (pChoose->alternate != 0)
break; break;
(*compression)++; (*compression)++;
} } while (*compression <= 3);
if (pChoose == NULL || pChoose->alternate == 0)
if (pChoose->alternate == 0)
return -ENOENT; /* Not supported. */ return -ENOENT; /* Not supported. */
if (send_to_cam) if (send_to_cam)
@ -279,7 +279,7 @@ static int set_video_mode_Timon(struct pwc_device *pdev, int size, int pixfmt,
static int set_video_mode_Kiara(struct pwc_device *pdev, int size, int pixfmt, static int set_video_mode_Kiara(struct pwc_device *pdev, int size, int pixfmt,
int frames, int *compression, int send_to_cam) int frames, int *compression, int send_to_cam)
{ {
const struct Kiara_table_entry *pChoose = NULL; const struct Kiara_table_entry *pChoose;
int fps, ret = 0; int fps, ret = 0;
if (size >= PSZ_MAX || *compression < 0 || *compression > 3) if (size >= PSZ_MAX || *compression < 0 || *compression > 3)
@ -293,13 +293,14 @@ static int set_video_mode_Kiara(struct pwc_device *pdev, int size, int pixfmt,
fps = (frames / 5) - 1; fps = (frames / 5) - 1;
/* Find a supported framerate with progressively higher compression */ /* Find a supported framerate with progressively higher compression */
while (*compression <= 3) { do {
pChoose = &Kiara_table[size][fps][*compression]; pChoose = &Kiara_table[size][fps][*compression];
if (pChoose->alternate != 0) if (pChoose->alternate != 0)
break; break;
(*compression)++; (*compression)++;
} } while (*compression <= 3);
if (pChoose == NULL || pChoose->alternate == 0)
if (pChoose->alternate == 0)
return -ENOENT; /* Not supported. */ return -ENOENT; /* Not supported. */
/* Firmware bug: video endpoint is 5, but commands are sent to endpoint 4 */ /* Firmware bug: video endpoint is 5, but commands are sent to endpoint 4 */