Commit 041e1827 authored by Adam Wujek's avatar Adam Wujek

sw/petalinux/python3-smbus: add patch to fix check of return value

Needed for testing monimod.
Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent 42ae389d
From 6c2df6081d35e5b7386e513ba066cf3c72b92682 Mon Sep 17 00:00:00 2001
From: Georgii Staroselskii <georgii.staroselskii@emlid.com>
Date: Fri, 23 Nov 2018 09:40:26 +0100
Subject: [PATCH] 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>
---
CHANGES | 2 ++
py-smbus/smbusmodule.c | 14 +++++++-------
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/CHANGES b/CHANGES
index 15ff761..630a48c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
i2c-tools CHANGES
-----------------
+ py-smbus: Fix i2c_smbus_* error propagation
+
4.0 (2017-10-30)
tools: Fix build with recent compilers (gcc 4.6+)
Add examples to the manual pages
diff --git a/py-smbus/smbusmodule.c b/py-smbus/smbusmodule.c
index 48a408b..bf9b284 100644
--- a/py-smbus/smbusmodule.c
+++ b/py-smbus/smbusmodule.c
@@ -215,7 +215,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;
}
@@ -238,7 +238,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;
}
@@ -262,7 +262,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;
}
@@ -286,7 +286,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;
}
@@ -310,7 +310,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;
}
@@ -334,7 +334,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;
}
@@ -359,7 +359,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;
}
--
2.17.1
#Patch
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += " file://0001-py-smbus-Fix-i2c_smbus_-error-propagation.patch;patchdir=${WORKDIR}/i2c-tools-${PV}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment