drivers: i2c: Check non-null pointer before dereferencing in i2c shell

Fixes the i2c shell to check the device name pointer is non-null before
dereferencing it.

Coverity CID: 210558

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
This commit is contained in:
Maureen Helm 2020-06-05 14:20:35 -05:00 committed by Anas Nashif
commit 3dd3c6a393

View file

@ -233,9 +233,9 @@ static void device_name_get(size_t idx, struct shell_static_entry *entry)
entry->subcmd = &dsub_device_name; entry->subcmd = &dsub_device_name;
for (dev = __device_start; dev != __device_end; dev++) { for (dev = __device_start; dev != __device_end; dev++) {
if ((dev->driver_api != NULL) && if ((dev->driver_api != NULL) && (dev->name != NULL) &&
strstr(dev->name, I2C_DEVICE_PREFIX) != NULL && strstr(dev->name, I2C_DEVICE_PREFIX) != NULL &&
strcmp(dev->name, "") && (dev->name != NULL)) { strcmp(dev->name, "")) {
if (idx == device_idx) { if (idx == device_idx) {
entry->syntax = dev->name; entry->syntax = dev->name;
break; break;