Missing error check of device_get_binding() and flash_area_open() #30195
Labels
area: Drivers
area: Tests
Issues related to a particular existing or missing test
bug
The issue is a bug, or the PR is fixing a bug
priority: low
Low impact/importance bug
Stale
Hi,
As described in the API documentation, function device_get_binding() is used to retrieve the device structure for a driver by name, and returns the pointer to device structure, or NULL if not found or cannot be used. But as shown in the following three call sites, the error checks are not made.
zephyr/drivers/console/uart_console.c
Lines 600 to 604 in 0a0404d
zephyr/drivers/display/ssd1306.c
Lines 413 to 414 in 0a0404d
zephyr/drivers/display/display_st7789v.c
Lines 353 to 354 in 0a0404d
Moreover, in other sites, the return values of device_get_binding() have been checked for NULL. For instance,
zephyr/drivers/flash/spi_nor.c
Lines 848 to 852 in 0a0404d
zephyr/drivers/display/gd7965.c
Lines 438 to 442 in 0a0404d
===================================================================================
Also, function flash_area_open() is used to retrieve partitions flash area from the flash_map, and returns 0 on success, -EACCES if the flash_map is not available , or -ENOENT if ID is unknown. But in the following codes, the return value of it is not checked before the call of flash_area_erase().
zephyr/tests/subsys/settings/fcb/src/settings_test_fcb.c
Lines 190 to 195 in 0a0404d
However, in other parts, the return values are error checked. As shown in the following codes,
zephyr/tests/subsys/settings/functional/src/settings_basic_test.c
Lines 34 to 39 in 0a0404d
zephyr/tests/subsys/fs/littlefs/src/testfs_lfs.c
Lines 55 to 61 in 0a0404d
The text was updated successfully, but these errors were encountered: