Skip to content

Commit 8fd0b70

Browse files
cfriedtdkalowsk
authored andcommitted
drivers: gpio: gpio_pca_series: check return values and exit on error
Check return values and exit on error to address CID 434641. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
1 parent 5e25a3e commit 8fd0b70

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

drivers/gpio/gpio_pca_series.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,9 @@ static int gpio_pca_series_pin_configure(const struct device *dev,
935935
/* configure PCA_REG_TYPE_1B_OUTPUT_CONFIG */
936936
ret = gpio_pca_series_reg_cache_read(dev,
937937
PCA_REG_TYPE_1B_OUTPUT_CONFIG, (uint8_t *)&reg_value);
938+
if (ret != 0) {
939+
goto out;
940+
}
938941
reg_value = sys_le32_to_cpu(reg_value);
939942
if (flags & GPIO_SINGLE_ENDED) {
940943
reg_value |= (BIT(pin)); /* set bit to set open-drain */
@@ -944,13 +947,19 @@ static int gpio_pca_series_pin_configure(const struct device *dev,
944947
reg_value = sys_cpu_to_le32(reg_value);
945948
ret = gpio_pca_series_reg_write(dev,
946949
PCA_REG_TYPE_1B_OUTPUT_CONFIG, (uint8_t *)&reg_value);
950+
if (ret != 0) {
951+
goto out;
952+
}
947953
}
948954

949955
if ((cfg->part_cfg->flags & PCA_HAS_PULL)) {
950956
if ((flags & GPIO_PULL_UP) || (flags & GPIO_PULL_DOWN)) {
951957
/* configure PCA_REG_TYPE_1B_PULL_SELECT */
952958
ret = gpio_pca_series_reg_cache_read(dev,
953959
PCA_REG_TYPE_1B_PULL_SELECT, (uint8_t *)&reg_value);
960+
if (ret != 0) {
961+
goto out;
962+
}
954963
reg_value = sys_le32_to_cpu(reg_value);
955964
if (flags & GPIO_PULL_UP) {
956965
reg_value |= (BIT(pin));
@@ -960,10 +969,16 @@ static int gpio_pca_series_pin_configure(const struct device *dev,
960969
reg_value = sys_cpu_to_le32(reg_value);
961970
ret = gpio_pca_series_reg_write(dev,
962971
PCA_REG_TYPE_1B_PULL_SELECT, (uint8_t *)&reg_value);
972+
if (ret != 0) {
973+
goto out;
974+
}
963975
}
964976
/* configure PCA_REG_TYPE_1B_PULL_ENABLE */
965977
ret = gpio_pca_series_reg_cache_read(dev,
966978
PCA_REG_TYPE_1B_PULL_ENABLE, (uint8_t *)&reg_value);
979+
if (ret != 0) {
980+
goto out;
981+
}
967982
reg_value = sys_le32_to_cpu(reg_value);
968983
if ((flags & GPIO_PULL_UP) || (flags & GPIO_PULL_DOWN)) {
969984
reg_value |= (BIT(pin)); /* set bit to enable pull */
@@ -973,6 +988,9 @@ static int gpio_pca_series_pin_configure(const struct device *dev,
973988
reg_value = sys_cpu_to_le32(reg_value);
974989
ret = gpio_pca_series_reg_write(dev, PCA_REG_TYPE_1B_PULL_ENABLE,
975990
(uint8_t *)&reg_value);
991+
if (ret != 0) {
992+
goto out;
993+
}
976994
}
977995

978996
/* configure PCA_REG_TYPE_1B_OUTPUT */
@@ -1013,6 +1031,10 @@ static int gpio_pca_series_pin_configure(const struct device *dev,
10131031
/* configure PCA_REG_TYPE_1B_CONFIGURATION */
10141032
ret = gpio_pca_series_reg_cache_read(dev,
10151033
PCA_REG_TYPE_1B_CONFIGURATION, (uint8_t *)&reg_value);
1034+
if (ret != 0) {
1035+
goto out;
1036+
}
1037+
10161038
reg_value = sys_le32_to_cpu(reg_value);
10171039
if (flags & GPIO_INPUT) {
10181040
reg_value |= (BIT(pin)); /* set bit to set input */

0 commit comments

Comments
 (0)