[bug report] lib: sparse: Make CHUNK_TYPE_RAW buffer aligned

Dan Carpenter dan.carpenter at linaro.org
Wed Jan 31 08:11:49 CET 2024


Hello qianfan Zhao,

The patch 62649165cb02: "lib: sparse: Make CHUNK_TYPE_RAW buffer
aligned" from Nov 16, 2021, leads to the following Smatch static
checker warning:

	lib/image-sparse.c:214 write_sparse_image()
	warn: unsigned 'blks' is never less than zero.

lib/image-sparse.c
    109 int write_sparse_image(struct sparse_storage *info,
    110                        const char *part_name, void *data, char *response)
    111 {
    112         lbaint_t blk;
    113         lbaint_t blkcnt;
    114         lbaint_t blks;
                ^^^^^^^^^^^^^
This is a u64


    115         uint64_t bytes_written = 0;
    116         unsigned int chunk;
    117         unsigned int offset;
    118         uint64_t chunk_data_sz;
    119         uint32_t *fill_buf = NULL;
    120         uint32_t fill_val;
    121         sparse_header_t *sparse_header;
    122         chunk_header_t *chunk_header;
    123         uint32_t total_blocks = 0;
    124         int fill_buf_num_blks;
    125         int i;
    126         int j;
    127 
    128         fill_buf_num_blks = CONFIG_IMAGE_SPARSE_FILLBUF_SIZE / info->blksz;

[ snip ]

    211 
    212                         blks = write_sparse_chunk_raw(info, blk, blkcnt,
    213                                                       data, response);
--> 214                         if (blks < 0)
                                    ^^^^^^^^
Can't be less than zero

    215                                 return -1;
    216 
    217                         blk += blks;
    218                         bytes_written += ((u64)blkcnt) * info->blksz;
    219                         total_blocks += chunk_header->chunk_sz;
    220                         data += chunk_data_sz;
    221                         break;
    222 
    223                 case CHUNK_TYPE_FILL:
    224                         if (chunk_header->total_sz !=

regards,
dan carpenter


More information about the U-Boot mailing list