summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mtac_gpiob.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/mtac_gpiob.c b/mtac_gpiob.c
index 6e08477..6b3a782 100644
--- a/mtac_gpiob.c
+++ b/mtac_gpiob.c
@@ -352,6 +352,11 @@ static ssize_t mts_attr_show_ap_din(struct kobject *kobj, struct kobj_attribute
bit = BIT(channel);
+ if (port_index > NUM_AP) {
+ log_error("port %d is invalid", port);
+ return -ENOENT;
+ }
+
tmp = spi_readn(gpiob_spi[port_index][din], &byte, 1);
if (tmp) {
log_error("spi_read failed %d", tmp);
@@ -391,6 +396,11 @@ static ssize_t mts_attr_store_ap_dout(struct kobject *kobj, struct kobj_attribut
return -EINVAL;
}
+ if (port_index > NUM_AP) {
+ log_error("port %d is invalid", port);
+ return -ENOENT;
+ }
+
mutex_lock(&spi_ap_dout_mutex);
if (value) {
@@ -429,6 +439,11 @@ static ssize_t mts_attr_show_ap_dout(struct kobject *kobj, struct kobj_attribute
bit = BIT(channel);
+ if (port_index > NUM_AP) {
+ log_error("port %d is invalid", port);
+ return -ENOENT;
+ }
+
mutex_lock(&spi_ap_dout_mutex);
value = spi_ap_dout_value[port_index] & bit ? 0 : 1;
@@ -467,6 +482,11 @@ static ssize_t mts_attr_show_ap_adc(struct kobject *kobj, struct kobj_attribute
}
port_index = port - 1;
+ if (port_index > NUM_AP) {
+ log_error("port %d is invalid", port);
+ return -ENOENT;
+ }
+
/* 1st transfer to set up (5V reference, channel to read from) */
tx_data = manual_mode | ((channel << 7) & channel_mask);
tx[0] = tx_data >> 8;