[bug report] [media] vcodec: mediatek: Add Mediatek JPEG Decoder Driver

Dan Carpenter dan.carpenter at oracle.com
Thu Mar 17 04:21:18 PDT 2022


Hello Media Devs!

The patch b2f0d2724ba4: "[media] vcodec: mediatek: Add Mediatek JPEG
Decoder Driver" from Dec 14, 2016, leads to the following Smatch
static checker warning:

	drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_parse.c:140 mtk_jpeg_do_parse()
	warn: duplicate check 'notfound' (previous on line 67)

drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_parse.c
    57 static bool mtk_jpeg_do_parse(struct mtk_jpeg_dec_param *param, u8 *src_addr_va,
    58                               u32 src_size)
    59 {
    60         bool notfound = true;
    61         struct mtk_jpeg_stream stream;
    62 
    63         stream.addr = src_addr_va;
    64         stream.size = src_size;
    65         stream.curr = 0;
    66 
    67         while (notfound) {
    68                 int i, length, byte;
    69                 u32 word;
    70 
    71                 byte = read_byte(&stream);
    72                 if (byte == -1)
    73                         return false;
    74                 if (byte != 0xff)
    75                         continue;
    76                 do
    77                         byte = read_byte(&stream);
    78                 while (byte == 0xff);
    79                 if (byte == -1)
    80                         return false;
    81                 if (byte == 0)
    82                         continue;
    83 
    84                 length = 0;
    85                 switch (byte) {
    86                 case SOF0:
    87                         /* length */
    88                         if (read_word_be(&stream, &word))
    89                                 break;
    90 
    91                         /* precision */
    92                         if (read_byte(&stream) == -1)
    93                                 break;
    94 
    95                         if (read_word_be(&stream, &word))
    96                                 break;
    97                         param->pic_h = word;
    98 
    99                         if (read_word_be(&stream, &word))
    100                                 break;
    101                         param->pic_w = word;
    102 
    103                         param->comp_num = read_byte(&stream);
    104                         if (param->comp_num != 1 && param->comp_num != 3)
    105                                 break;
    106 
    107                         for (i = 0; i < param->comp_num; i++) {
    108                                 param->comp_id[i] = read_byte(&stream);
    109                                 if (param->comp_id[i] == -1)
    110                                         break;
    111 
    112                                 /* sampling */
    113                                 byte = read_byte(&stream);
    114                                 if (byte == -1)
    115                                         break;
    116                                 param->sampling_w[i] = (byte >> 4) & 0x0F;
    117                                 param->sampling_h[i] = byte & 0x0F;
    118 
    119                                 param->qtbl_num[i] = read_byte(&stream);
    120                                 if (param->qtbl_num[i] == -1)
    121                                         break;
    122                         }
    123 
    124                         notfound = !(i == param->comp_num);

Should this:

	if (i == param->comp_num)
		return true;

    125                         break;
    126                 case RST ... RST + 7:
    127                 case SOI:
    128                 case EOI:
    129                 case TEM:
    130                         break;
    131                 default:
    132                         if (read_word_be(&stream, &word))
    133                                 break;
    134                         length = (long)word - 2;
    135                         read_skip(&stream, length);
    136                         break;
    137                 }
    138         }
    139 
--> 140         return !notfound;

We know that "notfound" is false.  The double negatives confuse me.  I
guess that means it must be found here?

    141 }

regards,
dan carpenter



More information about the Linux-mediatek mailing list