summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhii Voloshynov <serhii.voloshynov@globallogic.com>2021-07-01 10:47:43 +0300
committerJohn Klug <john.klug@multitech.com>2021-11-12 13:20:26 -0600
commit3d658a837f6bc73ee7bf53105de089f5ce0aa59f (patch)
tree3a65b3ff14a31bc31a28531938290403856ac8d4
parenta5556f09d5df715b48bc4f0959457f6e36b6481c (diff)
downloadmtac-gpiob-3d658a837f6bc73ee7bf53105de089f5ce0aa59f.tar.gz
mtac-gpiob-3d658a837f6bc73ee7bf53105de089f5ce0aa59f.tar.bz2
mtac-gpiob-3d658a837f6bc73ee7bf53105de089f5ce0aa59f.zip
improve the code, check arguments before spi_read/spi_write calling.
if the driver was built with a wrong NUM_AP value it prevents driver crash and the system stays bootable and working
-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;