Fix hidden segfault, this should never have been working. It should have trigggered...
authorNathael Pajani <nathael.pajani@ed3l.fr>
Wed, 23 Sep 2015 12:45:54 +0000 (14:45 +0200)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 8 Nov 2022 16:03:04 +0000 (17:03 +0100)
drivers/i2c.c

index 3be66a4..786171f 100644 (file)
@@ -234,7 +234,10 @@ void I2C_0_Handler(void)
                        break;
 
                case 0x50: /* Data byte has been received and ACK sent */
-                       i2c->in_buff[i2c->read_index++] = i2c->regs->data;
+                       if (i2c->in_buff != NULL) {
+                               i2c->in_buff[i2c->read_index] = i2c->regs->data;
+                       }
+                       i2c->read_index++;
                        if ((i2c->read_index + 1) < i2c->read_length) {
                                /* assert ACK after data is received, requesting next Data from slave */
                                i2c->regs->ctrl_set = I2C_ASSERT_ACK;
@@ -247,7 +250,10 @@ void I2C_0_Handler(void)
 
                case 0x58: /* Data byte has been received and NACK "sent" */
                        /* This tells the slave it was the last byte. We should be done. */
-                       i2c->in_buff[i2c->read_index++] = i2c->regs->data;
+                       if (i2c->in_buff != NULL) {
+                               i2c->in_buff[i2c->read_index] = i2c->regs->data;
+                       }
+                       i2c->read_index++;
                        /* FIXME : We have two other options : Repeated START or STOP + START,
                         *    but what for ? periodic reads ? */
                        i2c->regs->ctrl_set = I2C_STOP_FLAG;