diff options
author | Georgii Staroselskii <georgii.staroselskii@emlid.com> | 2018-11-23 09:40:26 +0100 |
---|---|---|
committer | Jean Delvare <jdelvare@suse.de> | 2018-11-23 09:40:26 +0100 |
commit | 0e384cf3030e0b6d28fc0313a6c80538dd30d0c1 (patch) | |
tree | e1f2d187668261cae9fd52ca268ac85a2ba87275 | |
parent | 4b2857942f043eed1afade106c08bb74d639dca9 (diff) | |
download | i2c-tools-git-0e384cf3030e0b6d28fc0313a6c80538dd30d0c1.tar.gz |
py-smbus: Fix i2c_smbus_* error propagation
The Python bindings haven't been updated after commit
330bba29f3d02432e2dca6f85082763b248887ff ("libi2c: Properly
propagate real error codes on read errors"). This led to erronenous
behavior every time an error other than -1 is returned by i2c_smbus_*
functions.
[JD: Edited description.]
Signed-off-by: Georgii Staroselskii <georgii.staroselskii@emlid.com>
Signed-off-by: Jean Delvare <jdelvare@suse.de>
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | py-smbus/smbusmodule.c | 14 |
2 files changed, 8 insertions, 7 deletions
@@ -11,6 +11,7 @@ master Documentation update for DDR4 Verify the CRC of DDR4 data block 1 eeprog: Fix ambiguous parentheses + py-smbus: Fix i2c_smbus_* error propagation 4.0 (2017-10-30) tools: Fix build with recent compilers (gcc 4.6+) diff --git a/py-smbus/smbusmodule.c b/py-smbus/smbusmodule.c index b189106..34af992 100644 --- a/py-smbus/smbusmodule.c +++ b/py-smbus/smbusmodule.c @@ -216,7 +216,7 @@ SMBus_read_byte(SMBus *self, PyObject *args) SMBus_SET_ADDR(self, addr); - if ((result = i2c_smbus_read_byte(self->fd)) == -1) { + if ((result = i2c_smbus_read_byte(self->fd)) < 0) { PyErr_SetFromErrno(PyExc_IOError); return NULL; } @@ -239,7 +239,7 @@ SMBus_write_byte(SMBus *self, PyObject *args) SMBus_SET_ADDR(self, addr); - if ((result = i2c_smbus_write_byte(self->fd, (__u8)val)) == -1) { + if ((result = i2c_smbus_write_byte(self->fd, (__u8)val)) < 0) { PyErr_SetFromErrno(PyExc_IOError); return NULL; } @@ -263,7 +263,7 @@ SMBus_read_byte_data(SMBus *self, PyObject *args) SMBus_SET_ADDR(self, addr); - if ((result = i2c_smbus_read_byte_data(self->fd, (__u8)cmd)) == -1) { + if ((result = i2c_smbus_read_byte_data(self->fd, (__u8)cmd)) < 0) { PyErr_SetFromErrno(PyExc_IOError); return NULL; } @@ -287,7 +287,7 @@ SMBus_write_byte_data(SMBus *self, PyObject *args) SMBus_SET_ADDR(self, addr); if ((result = i2c_smbus_write_byte_data(self->fd, - (__u8)cmd, (__u8)val)) == -1) { + (__u8)cmd, (__u8)val)) < 0) { PyErr_SetFromErrno(PyExc_IOError); return NULL; } @@ -311,7 +311,7 @@ SMBus_read_word_data(SMBus *self, PyObject *args) SMBus_SET_ADDR(self, addr); - if ((result = i2c_smbus_read_word_data(self->fd, (__u8)cmd)) == -1) { + if ((result = i2c_smbus_read_word_data(self->fd, (__u8)cmd)) < 0) { PyErr_SetFromErrno(PyExc_IOError); return NULL; } @@ -335,7 +335,7 @@ SMBus_write_word_data(SMBus *self, PyObject *args) SMBus_SET_ADDR(self, addr); if ((result = i2c_smbus_write_word_data(self->fd, - (__u8)cmd, (__u16)val)) == -1) { + (__u8)cmd, (__u16)val)) < 0) { PyErr_SetFromErrno(PyExc_IOError); return NULL; } @@ -360,7 +360,7 @@ SMBus_process_call(SMBus *self, PyObject *args) SMBus_SET_ADDR(self, addr); if ((result = i2c_smbus_process_call(self->fd, - (__u8)cmd, (__u16)val)) == -1) { + (__u8)cmd, (__u16)val)) < 0) { PyErr_SetFromErrno(PyExc_IOError); return NULL; } |